feat(accoun_move): creación del nodo impuestos_locales

Se realizo la creación del nodo de impuestos locales para timbrar facturas con el impuesto del 5 al
millar.
parent 1ecc60df
Pipeline #24402 failed with stages
in 10 minutes and 48 seconds
......@@ -50,10 +50,11 @@ class AccountMove(models.Model):
self.subtotal
- self.descuento
+ self.impuestos["total_traslados"]
+ self.impuestos["total_retenciones"]
- self.impuestos["total_retenciones"]
+ self.impuestos["total_locales"]
)
@property
def impuestos(self):
"""Return computed taxes for display on CFDI"""
......@@ -98,6 +99,7 @@ class AccountMove(models.Model):
taxes["total_locales"] += tax.amount
return taxes
# pylint: disable=W0212
address_issued_id = fields.Many2one(
"res.partner",
......@@ -538,20 +540,62 @@ class AccountMove(models.Model):
return unit
@api.model
def l10n_mx_facturae_compute_total_traslados(self, taxes):
res = False
if any(tax.type != "Excento" for tax in taxes["traslados"]):
res = taxes["total_traslados"]
"""
Calculate the total number of tax transfers.
return '{0:.2f}'.format(res)
:param dict taxes: Dictionary that includes computed total_retenciones as a float number
"""
total_traslados = taxes.get("total_traslados", 0.0)
return "{0:.2f}".format(total_traslados)
@api.model
def l10n_mx_facturae_compute_total_retenciones(self, taxes):
res = False
if taxes["total_retenciones"]:
res = taxes["total_retenciones"]
'{0:.2f}'.format(res)
"""
Calculate the total withholdings (including local taxes if applicable).
:param dict taxes: Dictionary that includes computed total_retenciones as a float number
"""
total_retenciones = taxes.get("total_retenciones", 0.0)
return "{0:.2f}".format(total_retenciones)
@api.model
def l10n_mx_facturae_total_traslados_locales(self, taxes):
"""
Gets the value of the key `total_retenciones` and if it is greater than zero,
returns the absolute value formatted with two decimal places as a text string.
:param data: Dictionary containing the key `total_retenciones`.
:return: Text string with the absolute value formatted with two decimal places,
or an empty string if it does not meet the condition.
"""
total_traslados = taxes.get("total_locales", 0)
total_locales = total_traslados if total_traslados > 0.0 else 0.0
return "{0:.2f}".format(total_locales)
@api.model
def l10n_mx_facturae_total_retenciones_locales(self, taxes):
"""
Gets the value of the key `total_retenciones` and if it is less than zero,
returns the absolute value formatted with two decimal places as a text string.
:param data: Dictionary containing the key `total_retenciones`.
:return: Text string with the absolute value formatted with two decimal places,
or an empty string if it does not meet the condition.
"""
total_retenciones = taxes.get('total_retenciones', 0)
total_locales = total_retenciones if total_retenciones < 0.0 else 0.0
return "{0:.2f}".format(total_locales)
@api.model
def calcular_impuestos(o):
taxes = o.impuestos
show_total_traslados = any(tax.type != "none" for tax in taxes["traslados"])
is_local_taxes = bool(taxes["total_locales"])
return show_total_traslados, is_local_taxes
return res
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
......@@ -699,6 +743,16 @@ class AccountMoveLine(models.Model):
)
# TODO: What happen when more than one tag is found?
tax_group = tax_rep_lines.mapped("tag_ids")[0]
if not tax_rep_lines.mapped("tag_ids"):
raise UserError(
"The configured tax has no tags assigned.\n"
"Please review the tax configuration and make sure that tax tags (tag_ids) have been assigned.\n\n"
"To correct this:\n"
"1. Go to tax configuration under 'Accounting > Setup > Taxes'.\n"
"2. Select the appropriate tax.\n"
"3. Assign a tax tag in the 'Tax Table' field.\n"
"4. Save the changes."
)
# IEPS tax only must be included when partner is IEPS subjected
if tax_group.name == "IEPS" and not partner.ieps_subjected:
return
......@@ -708,7 +762,7 @@ class AccountMoveLine(models.Model):
"002" if tax_group.name == "IVA" else "003"
)
tax["type"] = tax_record.l10n_mx_tax_type
tax["xml_amount"] = "{0:.2f}".format(tax["amount"])
tax["xml_amount"] = "{0:.2f}".format(abs(tax["amount"]))
tax["TasaOCuota"] = "{0:.6f}".format(abs(tax_record.amount)/100)
return tax
......
No preview for this file type
......@@ -3,8 +3,11 @@
<template id="account_move">
<t t-set="move" t-value="docs[0]" />
<t t-set="taxes" t-value="move.impuestos" />
<t t-set="is_local_taxes" t-value="bool(taxes.get('total_locales'))" />
<t t-set="total_traslados" t-value="move.l10n_mx_facturae_compute_total_traslados(taxes)" />
<t t-set="total_retenciones" t-value="move.l10n_mx_facturae_compute_total_retenciones(taxes)" />
<t t-set="total_traslados_locales" t-value="move.l10n_mx_facturae_total_traslados_locales(taxes)" />
<t t-set="total_retenciones_locales" t-value="move.l10n_mx_facturae_total_retenciones_locales(taxes)" />
<t t-set="tipoCambio" t-value="move.l10n_mx_facturae_compute_tipocambio()"/>
<t t-set="residenciaFiscal" t-value="move.l10n_mx_facturae_compute_residencia_fiscal()"/>
<t t-set="regimenTrib" t-value="move.l10n_mx_facturae_compute_regimen_tributario()"/>
......@@ -99,39 +102,36 @@
t-attf-Impuesto="{{ tax.xml_name }}"
t-attf-Importe="{{ tax.xml_amount }}" />
</cfdi:Retenciones>
<cfdi:Traslados t-if="line.impuestos['traslados']">
<t t-set="impuestos" t-value="line.impuestos"/>
<cfdi:Traslado t-foreach="impuestos['traslados']" t-as="tax"
<cfdi:Traslados t-if="line.impuestos['traslados']">
<t t-set="impuestos" t-value="line.impuestos"/>
<cfdi:Traslado t-foreach="impuestos['traslados']" t-as="tax"
t-att-Base="format_float(tax.base, o.currency_id.decimal_places)"
t-attf-Impuesto="{{ tax.xml_name }}"
t-attf-TipoFactor="{{ tax.type }}"
t-attf-TasaOCuota="{{ tax.TasaOCuota }}"
t-attf-Importe="{{ tax.xml_amount }}" />
</cfdi:Traslados>
</cfdi:Traslados>
</cfdi:Impuestos>
<!--
<cfdi:Complemento t-if="is_local_taxes">
<implocal:ImpuestosLocales
<cfdi:ImpuestosLocales
t-attf-version="1.0"
t-attf-TotaldeTraslados="${ '{0:.2f}'.format(sumif(taxes.locales, 'amount', [('amount', '>', 0)])) }"
t-attf-TotaldeRetenciones="${ '{0:.2f}'.format(abs(sumif(taxes.locales, 'amount', [('amount', '<', 0)]))) }">
<implocal:TrasladosLocales
t-foreach="taxes.locales" t-as="tax_line"
t-if="tax_line.amount > 0"
t-attf-ImpLocTrasladado="html_escape(tax_line.name)"
t-attf-TasadeTraslado="${ '{0:.2f}'.format(tax_line.TasaOCuota * 100) }"
t-attf-Importe="tax_line.amount" />
<implocal:RetencionesLocales
t-foreach="taxes.locales" t-as="tax_line"
t-if="tax_line.amount < 0"
t-attf-ImpLocRetenido="html_escape(tax_line.name)"
t-attf-TasadeRetencion="tax_line.TasaOCuota * 100 }"
t-attf-Importe="tax_line.amount" />
</implocal:ImpuestosLocales>
t-attf-TotaldeTraslados="{{ o.l10n_mx_facturae_total_traslados_locales(taxes) }}"
t-attf-TotaldeRetenciones="{{ o.l10n_mx_facturae_total_retenciones_locales(taxes) }}">
<cfdi:TrasladosLocales
t-foreach="taxes['locales']" t-as="tax_line"
t-if="tax_line.amount"
t-attf-ImpLocTrasladado="{{ tax_line.xml_name }}"
t-attf-TasadeTraslado="{{ tax_line.TasaOCuota }}"
t-attf-Importe="{{ tax_line.xml_amount }}" />
<cfdi:RetencionesLocales
t-foreach="taxes['locales']" t-as="tax_line"
t-if="tax_line.amount"
t-attf-ImpLocRetenido="{{ tax_line.xml_name }}"
t-attf-TasadeRetencion="{{ tax_line.TasaOCuota }}"
t-attf-Importe="{{ tax_line.xml_amount }}" />
</cfdi:ImpuestosLocales>
</cfdi:Complemento>
-->
</cfdi:Comprobante>
</template>
</odoo>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment