Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] account: compute tax ordering #156031

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Mar 1, 2024

Issue Description:
Currently, the order in which taxes are applied can vary based on the sequence they are entered in the invoice's Taxes field. This inconsistency arises when the tax list is not manually adjusted, leading to each tax having an identical sequence value. As a result, their hierarchy within the flatten_taxes_hierarchy function is determined by their input order rather than a defined sequence, causing unpredictable tax calculations.

def flatten_taxes_hierarchy(self, create_map=False):
# Flattens the taxes contained in this recordset, returning all the
# children at the bottom of the hierarchy, in a recordset, ordered by sequence.
# Eg. considering letters as taxes and alphabetic order as sequence :
# [G, B([A, D, F]), E, C] will be computed as [A, D, F, C, E, G]
# If create_map is True, an additional value is returned, a dictionary
# mapping each child tax to its parent group
all_taxes = self.env['account.tax']
groups_map = {}
for tax in self.sorted(key=lambda r: r.sequence):
if tax.amount_type == 'group':
flattened_children = tax.children_tax_ids.flatten_taxes_hierarchy()
all_taxes += flattened_children
for flat_child in flattened_children:
groups_map[flat_child] = tax
else:
all_taxes += tax
if create_map:
return all_taxes, groups_map
return all_taxes

A tax sequence should be explicitly defined, and in cases where sequences are identical, organization by tax ID should be enforced.

Steps to Reproduce:

  1. Navigate to the Account or Invoice app.
  2. Go to Configuration > Taxes.
  3. Create a new tax with the advanced option Affect Base of Subsequent Taxes and specify an amount.
  4. Generate a new invoice and add a line item priced at 100.
  5. Apply taxes in the Taxes column in the following order: 15% followed by the newly created tax, and note the total amount.
  6. Repeat step 5, but reverse the order of the taxes.
  7. Observe that the total amounts differ between the two sequences.

Proposed Solution:
To ensure that taxes are applied consistently regardless of input order, we will modify the flatten_taxes_hierarchy function to add sorting by id. If the sequences are identical, the sorting will depend only on the id, otherwise it will be based on the sequence. This setting ensures a predictable and logical process for applying taxes.

opw-3691765

Forward-Port-Of: #155414
Forward-Port-Of: #154167

@robodoo
Copy link
Contributor

robodoo commented Mar 1, 2024

@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 1, 2024

This PR targets saas-16.2 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Mar 1, 2024
@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 1, 2024

@ilru-odoo @smetl ci/runbot failed on this forward-port PR

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 1, 2024
@clbr-odoo clbr-odoo force-pushed the saas-16.2-17.0-opw-3691765-account_compute_tax_ordering-ilru-JJlT-fw branch from 44242b9 to e45b1e5 Compare March 4, 2024 08:13
@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 4, 2024

@ilru-odoo @smetl this PR was modified / updated and has become a normal PR. It should be merged the normal way (via @robodoo)

@IlyaRudy IlyaRudy force-pushed the saas-16.2-17.0-opw-3691765-account_compute_tax_ordering-ilru-JJlT-fw branch from e45b1e5 to be8bfee Compare March 4, 2024 08:57
@clbr-odoo clbr-odoo force-pushed the saas-16.2-17.0-opw-3691765-account_compute_tax_ordering-ilru-JJlT-fw branch 2 times, most recently from f6f7d5e to 085f852 Compare March 4, 2024 09:14
**Issue Description**:
Currently, the order in which taxes are applied can vary based on the sequence they are entered in the invoice's Taxes field. This inconsistency arises when the tax list is not manually adjusted, leading to each tax having an identical sequence value. As a result, their hierarchy within the `flatten_taxes_hierarchy` function is determined by their input order rather than a defined sequence, causing unpredictable tax calculations.
https://github.com/odoo/odoo/blob/56666f8f7858fcbcce466d2240135b35509d2d96/addons/account/models/account_tax.py#L611-L632

A tax sequence should be explicitly defined, and in cases where sequences are identical, organization by tax ID should be enforced.

**Steps to Reproduce**:
1. Navigate to the `Account` or `Invoice` application.
2. Go to `Configuration > Taxes`.
3. Create a new tax with the advanced option `Affect Base of Subsequent Taxes` and specify an amount.
4. Generate a new invoice and add a line item priced at 100.
5. Apply taxes in the `Taxes` column in the following order: 15% followed by the newly created tax, and note the total amount.
6. Repeat step 5, but reverse the order of the taxes.
7. Observe that the total amounts differ between the two sequences.

**Proposed Solution**:
To ensure that taxes are applied consistently regardless of input order, we will modify the `flatten_taxes_hierarchy` function to add sorting by id. If the sequences are identical, the sorting will depend only on the id, otherwise it will be based on the sequence. This setting ensures a predictable and logical process for applying taxes.

opw-3691765

X-original-commit: 516c471
@clbr-odoo clbr-odoo force-pushed the saas-16.2-17.0-opw-3691765-account_compute_tax_ordering-ilru-JJlT-fw branch from 085f852 to c0d2ad2 Compare March 4, 2024 09:29
@smetl
Copy link
Contributor

smetl commented Mar 4, 2024

@robodoo r+

robodoo pushed a commit that referenced this pull request Mar 4, 2024
**Issue Description**:
Currently, the order in which taxes are applied can vary based on the sequence they are entered in the invoice's Taxes field. This inconsistency arises when the tax list is not manually adjusted, leading to each tax having an identical sequence value. As a result, their hierarchy within the `flatten_taxes_hierarchy` function is determined by their input order rather than a defined sequence, causing unpredictable tax calculations.
https://github.com/odoo/odoo/blob/56666f8f7858fcbcce466d2240135b35509d2d96/addons/account/models/account_tax.py#L611-L632

A tax sequence should be explicitly defined, and in cases where sequences are identical, organization by tax ID should be enforced.

**Steps to Reproduce**:
1. Navigate to the `Account` or `Invoice` application.
2. Go to `Configuration > Taxes`.
3. Create a new tax with the advanced option `Affect Base of Subsequent Taxes` and specify an amount.
4. Generate a new invoice and add a line item priced at 100.
5. Apply taxes in the `Taxes` column in the following order: 15% followed by the newly created tax, and note the total amount.
6. Repeat step 5, but reverse the order of the taxes.
7. Observe that the total amounts differ between the two sequences.

**Proposed Solution**:
To ensure that taxes are applied consistently regardless of input order, we will modify the `flatten_taxes_hierarchy` function to add sorting by id. If the sequences are identical, the sorting will depend only on the id, otherwise it will be based on the sequence. This setting ensures a predictable and logical process for applying taxes.

opw-3691765

closes #156031

X-original-commit: 516c471
Signed-off-by: Laurent Smet (las) <las@odoo.com>
@robodoo robodoo closed this Mar 4, 2024
@fw-bot fw-bot deleted the saas-16.2-17.0-opw-3691765-account_compute_tax_ordering-ilru-JJlT-fw branch March 18, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants