From 33c7f7d4373d56b63e7684b23d498c680eec0471 Mon Sep 17 00:00:00 2001 From: "Bruno Zanotti (ADHOC)" Date: Thu, 8 Apr 2021 12:17:34 +0000 Subject: [PATCH] [IMP] l10n_ar: calculate removed latam fields Adapt the module to calculate removed fields from latam localization X-original-commit: c9536ab129c96582a784efe6a5bce133cad0d650 Part-of: odoo/odoo#78296 Co-authored-by: Juan Jose Scarafia --- addons/l10n_ar/models/__init__.py | 1 + addons/l10n_ar/models/account_move.py | 24 ++++++++++++- addons/l10n_ar/models/account_move_line.py | 30 ++++++++++++++++ .../models/l10n_latam_document_type.py | 6 ---- addons/l10n_ar/views/report_invoice.xml | 35 +++++++++++-------- 5 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 addons/l10n_ar/models/account_move_line.py diff --git a/addons/l10n_ar/models/__init__.py b/addons/l10n_ar/models/__init__.py index 4f7205335f3..02a1d06c8aa 100644 --- a/addons/l10n_ar/models/__init__.py +++ b/addons/l10n_ar/models/__init__.py @@ -15,3 +15,4 @@ from . import res_partner_bank from . import uom_uom from . import account_chart_template from . import account_move +from . import account_move_line diff --git a/addons/l10n_ar/models/account_move.py b/addons/l10n_ar/models/account_move.py index 07045bf968a..4e6a7885605 100644 --- a/addons/l10n_ar/models/account_move.py +++ b/addons/l10n_ar/models/account_move.py @@ -2,7 +2,6 @@ from odoo import models, fields, api, _ from odoo.exceptions import UserError, RedirectWarning, ValidationError from dateutil.relativedelta import relativedelta -from lxml import etree import logging _logger = logging.getLogger(__name__) @@ -293,3 +292,26 @@ class AccountMove(models.Model): if self.l10n_latam_use_documents and self.company_id.account_fiscal_country_id.code == 'AR': return 'l10n_ar.report_invoice_document' return super()._get_name_invoice_report() + + def _l10n_ar_get_invoice_totals_for_report(self): + self.ensure_one() + tax_ids_filter = tax_line_id_filter = None + include_vat = self._l10n_ar_include_vat() + + if include_vat: + tax_ids_filter = (lambda aml, tax: not bool(tax.tax_group_id.l10n_ar_vat_afip_code)) + tax_line_id_filter = (lambda aml, tax: not bool(tax.tax_group_id.l10n_ar_vat_afip_code)) + + tax_lines_data = self._prepare_tax_lines_data_for_totals_from_invoice( + tax_ids_filter=tax_ids_filter, tax_line_id_filter=tax_line_id_filter) + + if include_vat: + amount_untaxed = self.currency_id.round( + self.amount_total - sum([x['tax_amount'] for x in tax_lines_data if 'tax_amount' in x])) + else: + amount_untaxed = self.amount_untaxed + return self._get_tax_totals(self.partner_id, tax_lines_data, self.amount_total, amount_untaxed, self.currency_id) + + def _l10n_ar_include_vat(self): + self.ensure_one() + return self.l10n_latam_document_type_id.l10n_ar_letter in ['B', 'C', 'X', 'R'] diff --git a/addons/l10n_ar/models/account_move_line.py b/addons/l10n_ar/models/account_move_line.py new file mode 100644 index 00000000000..043a30718c5 --- /dev/null +++ b/addons/l10n_ar/models/account_move_line.py @@ -0,0 +1,30 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import models + + +class AccountMoveLine(models.Model): + + _inherit = 'account.move.line' + + def _l10n_ar_prices_and_taxes(self): + self.ensure_one() + invoice = self.move_id + included_taxes = self.tax_ids.filtered('tax_group_id.l10n_ar_vat_afip_code') if self.move_id._l10n_ar_include_vat() else self.tax_ids + if not included_taxes: + price_unit = self.tax_ids.with_context(round=False).compute_all( + self.price_unit, invoice.currency_id, 1.0, self.product_id, invoice.partner_id) + price_unit = price_unit['total_excluded'] + price_subtotal = self.price_subtotal + else: + price_unit = included_taxes.compute_all( + self.price_unit, invoice.currency_id, 1.0, self.product_id, invoice.partner_id)['total_included'] + price = self.price_unit * (1 - (self.discount or 0.0) / 100.0) + price_subtotal = included_taxes.compute_all( + price, invoice.currency_id, self.quantity, self.product_id, invoice.partner_id)['total_included'] + price_net = price_unit * (1 - (self.discount or 0.0) / 100.0) + + return { + 'price_unit': price_unit, + 'price_subtotal': price_subtotal, + 'price_net': price_net, + } diff --git a/addons/l10n_ar/models/l10n_latam_document_type.py b/addons/l10n_ar/models/l10n_latam_document_type.py index 5e15ad774d9..ed7beedf3e7 100644 --- a/addons/l10n_ar/models/l10n_latam_document_type.py +++ b/addons/l10n_ar/models/l10n_latam_document_type.py @@ -31,12 +31,6 @@ class L10nLatamDocumentType(models.Model): ('X', 'X'), ('I', 'I'), # used for mapping of imports ] - def _filter_taxes_included(self, taxes): - """ In argentina we include taxes depending on document letter """ - self.ensure_one() - if self.country_id.code == "AR" and self.l10n_ar_letter in ['B', 'C', 'X', 'R']: - return taxes.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code) - return super()._filter_taxes_included(taxes) def _format_document_number(self, document_number): """ Make validation of Import Dispatch Number diff --git a/addons/l10n_ar/views/report_invoice.xml b/addons/l10n_ar/views/report_invoice.xml index 7cf4d5e3e75..861ffb5695d 100644 --- a/addons/l10n_ar/views/report_invoice.xml +++ b/addons/l10n_ar/views/report_invoice.xml @@ -114,33 +114,39 @@ + + + - line.l10n_latam_price_unit - - - ', '.join(map(lambda x: (x.description or x.name), line.l10n_latam_tax_ids)) + + l10n_ar_values['price_unit'] + {"widget": "monetary", "display_currency": o.currency_id} - current_subtotal + line.l10n_latam_price_subtotal + current_subtotal + l10n_ar_values['price_subtotal'] - current_subtotal + line.l10n_latam_price_subtotal + current_subtotal + l10n_ar_values['price_subtotal'] Amount - line.l10n_latam_price_subtotal + + l10n_ar_values['price_subtotal'] + {"widget": "monetary", "display_currency": o.currency_id} - line.l10n_latam_price_subtotal + + l10n_ar_values['price_subtotal'] + {"widget": "monetary", "display_currency": o.currency_id} - o._get_tax_totals_for_latam_invoice_report() + o._l10n_ar_get_invoice_totals_for_report() @@ -148,16 +154,15 @@ % VAT - - o.tax_totals_json - - + + not o._l10n_ar_include_vat() + - o.tax_totals_json + not o._l10n_ar_include_vat() - ', '.join(map(lambda x: (x.description or x.name), line.l10n_latam_tax_ids.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code))) + ', '.join(map(lambda x: (x.description or x.name), line.tax_ids.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code)))