diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 554dcc68b94..3b387975d5b 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3429,43 +3429,13 @@ class AccountMoveLine(models.Model): audit_str = '' for tag in record.tax_tag_ids: - # In case of cash basis entries, we need to consider the original invoice, not the current move if record.move_id.tax_cash_basis_rec_id: - reconciled_amls = record.move_id.tax_cash_basis_rec_id.debit_move_id + record.move_id.tax_cash_basis_rec_id.credit_move_id - invoice_aml = reconciled_amls.filtered(lambda x: x.journal_id.type in ('sale', 'purchase')) # To exclude the payment - - if len(invoice_aml) > 1: - - caba_origin_inv_journal_type = invoice_aml.mapped('journal_id.type')[0] - type_prefixes = {'sale': 'out', 'purchase': 'in'} - - if record.tax_repartition_line_id: - # If tax_repartition_line_id is set, we know for sure we are on a tax line. - # We can then simply check whether the repartition line is intended for invoices or refunds - type_postfix = record.tax_repartition_line_id.invoice_tax_id and 'invoice' or 'refund' - caba_origin_inv_type = "%s_%s" % (type_prefixes[caba_origin_inv_journal_type], type_postfix) - - elif record.tax_ids: - # If it's a base line, we rely on debit/credit to guess the type of the CABA origin invoice. - if (caba_origin_inv_journal_type == 'sale' and record.credit) \ - or (caba_origin_inv_journal_type == 'purchase' and record.debit): - caba_origin_inv_type = type_prefixes[caba_origin_inv_journal_type] + '_invoice' - else: - caba_origin_inv_type = type_prefixes[caba_origin_inv_journal_type] + '_refund' - - else: - # Default type for non-tax related lines is invoice. (in/out depending of the journal) - caba_origin_inv_type = type_prefixes[caba_origin_inv_journal_type] + '_invoice' - - if caba_origin_inv_type not in invoice_aml.mapped('move_id.move_type'): - caba_origin_inv_type = type_prefixes[caba_origin_inv_journal_type] + '_invoice' - else: - caba_origin_inv_type = invoice_aml.move_id.move_type - + # Cash basis entries are always treated as misc operations, applying the tag sign directly to the balance + type_multiplicator = 1 else: - caba_origin_inv_type = record.move_id.move_type + type_multiplicator = (record.journal_id.type == 'sale' and -1 or 1) * (record.move_id.move_type in ('in_refund', 'out_refund') and -1 or 1) - tag_amount = (tag.tax_negate and -1 or 1) * (caba_origin_inv_type in record.move_id.get_inbound_types() and -1 or 1) * record.balance + tag_amount = type_multiplicator * (tag.tax_negate and -1 or 1) * record.balance if tag.tax_report_line_ids: #Then, the tag comes from a report line, and hence has a + or - sign (also in its name) @@ -4716,3 +4686,32 @@ class AccountMoveLine(models.Model): if self.payment_id: domains.append([('res_model', '=', 'account.payment'), ('res_id', '=', self.payment_id.id)]) return domains + + def _convert_tags_for_cash_basis(self, tags): + """ Cash basis entries are managed by the tax report just like misc operations. + So it means that the tax report will not apply any additional multiplicator + to the balance of the cash basis lines. + + For invoices move lines whose multiplicator would have been -1 (if their + taxes had not CABA), it will hence cause sign inversion if we directly copy + the tags from those lines. Instead, we need to invert all the signs from these + tags (if they come from tax report lines; tags created in data for financial + reports will stay onchanged). + """ + self.ensure_one() + tax_multiplicator = (self.journal_id.type == 'sale' and -1 or 1) * (self.move_id.move_type in ('in_refund', 'out_refund') and -1 or 1) + if tax_multiplicator == -1: + # Take the opposite tags instead + rslt = self.env['account.account.tag'] + for tag in tags: + if tag.tax_report_line_ids: + # tag created by an account.tax.report.line + new_tag = tag.tax_report_line_ids[0].tag_ids.filtered(lambda x: x.tax_negate != tag.tax_negate) + rslt += new_tag + else: + # tag created in data for use by an account.financial.html.report.line + rslt += tag + + return rslt + + return tags