I added a field for Odoo’s sales module and managed it using the compute and inverse function. When it receives an amount, I want it to convert it into a discount percentage and display it in the discount field, but it doesn’t work and when I fill the field, it doesn’t complete the discount field. Can anyone guide me?
class discount_amount_model(models.Model):
_inherit = 'sale.order.line'
discount_amount = fields.Float(compute='_compute_discount_amount', inverse='_inverse_discount_amount', string='discount_amount' , readonly=False)
@api.depends('discount_amount','price_unit')
def _compute_discount_amount(self):
for rec in self:
if rec.discount_amount > rec.price_unit :
return 0
elif rec.price_unit * rec.product_uom_qty != 0 :
rec.discount_amount = (rec.discount_amount / (rec.price_unit * rec.product_uom_qty)) * 100
def _inverse_discount_amount(self):
if self.discount_amount:
self.discount_amount = ((self.price_unit * self.product_uom_qty ) * self.discount) / 100
New contributor
atieh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2