I would like to show the discount of the pricelist. It matches with the price_discount
field of the model product.pricelist.item
.
But once I get the discount from that model I want to make it editable. How can I achieve this?
I tried this code with no luck. I make the field discount_percentage
invisible, I only use it for recomputing the field.
discount_percentage = fields.Float(
compute='_compute_discount_percentage',
string=_('Discount (%)'),
digits=dp.get_precision('Discount'),
)
discount_manual = fields.Float(
string=_('Discount dummy (%)'),
digits=dp.get_precision('Discount'),
)
@api.one
@api.depends('product_id', 'product_id.lst_price', 'price_reduce', 'price_unit')
def _compute_discount_percentage(self):
_logger.debug('-- COMPUTE DISCOUNT PERCENTAGE --')
if not self.discount_manual:
if self.product_id.lst_price:
disc = (self.product_id.lst_price - self.price_reduce) * 100 / self.product_id.lst_price
else:
disc = 0
self.discount_percentage = disc
self.discount_manual = self.discount_percentage
else:
self.discount_percentage = self.discount_manual
Is there a function where I can get the discount using the product_id
and pricelist_id
?
Should I use a SQL query in the product_id_change
method in order to get the discount?