From 7b012259c4e83893888ab5b4463f17eec7ba921d Mon Sep 17 00:00:00 2001
From: "noe.izquierdo" <noe.izquierdo@openpyme.mx>
Date: Wed, 10 Apr 2024 10:02:50 -0600
Subject: [PATCH 01/17] feat(account.payment): se agregan correcciones para los
 totales traslados y retenciones

---
 l10n_mx_facturae/models/account_move.py       | 24 +++++++++++++++++++
 .../templates/account_payment.xml             |  8 +++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 063bb5549b..19599d4bfa 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -541,6 +541,18 @@ class AccountMoveLine(models.Model):
         "N° Pediment",
     )
 
+    l10n_mx_tax_base_dr = fields.Monetary(
+        compute="_compute_l10n_mx_tax_base_dr"
+    )
+
+    l10n_mx_tax_importe_dr = fields.Monetary(
+        compute="_compute_l10n_mx_tax_importe_dr"
+    )
+
+    l10n_mx_tax_currency_dr = fields.Monetary(
+        compute="_compue_l10n_mx_tax_currency_dr"
+    )
+
     @api.constrains("cfdi_cuentapredial")
     def _constraint_cfdi_cuentapredial(self):
         for record in self:
@@ -761,3 +773,15 @@ class AccountMoveLine(models.Model):
 
     def l10n_mx_facturae_importe(self):
         return "{0:.2f}".format(self.importe)
+
+    def _compute_l10n_mx_tax_base_dr(self):
+        for record in self:
+            return
+
+    def _compute_l10n_mx_tax_importe_dr(self):
+        for record in self:
+            return
+
+    def _compue_l10n_mx_tax_currency_dr(self):
+        for record in self:
+            return
diff --git a/l10n_mx_facturae/templates/account_payment.xml b/l10n_mx_facturae/templates/account_payment.xml
index 3b9dfe6de3..9305f84f16 100644
--- a/l10n_mx_facturae/templates/account_payment.xml
+++ b/l10n_mx_facturae/templates/account_payment.xml
@@ -54,10 +54,10 @@
                     <pago20:Totales
                         t-attf-MontoTotalPagos="{{ o.l10n_mx_facturae_payment_montototalpagos() }}"
                         t-att-TotalTrasladosBaseIVAExento="traslados.get('baseIVAExento', False)"
-                        t-att-TotalTrasladosBaseIVA16="format_float(traslados.get('baseIVA16.0', False), o.currency_id.decimal_places)"
-                        t-att-TotalTrasladosImpuestoIVA16="traslados.get('importeIVA16.0', False)"
-                        t-att-TotalTrasladosBaseIVA8="traslados.get('baseIVA8.0', False)"
-                        t-att-TotalTrasladosImpuestoIVA8="traslados.get('importeIVA8.0', False)"
+                        t-att-TotalTrasladosBaseIVA16="format_float(traslados.get('baseIVA16.0'), o.currency_id.decimal_places) if traslados.get('baseIVA16.0', False) else False"
+                        t-att-TotalTrasladosImpuestoIVA16="format_float(traslados.get('importeIVA16.0'), o.currency_id.decimal_places) if traslados.get('importeIVA16.0', False) else False"
+                        t-att-TotalTrasladosBaseIVA8="format_float(traslados.get('baseIVA8.0'), o.currency_id.decimal_places) if traslados.get('baseIVA8.0', False) else False"
+                        t-att-TotalTrasladosImpuestoIVA8="format_float(traslados.get('importeIVA8.0'), o.currency_id.decimal_places) if traslados.get('importeIVA8.0', False) else False"
                         t-att-TotalTrasladosBaseIVA0="traslados.get('baseIVA0.0', False)"
                         t-att-TotalTrasladosImpuestoIVA0="traslados.get('importeIVA0.0', False)"
                         t-att-TotalRetencionesIVA="retenciones.get('importeIVA', False)"
-- 
GitLab


From 91537a6ac06590c24948dea7a33a3f27f54b4a24 Mon Sep 17 00:00:00 2001
From: "noe.izquierdo" <noe.izquierdo@openpyme.mx>
Date: Thu, 11 Apr 2024 18:01:09 -0600
Subject: [PATCH 02/17] fix(account.payment): se agregan funciones para
 calcular la basedr e impuestodr en la moneda del dr

---
 l10n_mx_facturae/models/account_move.py       | 24 -------
 l10n_mx_facturae/models/account_payment.py    | 70 ++++++++-----------
 .../templates/account_payment.xml             |  8 +--
 3 files changed, 33 insertions(+), 69 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 19599d4bfa..063bb5549b 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -541,18 +541,6 @@ class AccountMoveLine(models.Model):
         "N° Pediment",
     )
 
-    l10n_mx_tax_base_dr = fields.Monetary(
-        compute="_compute_l10n_mx_tax_base_dr"
-    )
-
-    l10n_mx_tax_importe_dr = fields.Monetary(
-        compute="_compute_l10n_mx_tax_importe_dr"
-    )
-
-    l10n_mx_tax_currency_dr = fields.Monetary(
-        compute="_compue_l10n_mx_tax_currency_dr"
-    )
-
     @api.constrains("cfdi_cuentapredial")
     def _constraint_cfdi_cuentapredial(self):
         for record in self:
@@ -773,15 +761,3 @@ class AccountMoveLine(models.Model):
 
     def l10n_mx_facturae_importe(self):
         return "{0:.2f}".format(self.importe)
-
-    def _compute_l10n_mx_tax_base_dr(self):
-        for record in self:
-            return
-
-    def _compute_l10n_mx_tax_importe_dr(self):
-        for record in self:
-            return
-
-    def _compue_l10n_mx_tax_currency_dr(self):
-        for record in self:
-            return
diff --git a/l10n_mx_facturae/models/account_payment.py b/l10n_mx_facturae/models/account_payment.py
index d43314d24f..5acacfaa41 100644
--- a/l10n_mx_facturae/models/account_payment.py
+++ b/l10n_mx_facturae/models/account_payment.py
@@ -345,20 +345,8 @@ class AccountPayment(models.Model):
             tax_group = tax_rep_lines.mapped("tag_ids")
             key = tax_group.name + str(line["tax_id"].amount)
 
-            if company_currency != voucher_currency:
-                company_currency = company_currency.with_context(
-                    special_currency_rate=self.currency_rate(),
-                    special_currency=voucher_currency.id,
-                )
-                tax_totals["importe" + key] = company_currency.compute(
-                    line["importe"], voucher_currency,
-                )
-                tax_totals["base" + key] = company_currency.compute(
-                    line["tax_base"], voucher_currency,
-                )
-            else:
-                tax_totals["importe" + key] = line["importe"]
-                tax_totals["base" + key] = line["tax_base"]
+            tax_totals["importe" + key] = line["importe"]
+            tax_totals["base" + key] = line["tax_base"]
 
         return tax_totals
 
@@ -378,35 +366,11 @@ class AccountPayment(models.Model):
                         importe=0.0,
                     )
 
-                if tax_move.currency_id != voucher_currency:
-                    invoice_currency = (
-                        tax_move.currency_id
-                        if tax_move.currency_id else company_currency
-                    )
-                    invoice_currency = invoice_currency.with_context(date=self.date)
-                    if invoice_currency != company_currency:
-                        invoice_currency = invoice_currency.with_context(
-                            special_currency_rate=self.tipocambiodr(invoice),
-                            special_currency=invoice_currency.id,
-                        )
-                    else:
-                        invoice_currency = invoice_currency.with_context(
-                            special_currency_rate=(1 / self.tipocambiodr(invoice)),
-                            special_currency=voucher_currency.id,
-                        )
-                    tax_base = invoice_currency.compute(
-                        tax_move.tax_base_amount, voucher_currency, round=False,
-                    )
-                    # Force rounding 6 decimals to use as many decimal as possible and
-                    # avoid rounding errors when validating XML
-                    tax_base = float_round(
-                        tax_base, precision_digits=2, rounding_method="DOWN",
-                    )
-                else:
-                    tax_base = tax_move.tax_base_amount
+                tax_base = self._l10n_mx_tax_base_dr(invoice, tax_move)
+                importe = self._l10n_mx_tax_importe_dr(invoice, tax_move)
 
                 tax_totals[tax_move.tax_line_id.id]["tax_base"] += tax_base
-                tax_totals[tax_move.tax_line_id.id]["importe"] += abs(tax_move.balance)
+                tax_totals[tax_move.tax_line_id.id]["importe"] += importe
 
         return [line for line in tax_totals.values()]
 
@@ -429,3 +393,27 @@ class AccountPayment(models.Model):
             domain.append(("tax_line_id.amount_type", "=", "percent"))
 
         return domain
+
+    def _l10n_mx_tax_base_dr(self, invoice, tax_move):
+        amount = tax_move.tax_base_amount
+
+        if invoice.currency_id != self.company_id.currency_id:
+            account = (
+                tax_move.company_id.account_cash_basis_base_account_id or
+                tax_move.account_id
+            )
+            base_line = tax_move.move_id.line_ids.filtered(
+                lambda l:
+                    l.id != tax_move.id and l.account_id == account and l.tax_ids
+            )
+            amount = -1 * base_line.amount_currency
+
+        return amount
+
+    def _l10n_mx_tax_importe_dr(self, invoice, tax_move):
+        amount = tax_move.balance
+
+        if invoice.currency_id != self.company_id.currency_id:
+            amount = tax_move.amount_currency
+
+        return -1 * amount
diff --git a/l10n_mx_facturae/templates/account_payment.xml b/l10n_mx_facturae/templates/account_payment.xml
index 9305f84f16..eeec6bff47 100644
--- a/l10n_mx_facturae/templates/account_payment.xml
+++ b/l10n_mx_facturae/templates/account_payment.xml
@@ -58,8 +58,8 @@
                         t-att-TotalTrasladosImpuestoIVA16="format_float(traslados.get('importeIVA16.0'), o.currency_id.decimal_places) if traslados.get('importeIVA16.0', False) else False"
                         t-att-TotalTrasladosBaseIVA8="format_float(traslados.get('baseIVA8.0'), o.currency_id.decimal_places) if traslados.get('baseIVA8.0', False) else False"
                         t-att-TotalTrasladosImpuestoIVA8="format_float(traslados.get('importeIVA8.0'), o.currency_id.decimal_places) if traslados.get('importeIVA8.0', False) else False"
-                        t-att-TotalTrasladosBaseIVA0="traslados.get('baseIVA0.0', False)"
-                        t-att-TotalTrasladosImpuestoIVA0="traslados.get('importeIVA0.0', False)"
+                        t-att-TotalTrasladosBaseIVA0="format_float(traslados.get('baseIVA0.0'), o.currency_id.decimal_places) if traslados.get('baseIVA0.0', False) else False"
+                        t-att-TotalTrasladosImpuestoIVA0="format_float(traslados.get('importeIVA0.0'), o.currency_id.decimal_places) if traslados.get('importeIVA0.0', False) else False"
                         t-att-TotalRetencionesIVA="retenciones.get('importeIVA', False)"
                         t-att-TotalRetencionesISR="retenciones.get('importeISR', False)"
                         t-att-TotalRetencionesIEPS="retenciones.get('importeIEPS', False)" />
@@ -92,9 +92,9 @@
                                 </pago20:RetencionesDR>
                                 <pago20:TrasladosDR>
                                     <pago20:TrasladoDR t-foreach="o.impuestos_dr(invoice)" t-as="tax_move"
-                                        t-att-BaseDR="format_float(tax_move.tax_base_amount, invoice.currency_id.decimal_places)"
+                                        t-att-BaseDR="format_float(o._l10n_mx_tax_base_dr(invoice, tax_move), invoice.currency_id.decimal_places)"
                                         t-att-ImpuestoDR="format_impuesto(tax_move.tax_line_id)"
-                                        t-att-ImporteDR="format_float(abs(tax_move.balance), invoice.currency_id.decimal_places)"
+                                        t-att-ImporteDR="format_float(abs(o._l10n_mx_tax_importe_dr(invoice, tax_move)), invoice.currency_id.decimal_places)"
                                         t-att-TasaOCuotaDR="format_tasaocuota(tax_move.tax_line_id)"
                                         t-att-TipoFactorDR="tax_move.tax_line_id.l10n_mx_tax_type" />
                                 </pago20:TrasladosDR>
-- 
GitLab


From 41499162050314a5c911ac69dd4bd83777db1e1d Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Thu, 18 Apr 2024 10:34:11 -0600
Subject: [PATCH 03/17] =?UTF-8?q?feat(cancelaci=C3=B3n=20de=20facturas):?=
 =?UTF-8?q?=20se=20creo=20un=20campo=20boolean=20en=20el=20objeto=20accoun?=
 =?UTF-8?q?t.move,=20y=20un=20campo=20al=20xml?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py | 3 +++
 l10n_mx_facturae/views/account_move.xml | 1 +
 2 files changed, 4 insertions(+)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 063bb5549b..9ab48f3f88 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -17,6 +17,9 @@ class AccountMove(models.Model):
     _name = "account.move"
     _inherit = ["account.move", "base.cfdi"]
 
+    is_cancelable = fields.Boolean(
+        "Candidate is canceled"
+    )
     @property
     def formapago(self):
         """Return payment type for display on CFDI"""
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index f7d429a9fe..fefbbf1c4c 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -32,6 +32,7 @@
         <field name="arch" type="xml">
             <button name="button_cancel" position="before">
                 <field name="is_cfdi_candidate" invisible="1" />
+                <field name="is_cancelable" invisible="1" />
             </button>
             <xpath expr="//header" position="after">
                 <div
-- 
GitLab


From f1c15630f6b1365005db534c4bea0eb5ff1284c6 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Thu, 18 Apr 2024 18:10:12 -0600
Subject: [PATCH 04/17] =?UTF-8?q?Se=20agrego=20el=20boton=20Cancelar=20CFD?=
 =?UTF-8?q?I=20al=20header,=20se=20uso=20una=20funci=C3=B3n=20de=20ejemplo?=
 =?UTF-8?q?=20que=20imprime=20el=20hola=20mundo=20para=20que=20nos=20permi?=
 =?UTF-8?q?tiara=20crear=20el=20boton=20ya=20que=20la=20funci=C3=B3n=20es?=
 =?UTF-8?q?=20obligatoria=20y=20por=20ultimo=20se=20agregaron=20la=20condi?=
 =?UTF-8?q?ciones=20al=20attrs=20del=20boton=20creado=20para=20indicarlo?=
 =?UTF-8?q?=20cuando=20debe=20de=20estar=20visible?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py | 4 ++++
 l10n_mx_facturae/views/account_move.xml | 1 +
 2 files changed, 5 insertions(+)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 9ab48f3f88..cfef523c5d 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -20,6 +20,10 @@ class AccountMove(models.Model):
     is_cancelable = fields.Boolean(
         "Candidate is canceled"
     )
+    def l10n_mx_action_cancel(self):
+        print("Hola Mundo")
+
+
     @property
     def formapago(self):
         """Return payment type for display on CFDI"""
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index fefbbf1c4c..59c291ca18 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -31,6 +31,7 @@
         <field name="inherit_id" ref="account.view_move_form"/>
         <field name="arch" type="xml">
             <button name="button_cancel" position="before">
+            <button name="l10n_mx_action_cancel" string="Cancelar CFDI" type="object" class="btn-primary" attrs="{'invisible': [('state', '!=', 'posted'), ('cfdi_state', '!=', 'done')]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
                 <field name="is_cancelable" invisible="1" />
             </button>
-- 
GitLab


From baebf299fc65eb16edbfeeae23acafc4409788dc Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Fri, 19 Apr 2024 16:13:22 -0600
Subject: [PATCH 05/17] =?UTF-8?q?Se=20coloca=20el=20campo=20is=5Fcancelabl?=
 =?UTF-8?q?e=20despues=20de=20l10n=5Fmx=5Fexport,=20y=20se=20ajusta=20la?=
 =?UTF-8?q?=20identaci=C3=B3n=20en=20el=20modelo=20de=20vista?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py |  8 ++++----
 l10n_mx_facturae/views/account_move.xml | 13 ++++++++++++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index cfef523c5d..a170c923ce 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -17,13 +17,9 @@ class AccountMove(models.Model):
     _name = "account.move"
     _inherit = ["account.move", "base.cfdi"]
 
-    is_cancelable = fields.Boolean(
-        "Candidate is canceled"
-    )
     def l10n_mx_action_cancel(self):
         print("Hola Mundo")
 
-
     @property
     def formapago(self):
         """Return payment type for display on CFDI"""
@@ -161,6 +157,10 @@ class AccountMove(models.Model):
         string="Merchandise export",
     )
 
+    is_cancelable = fields.Boolean(
+        "Candidate is canceled"
+    )
+
     def button_validate(self):
         """
             Extend `AccountMove.button_validate`: prevents  to manipulate the
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index 59c291ca18..d5144b7db1 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -31,7 +31,18 @@
         <field name="inherit_id" ref="account.view_move_form"/>
         <field name="arch" type="xml">
             <button name="button_cancel" position="before">
-            <button name="l10n_mx_action_cancel" string="Cancelar CFDI" type="object" class="btn-primary" attrs="{'invisible': [('state', '!=', 'posted'), ('cfdi_state', '!=', 'done')]}"/>
+                <button name="l10n_mx_action_cancel"
+                        string="Cancel CFDI"
+                        type="object"
+                        class="btn-primary"
+                        attrs="{'invisible': [
+                        ('state', '!=', 'posted'),
+                         (
+                            'cfdi_state',
+                            '!=',
+                            'done'
+                         )
+                         ]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
                 <field name="is_cancelable" invisible="1" />
             </button>
-- 
GitLab


From fff622ff98efe9b35dcc0cf1646a7493fa460208 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 22 Apr 2024 13:26:55 -0600
Subject: [PATCH 06/17] =?UTF-8?q?Se=20coloca=20la=20funci=C3=B3n=20l10n=5F?=
 =?UTF-8?q?mx=5Faction=5Fcancel=20al=20final=20de=20las=20funciones=20de?=
 =?UTF-8?q?=20la=20clase=20account?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index a170c923ce..81bb604051 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -17,9 +17,6 @@ class AccountMove(models.Model):
     _name = "account.move"
     _inherit = ["account.move", "base.cfdi"]
 
-    def l10n_mx_action_cancel(self):
-        print("Hola Mundo")
-
     @property
     def formapago(self):
         """Return payment type for display on CFDI"""
@@ -527,6 +524,8 @@ class AccountMove(models.Model):
 
         return res
 
+    def l10n_mx_action_cancel(self):
+        print("Hola Mundo")
 
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
-- 
GitLab


From 364bce9b8aef4aca0a4388a181c0fe4bd526a899 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 22 Apr 2024 13:44:28 -0600
Subject: [PATCH 07/17] =?UTF-8?q?Se=20corrige=20la=20identaci=C3=B3n=20del?=
 =?UTF-8?q?=20bot=C3=B3n=20Cancel=20CFDI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/views/account_move.xml | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index d5144b7db1..90f997368a 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -36,12 +36,8 @@
                         type="object"
                         class="btn-primary"
                         attrs="{'invisible': [
-                        ('state', '!=', 'posted'),
-                         (
-                            'cfdi_state',
-                            '!=',
-                            'done'
-                         )
+                            ('state', '!=', 'posted'),
+                            ('cfdi_state', '!=', 'done')
                          ]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
                 <field name="is_cancelable" invisible="1" />
-- 
GitLab


From f9f81b8de3c2bdaf8e29a57376f60d870d41d198 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 22 Apr 2024 14:04:11 -0600
Subject: [PATCH 08/17] =?UTF-8?q?Se=20corrige=20la=20identaci=C3=B3n=20del?=
 =?UTF-8?q?=20boton=20tal=20cual=20esta=20mostrada=20en=20el=20ejemplo=20g?=
 =?UTF-8?q?it=20lab=20con=204=20espacios=20a=20su=20izquierda?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/views/account_move.xml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index 90f997368a..9bfd892623 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -32,15 +32,15 @@
         <field name="arch" type="xml">
             <button name="button_cancel" position="before">
                 <button name="l10n_mx_action_cancel"
-                        string="Cancel CFDI"
-                        type="object"
-                        class="btn-primary"
-                        attrs="{'invisible': [
-                            ('state', '!=', 'posted'),
-                            ('cfdi_state', '!=', 'done')
-                         ]}"/>
+                    string="Cancel CFDI"
+                    type="object"
+                    class="btn-primary"
+                    attrs="{'invisible': [
+                        ('state', '!=', 'posted'),
+                        ('cfdi_state', '!=', 'done')
+                    ]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
-                <field name="is_cancelable" invisible="1" />
+                <field name="is_cancelable" invisible="0" />
             </button>
             <xpath expr="//header" position="after">
                 <div
-- 
GitLab


From 7ec35c6afad7c5dea853dae8852f9f41394b19c2 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 22 Apr 2024 18:06:59 -0600
Subject: [PATCH 09/17] =?UTF-8?q?Se=20agrego=20la=20funci=C3=B3n=20que=20c?=
 =?UTF-8?q?ambia=20el=20estado=20de=20la=20celda=20is=5Fcancelable=20a=20T?=
 =?UTF-8?q?rue=20cuando=20se=20presiona=20el=20boton=20Cancel=20CFDI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py | 3 ++-
 l10n_mx_facturae/views/account_move.xml | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 81bb604051..04ab01abd9 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -525,7 +525,8 @@ class AccountMove(models.Model):
         return res
 
     def l10n_mx_action_cancel(self):
-        print("Hola Mundo")
+        # Call write() to update the is_cancelable field
+        self.write({'is_cancelable': True})
 
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index 9bfd892623..2cde0e337c 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -40,7 +40,7 @@
                         ('cfdi_state', '!=', 'done')
                     ]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
-                <field name="is_cancelable" invisible="0" />
+                <field name="is_cancelable" invisible="1" />
             </button>
             <xpath expr="//header" position="after">
                 <div
-- 
GitLab


From 88c0fd93497fbf7e55decd42f8afcd2846622592 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Tue, 23 Apr 2024 11:23:19 -0600
Subject: [PATCH 10/17] Se agrega el ciclo que filtra a las facturas por
 atributos

---
 l10n_mx_facturae/models/account_move.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 04ab01abd9..325d97e325 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -527,6 +527,17 @@ class AccountMove(models.Model):
     def l10n_mx_action_cancel(self):
         # Call write() to update the is_cancelable field
         self.write({'is_cancelable': True})
+        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
+        """Extend `AccountInvoice.action_cancel()`; Cancels the CFDI related to the
+        invoice
+        """
+        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
+        cfdis = self.filtered(
+            lambda i:
+                i.journal_id.sign_sat
+                and i.cfdi_id
+                and i.cfdi_id.state not in ["draft", "cancel"]
+        )
 
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
-- 
GitLab


From 85a3e046503f2c92988c84464ce16b3782cf3735 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Tue, 23 Apr 2024 13:10:11 -0600
Subject: [PATCH 11/17] Se agrega el ciclo for y dentro de este manda el
 mensaje al chatter siempre que el for se ejecute

---
 l10n_mx_facturae/models/account_move.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 325d97e325..2a995c376a 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -538,6 +538,18 @@ class AccountMove(models.Model):
                 and i.cfdi_id
                 and i.cfdi_id.state not in ["draft", "cancel"]
         )
+        for invoice in cfdis:
+            # Ensure we can cancel this invoice
+            invoice.check_if_can_cancel()
+            # If l10n_mx_edi_original_invoice is set save uuid to send info to PAC
+            # while cancel invoice
+            invoice.cfdi_id.substitute_cfdi_uuid = (
+                invoice.l10n_mx_edi_original_invoice.cfdi_id.uuid
+            )
+            invoice.message_post(
+                body=_("Cancellation request sent")
+            )
+            cancelacion = invoice.cancel_cfdi()[0]
 
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
-- 
GitLab


From 990b2d682067fc446e16112adb9a3f65cb90b44d Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Tue, 23 Apr 2024 13:17:46 -0600
Subject: [PATCH 12/17] Se agregaron codiciones

---
 l10n_mx_facturae/models/account_move.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 2a995c376a..1d29077802 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -550,6 +550,19 @@ class AccountMove(models.Model):
                 body=_("Cancellation request sent")
             )
             cancelacion = invoice.cancel_cfdi()[0]
+            if cancelacion:
+                # CFDI cancelled (cancelacion == True) must cancel invoice too
+                invoice.button_draft()
+                invoice.button_cancel()
+            elif cancelacion is None:
+                # CFDI set to approval (cancelacion == None) must set invoice
+                # to waiting too
+                invoice.write({"state": "waiting"})
+            elif cancelacion is False:
+                # CFDI cancel denied (cancelacion == False) must get back invoice
+                # to open state
+                self.undo_waiting_state()
+
 
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
-- 
GitLab


From 5ef61504f349f89380285ea758fa1436ba7b29f1 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Tue, 23 Apr 2024 18:19:30 -0600
Subject: [PATCH 13/17] =?UTF-8?q?Problema=20con=20la=20variable=20cancelac?=
 =?UTF-8?q?i=C3=B3n=20dentro=20del=20ciclo=20for=20en=20la=20funcion=20l10?=
 =?UTF-8?q?n=5Fmx=5Faction=5Fcancel?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_move.py | 65 ++-----------------------
 l10n_mx_facturae/views/account_move.xml |  1 +
 2 files changed, 6 insertions(+), 60 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 1d29077802..312a8c1041 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -320,42 +320,6 @@ class AccountMove(models.Model):
                 # Create new CFDI object for this invoice
                 account_invoice.create_cfdi()
 
-    def action_cancel(self):
-        """Extend `AccountMove.action_cancel()`; Cancels the CFDI related to the
-        invoice
-        """
-        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
-        cfdis = self.filtered(
-            lambda i:
-                i.journal_id.sign_sat
-                and i.cfdi_id
-                and i.cfdi_id.state not in ["draft", "cancel"]
-        )
-        for invoice in cfdis:
-            # Ensure we can cancel this invoice
-            invoice.check_if_can_cancel()
-            # If l10n_mx_edi_original_invoice is set save uuid to send info to PAC
-            # while cancel invoice
-            invoice.cfdi_id.substitute_cfdi_uuid = (
-                invoice.l10n_mx_edi_original_invoice.cfdi_id.uuid
-            )
-            cancelacion = invoice.cancel_cfdi()[0]
-            if cancelacion:
-                # CFDI cancelled (cancelacion == True) must cancel invoice too
-                super(AccountMove, invoice).action_cancel()
-            elif cancelacion is None:
-                # CFDI set to approval (cancelacion == None) must set invoice
-                # to waiting too
-                invoice.write({"state": "waiting"})
-            elif cancelacion is False:
-                # CFDI cancel denied (cancelacion == False) must get back invoice
-                # to open state
-                self.undo_waiting_state()
-
-        # Call super only with invoices without CFDI
-        invoices = self - cfdis
-        return super(AccountMove, invoices).action_cancel()
-
     def undo_waiting_state(self):
         """When cancel is negate revert invoice to open and post account_move"""
         for record in self:
@@ -525,12 +489,11 @@ class AccountMove(models.Model):
         return res
 
     def l10n_mx_action_cancel(self):
+        """Cancels the CFDI related to the invoice"""
+
         # Call write() to update the is_cancelable field
-        self.write({'is_cancelable': True})
-        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
-        """Extend `AccountInvoice.action_cancel()`; Cancels the CFDI related to the
-        invoice
-        """
+        self.write({"is_cancelable": True})
+
         # Get only invoices with related cfdi to cancel cfdi before cancel invoice
         cfdis = self.filtered(
             lambda i:
@@ -538,30 +501,12 @@ class AccountMove(models.Model):
                 and i.cfdi_id
                 and i.cfdi_id.state not in ["draft", "cancel"]
         )
+
         for invoice in cfdis:
-            # Ensure we can cancel this invoice
-            invoice.check_if_can_cancel()
-            # If l10n_mx_edi_original_invoice is set save uuid to send info to PAC
-            # while cancel invoice
-            invoice.cfdi_id.substitute_cfdi_uuid = (
-                invoice.l10n_mx_edi_original_invoice.cfdi_id.uuid
-            )
             invoice.message_post(
                 body=_("Cancellation request sent")
             )
             cancelacion = invoice.cancel_cfdi()[0]
-            if cancelacion:
-                # CFDI cancelled (cancelacion == True) must cancel invoice too
-                invoice.button_draft()
-                invoice.button_cancel()
-            elif cancelacion is None:
-                # CFDI set to approval (cancelacion == None) must set invoice
-                # to waiting too
-                invoice.write({"state": "waiting"})
-            elif cancelacion is False:
-                # CFDI cancel denied (cancelacion == False) must get back invoice
-                # to open state
-                self.undo_waiting_state()
 
 
 class AccountMoveLine(models.Model):
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index 2cde0e337c..bd0ec404a5 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -36,6 +36,7 @@
                     type="object"
                     class="btn-primary"
                     attrs="{'invisible': [
+                        '&amp;',
                         ('state', '!=', 'posted'),
                         ('cfdi_state', '!=', 'done')
                     ]}"/>
-- 
GitLab


From c6a747f3c993f3b1b2611bc951c2669943a2af3e Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Fri, 26 Apr 2024 12:26:20 -0600
Subject: [PATCH 14/17] Mensaje al chatter dentro del ciclo for y condiciones
 agregadas funcionando correctamente al cancelar la factura

---
 l10n_mx_facturae/models/account_move.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 312a8c1041..0f652b4d51 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -506,7 +506,19 @@ class AccountMove(models.Model):
             invoice.message_post(
                 body=_("Cancellation request sent")
             )
-            cancelacion = invoice.cancel_cfdi()[0]
+            cancelacion = invoice.cancel_cfdi()
+            if cancelacion:
+                # CFDI cancelled (cancelacion == True) must cancel invoice too
+                invoice.button_draft()
+                invoice.button_cancel()
+            elif cancelacion is None:
+                # CFDI set to approval (cancelacion == None) must set invoice
+                # to waiting too
+                invoice.write({"state": "waiting"})
+            elif cancelacion is False:
+                # CFDI cancel denied (cancelacion == False) must get back invoice
+                # to open state
+                self.undo_waiting_state()
 
 
 class AccountMoveLine(models.Model):
-- 
GitLab


From 818e5ef7997a80b21e14d09318e11c0087a3f636 Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 29 Apr 2024 12:37:16 -0600
Subject: [PATCH 15/17] Se hicieron las correcciones indicadas en los ultimos
 comentarios agregados al merge

---
 l10n_mx_facturae/models/account_move.py | 84 +++++++++++++------------
 l10n_mx_facturae/views/account_move.xml |  1 -
 2 files changed, 45 insertions(+), 40 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 0f652b4d51..2fb66e826a 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -154,10 +154,6 @@ class AccountMove(models.Model):
         string="Merchandise export",
     )
 
-    is_cancelable = fields.Boolean(
-        "Candidate is canceled"
-    )
-
     def button_validate(self):
         """
             Extend `AccountMove.button_validate`: prevents  to manipulate the
@@ -320,13 +316,56 @@ class AccountMove(models.Model):
                 # Create new CFDI object for this invoice
                 account_invoice.create_cfdi()
 
+    def l10n_mx_action_cancel(self):
+        """Cancels the CFDI related to the invoice"""
+
+        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
+        cfdis = self.filtered(
+            lambda i:
+                i.journal_id.sign_sat
+                and i.cfdi_id
+                and i.cfdi_id.state not in ["draft", "cancel"]
+        )
+
+        for invoice in cfdis:
+            invoice.message_post(
+                body=_("Cancellation request sent")
+            )
+            cancelacion = invoice.cancel_cfdi()
+            if cancelacion:
+                # CFDI cancelled (cancelacion == True) must cancel invoice too
+                invoice.button_draft()
+                invoice.button_cancel()
+            elif cancelacion is None:
+                # CFDI set to approval (cancelacion == None) must set invoice
+                # to waiting too
+                invoice.write({"state": "posted"})
+                invoice.message_post(
+                    body=_("Awaiting cancellation")
+                )
+            elif cancelacion is False:
+                # CFDI cancel denied (cancelacion == False) must get back invoice
+                # to open state
+                self.undo_waiting_state()
+                invoice.message_post(
+                    body=_("Denied cancellation")
+                )
+
     def undo_waiting_state(self):
         """When cancel is negate revert invoice to open and post account_move"""
         for record in self:
-            to_update = record.filtered(lambda i: i.state == "waiting")
-            to_update.write({"state": "open"})
+            to_update = record.filtered(lambda i: i.cfdi_state == "waiting")
+            to_update.write({"state": "posted"})
             to_update.mapped("move_id").post()
 
+    @api.depends("state", "cfdi_state")
+    def _compute_show_reset_to_draft_button(self):
+        super()._compute_show_reset_to_draft_button()
+
+        for move in self:
+            if move.state in ("posted", "cancel") and move.cfdi_state in ("signed", "done", "waiting", "cancel"):
+                move.show_reset_to_draft_button = False
+
     def action_consult_cancellation_status(self):
         """Verify cancellation status"""
         # TODO: Is this really needed? Maybe we can reuse the action_cancel
@@ -488,39 +527,6 @@ class AccountMove(models.Model):
 
         return res
 
-    def l10n_mx_action_cancel(self):
-        """Cancels the CFDI related to the invoice"""
-
-        # Call write() to update the is_cancelable field
-        self.write({"is_cancelable": True})
-
-        # Get only invoices with related cfdi to cancel cfdi before cancel invoice
-        cfdis = self.filtered(
-            lambda i:
-                i.journal_id.sign_sat
-                and i.cfdi_id
-                and i.cfdi_id.state not in ["draft", "cancel"]
-        )
-
-        for invoice in cfdis:
-            invoice.message_post(
-                body=_("Cancellation request sent")
-            )
-            cancelacion = invoice.cancel_cfdi()
-            if cancelacion:
-                # CFDI cancelled (cancelacion == True) must cancel invoice too
-                invoice.button_draft()
-                invoice.button_cancel()
-            elif cancelacion is None:
-                # CFDI set to approval (cancelacion == None) must set invoice
-                # to waiting too
-                invoice.write({"state": "waiting"})
-            elif cancelacion is False:
-                # CFDI cancel denied (cancelacion == False) must get back invoice
-                # to open state
-                self.undo_waiting_state()
-
-
 class AccountMoveLine(models.Model):
     _inherit = "account.move.line"
 
diff --git a/l10n_mx_facturae/views/account_move.xml b/l10n_mx_facturae/views/account_move.xml
index bd0ec404a5..fd28448063 100644
--- a/l10n_mx_facturae/views/account_move.xml
+++ b/l10n_mx_facturae/views/account_move.xml
@@ -41,7 +41,6 @@
                         ('cfdi_state', '!=', 'done')
                     ]}"/>
                 <field name="is_cfdi_candidate" invisible="1" />
-                <field name="is_cancelable" invisible="1" />
             </button>
             <xpath expr="//header" position="after">
                 <div
-- 
GitLab


From f4647afabe0adbcc4b97c0eec06156f958f64e2d Mon Sep 17 00:00:00 2001
From: "ricardo.mendoza" <ricardo.mendoza@openpyme.mx>
Date: Mon, 29 Apr 2024 15:56:41 -0600
Subject: [PATCH 16/17] Se elimina el campo state

---
 l10n_mx_facturae/models/account_move.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/l10n_mx_facturae/models/account_move.py b/l10n_mx_facturae/models/account_move.py
index 2fb66e826a..3bdc1422f9 100644
--- a/l10n_mx_facturae/models/account_move.py
+++ b/l10n_mx_facturae/models/account_move.py
@@ -124,10 +124,6 @@ class AccountMove(models.Model):
         "cfdi.use", "CFDI use", readonly=True, states={"draft": [("readonly", False)]}
     )
     cfdi_relation_type = fields.Many2one("cfdi.relation.type", "CFDI Relation type")
-    state = fields.Selection(
-        selection_add=[("waiting", _("To cancel"))],
-        ondelete={'waiting': 'cascade'}
-    )
     l10n_mx_edi_to_cancel = fields.Char(
         #compute="_compute_l10n_mx_edi_to_cancel",
         #search="_search_l10n_mx_edi_to_cancel",
-- 
GitLab


From 9d464eb016b107084843d50a3553ced5bea4343a Mon Sep 17 00:00:00 2001
From: "jesus.lomas" <jesus.lomas@openpyme.mx>
Date: Mon, 29 Apr 2024 13:28:40 -0600
Subject: [PATCH 17/17] =?UTF-8?q?feat(res.company):=20a=20la=20compa=C3=B1?=
 =?UTF-8?q?ia=20fronteriza=20se=20le=20agreg=C3=B3=20el=20regimen=20fiscal?=
 =?UTF-8?q?=20y=20el=20uso=20del=20cfdi?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

a la compañia fronteriza se le agregó el regimen fiscal y el uso del cfdi, ademas se creo el parther
de Maria Olivia
---
 l10n_mx_facturae/demo/demo_res_partner.xml | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/l10n_mx_facturae/demo/demo_res_partner.xml b/l10n_mx_facturae/demo/demo_res_partner.xml
index 941161b955..2ec790f9f7 100644
--- a/l10n_mx_facturae/demo/demo_res_partner.xml
+++ b/l10n_mx_facturae/demo/demo_res_partner.xml
@@ -25,4 +25,31 @@
         <field name="payment_method_id" ref="l10n_mx_base.cfdi_payment_method_1"/>
     </record>
 
+    <record id="l10n_mx_ir_attachment_facturae.demo_partner_company_mx_frontier" model="res.partner">
+        <field name="cfdi_fiscal_regime_id" ref="l10n_mx_base.regime_fiscal_601"/>
+        <field name="cfdi_use_id" ref="l10n_mx_base.cfdi_use_S01"/>
+    </record>
+
+    <record id="l10n_mx_ir_attachment_facturae.res_company_mx_frontier" model="res.company">
+        <field name="cfdi_fiscal_regime_id" ref="l10n_mx_base.regime_fiscal_601"/>
+        <field name="cfdi_use_id" ref="l10n_mx_base.cfdi_use_S01"/>
+    </record>
+
+   <record id="res_partner_2024" model="res.partner">
+        <field name="name">Maria Olivia Martinez Sagaz</field>
+        <field name="is_company">1</field>
+        <field name="street">45 10 oriente</field>
+        <field name="city">Culiacán</field>
+        <field name="state_id" ref="base.state_mx_sin"/>
+        <field name="zip">80290</field>
+        <field name="vat">MXMASO451221PM4</field>
+        <field name="phone">(870)-931-0505</field>
+        <field name="country_id" ref="base.mx"/>
+        <field name="email">maria.martinez@example.com</field>
+        <field name="company_id" ref="l10n_mx_ir_attachment_facturae.res_company_mx_frontier"/>
+        <field name="cfdi_fiscal_regime_id" ref="l10n_mx_base.regime_fiscal_616"/>
+        <field name="cfdi_use_id" ref="l10n_mx_base.cfdi_use_S01"/>
+        <field name="payment_method_id" ref="l10n_mx_base.cfdi_payment_method_1"/>
+   </record>
+
 </odoo>
-- 
GitLab