From ef9e2d9f8bb1682ca9614769f17d2afc168254e5 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Wed, 9 Mar 2022 09:25:06 +0000 Subject: [PATCH] [FIX] account: proper tax repartition for tax lines when using a writeoff reconciliation model with taxes When creating the results of a writeoff button for the manual reconciliation widget, debit and credit are actually inverted with regards to what will actually get created (final inversion is then done here to bring them back to the right sign: https://github.com/odoo/enterprise/blob/15.0/account_accountant/models/reconciliation_widget.py#L986). Because of that, the conditions defining whether or not the compute_all should compute refund repartition need to be inverted as well. Note that it wasn't the case for bank reconciliation widget, for which the sign was directly right. Before that, compute_tax_tag_invert computed a different value for the tax_tag_invert field on base and tax line (as the tax line uses the repartition type of tax_repartition_line_id, and the base line depends on debit/credit and the tax type). Hence, the tax_tag_invert values between those two lines where inconsistent, and the tax report was wrong (since we did * -1 on one of them, but not the other). OPW 2769586 closes odoo/odoo#86870 X-original-commit: fdf448ef226ecf27685675ea4a49a4501d4f9263 Signed-off-by: Laurent Smet --- addons/account/models/account_reconcile_model.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index a98f5275b5f..62c9bfbfa2b 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -312,7 +312,7 @@ class AccountReconcileModel(models.Model): # RECONCILIATION PROCESS #################################################### - def _get_taxes_move_lines_dict(self, tax, base_line_dict): + def _get_taxes_move_lines_dict(self, tax, base_line_dict, statement_line=None): ''' Get move.lines dict (to be passed to the create()) corresponding to a tax. :param tax: An account.tax record. :param base_line_dict: A dict representing the move.line containing the base amount. @@ -322,7 +322,11 @@ class AccountReconcileModel(models.Model): balance = base_line_dict['balance'] tax_type = tax.type_tax_use - is_refund = (tax_type == 'sale' and balance > 0) or (tax_type == 'purchase' and balance < 0) + if statement_line: + is_refund = (tax_type == 'sale' and balance > 0) or (tax_type == 'purchase' and balance < 0) + else: + is_refund = (tax_type == 'sale' and balance < 0) or (tax_type == 'purchase' and balance > 0) + res = tax.compute_all(balance, is_refund=is_refund) new_aml_dicts = [] @@ -432,7 +436,7 @@ class AccountReconcileModel(models.Model): # only allow to set the force_tax_included field if we have one tax selected if line.force_tax_included: taxes = taxes[0].with_context(force_price_include=True) - tax_vals_list = self._get_taxes_move_lines_dict(taxes, writeoff_line) + tax_vals_list = self._get_taxes_move_lines_dict(taxes, writeoff_line, statement_line=st_line) lines_vals_list += tax_vals_list if not line.force_tax_included: for tax_line in tax_vals_list: