forked from OCA/product-pack
/
sale_order_line_pack_line.py
38 lines (33 loc) · 1.41 KB
/
sale_order_line_pack_line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, fields, models
class SaleOrderLinePackLine(models.Model):
_name = "sale.order.line.pack.line"
_description = "Sale Order None Detailed Pack Lines"
order_line_id = fields.Many2one(
"sale.order.line", "Order Line", ondelete="cascade", index=True, required=True
)
product_id = fields.Many2one("product.product", "Product", required=True)
price_unit = fields.Float("Unit Price", required=True, digits="Product Price")
discount = fields.Float(
"Discount (%)",
digits="Discount",
)
price_subtotal = fields.Float(
compute="_compute_price_subtotal", string="Subtotal", digits="Account"
)
product_uom_qty = fields.Float("Quantity", digits="Product UoS", required=True)
@api.onchange("product_id")
def onchange_product_id(self):
for line in self:
line.price_unit = line.product_id.price
@api.depends("price_unit", "product_uom_qty")
def _compute_price_subtotal(self):
for line in self:
line.price_subtotal = (
line.product_uom_qty
* line.price_unit
* (1 - (line.discount or 0.0) / 100.0)
)