[IMP] l10n_cl: calculate removed latam fields
Adapt the module to calculate removed fields from latam localization closes odoo/odoo#78296 X-original-commit: 9269ac23e86cfd0218234360ac8271785697a725 Signed-off-by: Josse Colpaert <jco@openerp.com> Co-authored-by: Juan Jose Scarafia <jjs@adhoc.com.ar>
This commit is contained in:
committed by
Bruno Zanotti
co-authored by
Juan Jose Scarafia
parent
33c7f7d437
commit
ab9f36db24
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from . import account_chart_template
|
||||
from . import account_move
|
||||
from . import account_move_line
|
||||
from . import account_tax
|
||||
from . import l10n_latam_document_type
|
||||
from . import res_company
|
||||
|
||||
@@ -42,7 +42,6 @@ class AccountMove(models.Model):
|
||||
domain += [('code', 'in', [])]
|
||||
return domain
|
||||
|
||||
|
||||
def _check_document_types_post(self):
|
||||
for rec in self.filtered(
|
||||
lambda r: r.company_id.account_fiscal_country_id.code == "CL" and
|
||||
@@ -120,3 +119,26 @@ class AccountMove(models.Model):
|
||||
if self.l10n_latam_use_documents and self.company_id.account_fiscal_country_id.code == 'CL':
|
||||
return 'l10n_cl.report_invoice_document'
|
||||
return super()._get_name_invoice_report()
|
||||
|
||||
def _l10n_cl_get_invoice_totals_for_report(self):
|
||||
self.ensure_one()
|
||||
tax_ids_filter = tax_line_id_filter = None
|
||||
include_sii = self._l10n_cl_include_sii()
|
||||
|
||||
if include_sii:
|
||||
tax_ids_filter = (lambda aml, tax: bool(tax.l10n_cl_sii_code != 14))
|
||||
tax_line_id_filter = (lambda aml, tax: bool(tax.l10n_cl_sii_code != 14))
|
||||
|
||||
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_sii:
|
||||
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_cl_include_sii(self):
|
||||
self.ensure_one()
|
||||
return self.l10n_latam_document_type_id.code in ['39', '41', '110', '111', '112', '34']
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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_cl_prices_and_taxes(self):
|
||||
self.ensure_one()
|
||||
invoice = self.move_id
|
||||
included_taxes = self.tax_ids.filtered(lambda x: x.l10n_cl_sii_code == 14) if self.move_id._l10n_cl_include_sii() 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
|
||||
}
|
||||
@@ -28,10 +28,3 @@ class L10nLatamDocumentType(models.Model):
|
||||
return False
|
||||
|
||||
return document_number.zfill(6)
|
||||
|
||||
def _filter_taxes_included(self, taxes):
|
||||
""" In Chile we include taxes depending on document type """
|
||||
self.ensure_one()
|
||||
if self.country_id.code == "CL" and self.code in ['39', '41', '110', '111', '112', '34']:
|
||||
return taxes.filtered(lambda x: x.l10n_cl_sii_code == 14)
|
||||
return super()._filter_taxes_included(taxes)
|
||||
|
||||
@@ -138,16 +138,22 @@
|
||||
|
||||
<xpath expr="//h2" position="replace"/>
|
||||
|
||||
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" position="before">
|
||||
<t t-set="l10n_cl_values" t-value="line._l10n_cl_prices_and_taxes()"/>
|
||||
</t>
|
||||
|
||||
<xpath expr="//span[@t-field='line.price_unit']" position="attributes">
|
||||
<attribute name="t-field">line.l10n_latam_price_unit</attribute>
|
||||
<attribute name="t-field"></attribute>
|
||||
<attribute name="t-esc">line.price_unit</attribute>
|
||||
<attribute name="t-options">{"widget": "monetary", "display_currency": o.currency_id}</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-esc">', '.join(map(lambda x: (x.description or x.name), line.tax_lines))</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_cl_values['price_subtotal']</attribute>
|
||||
</t>
|
||||
|
||||
<xpath expr="//th[@name='th_subtotal']/span[@groups='account.group_show_line_subtotals_tax_included']" position="replace">
|
||||
@@ -155,11 +161,13 @@
|
||||
</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">current_subtotal + l10n_cl_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_cl_get_invoice_totals_for_report()</attribute>
|
||||
</t>
|
||||
|
||||
<xpath expr="//th[@name='th_taxes']" position="replace"/>
|
||||
|
||||
Reference in New Issue
Block a user