Skip to content

Commit

Permalink
[REVERT] sale: Fix fiscal pos. mapping taxes to price included
Browse files Browse the repository at this point in the history
This reverts commit d89562e.

Since this commit, the taxes mapped by fiscal position wasn't managed by the _fix_tax_included_price_company method anymore.
Otherwise, some customizations exist on this method that are no longer called.
The 2527940 issue is also due to a remaining bug: the total_excluded price should be divided by the quantity but:
- what if the quantity & price_unit are both signed?
- what if the number of digits for price_unit and the currency are different? Should we skip the rounding of taxes?
Since this commit is not perfect and has a lot of dependencies in others modules, we decided to revert it.

Original PR: odoo#68997
Revert PR: odoo#70858

closes odoo#70883

Issue: 2527940
X-original-commit: c9330e4
Signed-off-by: Victor Feyens (vfe) <[email protected]>
Signed-off-by: Laurent Smet <[email protected]>
  • Loading branch information
smetl committed May 17, 2021
1 parent 09da295 commit def7d7b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 172 deletions.
43 changes: 3 additions & 40 deletions addons/sale/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,43 +1648,6 @@ def _get_display_price(self, product):
# negative discounts (= surcharge) are included in the display price
return max(base_price, final_price)

def _get_default_price_unit_from_product(self, product):
self.ensure_one()

currency = self.order_id.currency_id
fiscal_position = self.order_id.fiscal_position_id or self.order_id.partner_id.property_account_position_id
product_taxes = self.product_id.taxes_id.filtered(lambda r: r.company_id == self.order_id.company_id)
product_taxes_after_fp = fiscal_position.map_tax(product_taxes, partner=self.order_id.partner_id)
price_unit = self._get_display_price(product)

if set(product_taxes.ids) != set(product_taxes_after_fp.ids):
flattened_taxes = product_taxes._origin.flatten_taxes_hierarchy()
if any(tax.price_include for tax in flattened_taxes):
taxes_res = flattened_taxes.compute_all(
price_unit,
quantity=self.product_uom_qty,
currency=currency,
product=self.product_id,
partner=self.order_id.partner_id,
)
price_unit = currency.round(taxes_res['total_excluded'])

flattened_taxes = product_taxes_after_fp._origin.flatten_taxes_hierarchy()
if any(tax.price_include for tax in flattened_taxes):
taxes_res = flattened_taxes.compute_all(
price_unit,
quantity=self.product_uom_qty,
currency=currency,
product=self.product_id,
partner=self.order_id.partner_id,
handle_price_include=False,
)
for tax_res in taxes_res['taxes']:
tax = self.env['account.tax'].browse(tax_res['id'])
if tax.price_include:
price_unit += tax_res['amount']
return price_unit

@api.onchange('product_id')
def product_id_change(self):
if not self.product_id:
Expand Down Expand Up @@ -1713,13 +1676,13 @@ def product_id_change(self):
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id
)

vals.update(name=self.get_sale_order_line_multiline_description_sale(product))

self._compute_tax_id()

if self.order_id.pricelist_id and self.order_id.partner_id:
vals['price_unit'] = self._get_default_price_unit_from_product(product)

vals['price_unit'] = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)
self.update(vals)

title = False
Expand Down Expand Up @@ -1752,7 +1715,7 @@ def product_uom_change(self):
uom=self.product_uom.id,
fiscal_position=self.env.context.get('fiscal_position')
)
self.price_unit = self._get_default_price_unit_from_product(product)
self.price_unit = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)

def name_get(self):
result = []
Expand Down
1 change: 0 additions & 1 deletion addons/sale/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
from . import test_sale_signature
from . import test_sale_transaction
from . import test_sale_flow
from . import test_sale_fiscal_position
131 changes: 0 additions & 131 deletions addons/sale/tests/test_sale_fiscal_position.py

This file was deleted.

0 comments on commit def7d7b

Please sign in to comment.