Skip to content

Commit

Permalink
[FIX] account_edi_ubl_cii: Fix call to '_prepare_edi_tax_details'
Browse files Browse the repository at this point in the history
This module no longer depends of account_edi.
Then, `_prepare_edi_tax_details` can't not be used.
We need to use `_prepare_invoice_aggregated_taxes` instead.

closes odoo#131109

X-original-commit: 89debfc
Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
Signed-off-by: Laurent Smet (las) <las@odoo.com>
  • Loading branch information
smetl committed Aug 8, 2023
1 parent 248ee47 commit c8b5fdb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def grouping_key_generator(base_line, tax_values):
self._validate_taxes(invoice)

# Create file content.
tax_details = invoice._prepare_edi_tax_details(grouping_key_generator=grouping_key_generator)
tax_details = invoice._prepare_invoice_aggregated_taxes(grouping_key_generator=grouping_key_generator)

# Fixed Taxes: filter them on the document level, and adapt the totals
# Fixed taxes are not supposed to be taxes in real live. However, this is the way in Odoo to manage recupel
Expand Down
8 changes: 5 additions & 3 deletions addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,11 @@ def grouping_key_generator(base_line, tax_values):
self._validate_taxes(invoice)

# Compute the tax details for the whole invoice and each invoice line separately.
taxes_vals = invoice._prepare_edi_tax_details(grouping_key_generator=grouping_key_generator,
filter_to_apply=self._apply_invoice_tax_filter,
filter_invl_to_apply=self._apply_invoice_line_filter)
taxes_vals = invoice._prepare_invoice_aggregated_taxes(
grouping_key_generator=grouping_key_generator,
filter_tax_values_to_apply=self._apply_invoice_tax_filter,
filter_invl_to_apply=self._apply_invoice_line_filter,
)

# Fixed Taxes: filter them on the document level, and adapt the totals
# Fixed taxes are not supposed to be taxes in real live. However, this is the way in Odoo to manage recupel
Expand Down
10 changes: 6 additions & 4 deletions addons/l10n_sa_edi/models/account_edi_xml_ubl_21_zatca.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def _l10n_sa_get_prepaid_amount(self, invoice, vals):
""" Calculate the down-payment amount according to ZATCA rules """
downpayment_lines = False if invoice._is_downpayment() else invoice.line_ids.filtered(lambda l: l._get_downpayment_lines())
if downpayment_lines:
tax_vals = invoice._prepare_edi_tax_details(filter_to_apply=lambda l, t: not self.env['account.tax'].browse(t['id']).l10n_sa_is_retention)
tax_vals = invoice._prepare_invoice_aggregated_taxes(
filter_tax_values_to_apply=lambda l, t: not self.env['account.tax'].browse(t['id']).l10n_sa_is_retention
)
base_amount = abs(sum(tax_vals['tax_details_per_record'][l]['base_amount_currency'] for l in downpayment_lines))
tax_amount = abs(sum(tax_vals['tax_details_per_record'][l]['tax_amount_currency'] for l in downpayment_lines))
return {
Expand Down Expand Up @@ -331,9 +333,9 @@ def grouping_key_generator(base_line, tax_values):
# values to set in the TaxableAmount and TaxAmount nodes on the InvoiceLine for the down payment.
# This means ZATCA will return a warning message for the BR-KSA-80 rule since it cannot calculate the
# TaxableAmount and the TaxAmount nodes correctly. To avoid this, we re-caclculate the taxes_vals just before
# we set the values for the down payment line, and we do not pass any filters to the _prepare_edi_tax_details
# method
line_taxes = line.move_id._prepare_edi_tax_details(grouping_key_generator=grouping_key_generator)
# we set the values for the down payment line, and we do not pass any filters to the
# _prepare_invoice_aggregated_taxes method
line_taxes = line.move_id._prepare_invoice_aggregated_taxes(grouping_key_generator=grouping_key_generator)
taxes_vals = line_taxes['tax_details_per_record'][line]

line_vals = super()._get_invoice_line_vals(line, taxes_vals)
Expand Down

0 comments on commit c8b5fdb

Please sign in to comment.