Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged

In my below code you can see that, I have created a function to check if product is in pricelist or not and then proceed the next steps (i.e) calculate price_unit with discount given and move to next product in sale.order but now the problem here is, In else: part there is another flow working (i.e) if the product does not exist in pricelist it will raise warning but the product existing in the pricelist is working with the code given in else which it should not since it is already in pricelist and only work with the for loop given at the beginning. Also the product not in pricelist is perfectly working with the code. Only the product already in pricelist is working over in else part which it shouldn't. Can anyone explain why does this happen? I am using v11 and this is a custom module 

@api.onchange('price_unit')
def change_price_unit(self):
item_found = False
for
item in self.order_id.pricelist_id.item_ids:
if self.product_id.product_tmpl_id == item.product_tmpl_id:
item_found = True
price_list_price = item.fixed_price - (
item.fixed_price * (self.env.user.discount_limit / 100.0))
if self.price_unit < price_list_price:
raise UserError(
_('You don\'t have Access to change the\
Price Less than %s'
) % price_list_price)
else:
res = {}
warning = {}
price_unit = 0
itemFound = False
sale_price = self.product_id.product_tmpl_id.list_price
for item in self.order_id.pricelist_id.item_ids:
if itemFound == False and self.product_id.product_tmpl_id != item.product_tmpl_id:
if self.price_unit < sale_price:
warning = {
'title': _("Warning"),
'message'
: _(
'Please add product to pricelist'),
}
res = {'value': {'price_unit': price_unit}}
if self.price_unit > sale_price:
warning = {
'title': _("Warning"),
'message'
: _(
'Please add product to pricelist'),
}
res = {'value': {'price_unit': price_unit}}
return {'value': res.get('value'), 'warning': warning}

Apologies if my description is still not explainable. But I can explain again.


Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
úno 18
4491
1
pro 17
5784
0
pro 17
4215
2
led 24
5414
0
čvn 23
2023