Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
5117 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
bře 24
1307
1
led 25
1842
2
pro 24
21384
0
zář 24
1138
3
srp 24
2322