[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 <jjs@adhoc.com.ar>
This commit is contained in:
Bruno Zanotti (ADHOC)
2021-10-14 16:16:04 +00:00
committed by Bruno Zanotti
co-authored by Juan Jose Scarafia
parent ee7e20f49d
commit 33c7f7d437
5 changed files with 74 additions and 22 deletions
+1
View File
@@ -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
+23 -1
View File
@@ -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']
@@ -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,
}
@@ -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
+20 -15
View File
@@ -114,33 +114,39 @@
</td>
<!-- use latam prices (to include/exclude VAT) -->
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" position="before">
<t t-set="l10n_ar_values" t-value="line._l10n_ar_prices_and_taxes()"/>
</t>
<xpath expr="//span[@t-field='line.price_unit']" position="attributes">
<attribute name="t-field">line.l10n_latam_price_unit</attribute>
</xpath>
<xpath expr="//span[@id='line_tax_ids']" position="attributes">
<attribute name="t-esc">', '.join(map(lambda x: (x.description or x.name), line.l10n_latam_tax_ids))</attribute>
<attribute name="t-field"></attribute>
<attribute name="t-esc">l10n_ar_values['price_unit']</attribute>
<attribute name="t-options">{"widget": "monetary", "display_currency": o.currency_id}</attribute>
</xpath>
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" position="attributes">
<attribute name="t-value">current_subtotal + line.l10n_latam_price_subtotal</attribute>
<attribute name="t-value">current_subtotal + l10n_ar_values['price_subtotal']</attribute>
</t>
<!-- if b2c we still wants the latam subtotal -->
<t t-set="current_subtotal" t-value="current_subtotal + line.price_total" position="attributes">
<attribute name="t-value">current_subtotal + line.l10n_latam_price_subtotal</attribute>
<attribute name="t-value">current_subtotal + l10n_ar_values['price_subtotal']</attribute>
</t>
<!-- label amount for subtotal column on b2b and b2c -->
<xpath expr="//th[@name='th_subtotal']/span[@groups='account.group_show_line_subtotals_tax_included']" position="replace">
<span groups="account.group_show_line_subtotals_tax_included">Amount</span>
</xpath>
<span t-field="line.price_subtotal" position="attributes">
<attribute name="t-field">line.l10n_latam_price_subtotal</attribute>
<attribute name="t-field"></attribute>
<attribute name="t-esc">l10n_ar_values['price_subtotal']</attribute>
<attribute name="t-options">{"widget": "monetary", "display_currency": o.currency_id}</attribute>
</span>
<!-- if b2c we still wants the latam subtotal -->
<span t-field="line.price_total" position="attributes">
<attribute name="t-field">line.l10n_latam_price_subtotal</attribute>
<attribute name="t-field"></attribute>
<attribute name="t-esc">l10n_ar_values['price_subtotal']</attribute>
<attribute name="t-options">{"widget": "monetary", "display_currency": o.currency_id}</attribute>
</span>
<t t-set="tax_totals" position="attributes">
<attribute name="t-value">o._get_tax_totals_for_latam_invoice_report()</attribute>
<attribute name="t-value">o._l10n_ar_get_invoice_totals_for_report()</attribute>
</t>
<!-- use column vat instead of taxes and only if vat discriminated -->
@@ -148,16 +154,15 @@
<span>% VAT</span>
</xpath>
<xpath expr="//th[@name='th_taxes']" position="attributes">
<attribute name="t-if">o.tax_totals_json</attribute>
</xpath>
<!-- use column vat instead of taxes and only list vat taxes-->
<xpath expr="//th[@name='th_taxes']" position="attributes">
<attribute name="t-if">not o._l10n_ar_include_vat()</attribute>
</xpath>
<xpath expr="//span[@id='line_tax_ids']/.." position="attributes">
<attribute name="t-if">o.tax_totals_json</attribute>
<attribute name="t-if">not o._l10n_ar_include_vat()</attribute>
</xpath>
<span id="line_tax_ids" position="attributes">
<attribute name="t-esc">', '.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)))</attribute>
<attribute name="t-esc">', '.join(map(lambda x: (x.description or x.name), line.tax_ids.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code)))</attribute>
</span>
<!-- remove payment reference that is not used in Argentina -->