-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsale_order_line.py
More file actions
72 lines (63 loc) · 2.38 KB
/
sale_order_line.py
File metadata and controls
72 lines (63 loc) · 2.38 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
discount_total = fields.Monetary(
compute="_compute_amount",
store=True,
precompute=True,
)
discount_subtotal = fields.Monetary(
compute="_compute_amount",
store=True,
precompute=True,
)
price_subtotal_no_discount = fields.Monetary(
compute="_compute_amount",
string="Subtotal Without Discount",
store=True,
precompute=True,
)
price_total_no_discount = fields.Monetary(
compute="_compute_amount",
string="Total Without Discount",
store=True,
precompute=True,
)
def _update_discount_display_fields(self):
for line in self:
line.price_subtotal_no_discount = 0
line.price_total_no_discount = 0
line.discount_total = 0
if not line.discount:
line.price_subtotal_no_discount = line.price_subtotal
line.price_total_no_discount = line.price_total
price = line.price_unit
taxes = line.tax_id.compute_all(
price,
line.order_id.currency_id,
line.product_uom_qty,
product=line.product_id,
partner=line.order_id.partner_shipping_id,
)
price_subtotal_no_discount = taxes["total_excluded"]
price_total_no_discount = taxes["total_included"]
discount_total = price_total_no_discount - line.price_total
discount_subtotal = price_subtotal_no_discount - line.price_subtotal
line.update(
{
"discount_total": discount_total,
"discount_subtotal": discount_subtotal,
"price_subtotal_no_discount": price_subtotal_no_discount,
"price_total_no_discount": price_total_no_discount,
}
)
@api.model
def _get_compute_amount_depends(self):
return ["product_uom_qty", "discount", "price_unit", "tax_id"]
@api.depends(lambda self: self._get_compute_amount_depends())
def _compute_amount(self):
res = super()._compute_amount()
self._update_discount_display_fields()
return res