Skip to content

Commit

Permalink
[FIX] product_price_taxes_included: recursion check in price list
Browse files Browse the repository at this point in the history
  • Loading branch information
lef-adhoc committed Mar 6, 2024
1 parent b7b1a8f commit 06f0090
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions product_price_taxes_included/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models
from odoo import models, fields


class ProductPricelist(models.Model):
Expand Down Expand Up @@ -47,9 +47,30 @@ def check_for_product_pack_parent(self, product):

def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
res = super()._get_product_price(product, quantity, uom=None, date=False, **kwargs)
if self._context.get('taxes_included'):
if self._context.get('taxes_included') and self._recursion_check(product, quantity, uom, **kwargs):
company_id = (self._context.get('company_id')
or self.env.company.id)
res = product.taxes_id.filtered(
lambda x: x.company_id.id == company_id).compute_all(res, product=product)['total_included']
return res

def _recursion_check(self, product, quantity, uom, **kwargs):
"""
Verify that it is not a pricelist that depends on another so that it does not apply taxes recursively
"""
date = fields.Datetime.now()
rules = self._get_applicable_rules(product, date, **kwargs)
suitable_rule = self.env['product.pricelist.item']
product_uom = product.uom_id
target_uom = uom or product_uom
if target_uom != product_uom:
qty_in_product_uom = target_uom._compute_quantity(quantity, product_uom, raise_if_failure=False)
else:
qty_in_product_uom = quantity

for rule in rules:
if rule._is_applicable_for(product, qty_in_product_uom):
suitable_rule = rule
break

return not (suitable_rule.compute_price == 'formula' and suitable_rule.base == 'pricelist' and suitable_rule.base_pricelist_id)

0 comments on commit 06f0090

Please sign in to comment.