Skip to Content
Menu
This question has been flagged
2 Replies
4425 Views

Hello,


I've been adding some functionality to Odoo 13's SaleOrderLine's discount-field. My goal is to add a discount from a field in res.partner, but I want to implement a feature that gives the partner discount as default to sale.order.line's discount-field and then if this field's value is changed, calculates the new discount percentage by the old and new values. I've managed to do all of this and now I'm calculating the discount with an @api.onchange('discount') -method. The problem with this onchange is that when I calculate the percentage and add it to the self.discount, I trigger another onchange for the discount. This happens at least if the user gives a new discount and then presses enter or tab to move to another row.


My question is, is there a way to prevent the retriggering of the onchange or set a flag that prevents the recalculation of  discount? I haven't been able to do anything with the context and my last resort is to add a field into the model that I set to True and False during the update and after...

Avatar
Discard
Best Answer

Hi,

I think another function is triggered after the function of yours. So you have to super the original function and add the code like below.

@api.onchange('product_id', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id')
def _onchange_discount(self):
res = super(ClassName, self)._onchange_discount()
""" Your code here """
return res

Hope it helps

Avatar
Discard
Author Best Answer

Hi,

thanks for your answer! I decided to got with setting the discount on the product_id onchange and to not fiddle with it any more since doing changes to the discount after a user has changed it can seem somewhat limiting to the user. So, I'll go with this simpler solution for now and maybe change it in the future.

You're probably right on what you said about _onchange_discount being triggered after my function, if I decide to do the discount -calculation the way I originally meant, I probably would check that function out.


Avatar
Discard
Related Posts Replies Views Activity
0
Mar 24
285
0
Sep 24
122
3
Aug 24
528
0
Feb 24
263
0
Feb 24
157