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
|
from odoo import models, fields, api
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
discount = fields.Float(
string='Discount (%)',
digits='Discount',
default=0.0
)
discount_amount = fields.Float(
string='Discount Amount',
compute='_compute_discount_amount'
)
@api.depends('price_unit', 'product_qty', 'discount')
def _compute_discount_amount(self):
for line in self:
discount = line.discount or 0.0
line.discount_amount = (line.price_unit * line.product_qty * discount) / 100.0
def _prepare_compute_all_values(self):
res = super(PurchaseOrderLine, self)._prepare_compute_all_values()
price_unit = res['price_unit'] * (1 - (self.discount or 0.0) / 100.0)
res.update({
'price_unit': price_unit,
})
return res
@api.depends('product_qty', 'price_unit', 'taxes_id', 'discount')
def _compute_amount(self):
return super(PurchaseOrderLine, self)._compute_amount()
def write(self, values):
res = super().write(values)
if 'discount' in values:
self._compute_amount()
return res
|