From e2f5af263b96cf1814ef4afd7a340a36652dbcff Mon Sep 17 00:00:00 2001
From: "jesus.lomas" <jesus.lomas@openpyme.mx>
Date: Thu, 16 May 2024 10:00:36 -0600
Subject: [PATCH] =?UTF-8?q?feat(cancelaci=C3=B3n=20de=20cfdi's=20de=20comp?=
 =?UTF-8?q?lementos=20de=20pago):=20agregar=20boton?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 l10n_mx_facturae/models/account_payment.py |  4 +++-
 l10n_mx_facturae/views/account_payment.xml | 10 ++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/l10n_mx_facturae/models/account_payment.py b/l10n_mx_facturae/models/account_payment.py
index ef11f80259..bf5636be1b 100644
--- a/l10n_mx_facturae/models/account_payment.py
+++ b/l10n_mx_facturae/models/account_payment.py
@@ -145,7 +145,9 @@ class AccountPayment(models.Model):
     def replace_cfdi(self):
         """Cancel voucher cfdi by replacing with 1 MXN voucher"""
         for record in self:
-            self._cancel_cfdi()
+            record.cancel_cfdi()
+            record.action_draft()
+            record.action_cancel()
 
     def currency_rate(self):
         """Compute currency rate used for current voucher to display on XML
diff --git a/l10n_mx_facturae/views/account_payment.xml b/l10n_mx_facturae/views/account_payment.xml
index c35f3805ce..fbee1ae857 100644
--- a/l10n_mx_facturae/views/account_payment.xml
+++ b/l10n_mx_facturae/views/account_payment.xml
@@ -24,6 +24,11 @@
         <field name="model">account.payment</field>
         <field name="inherit_id" ref="account.view_account_payment_form"/>
         <field name="arch" type="xml">
+             <button name="action_draft" position="attributes">
+                <attribute name="attrs">
+                    {'invisible': ['&amp;',('state', 'in', ('posted', 'cancel')),('cfdi_state', 'in', ('done', 'cancel'))]}
+                </attribute>
+            </button>
             <button name="action_post" position="after">
                 <button name="sign_payment" type="object" string="Sign"
                     class="oe_highlight"
@@ -33,8 +38,9 @@
                         ('cfdi_state', '!=', False)
                     ]}" />
                 <!--<button name="substitute_payment" type="object" string="Replace"
-                    attrs="{'invisible': ['|', ('cfdi_state', 'not in', ['signed', 'done']), ('state', '=', 'cancel')]}"/>
-                <button name="replace_cfdi" type="object" string="Cancel"
+                    attrs="{'invisible': ['|', ('cfdi_state', 'not in', ['signed',
+                    'done']), ('state', '=', 'cancel')]}"/>-->
+                <button name="replace_cfdi" type="object" class="btn-primary" string="Cancel"
                     confirm="Are you sure to cancel this payment?"
                     attrs="{'invisible': ['|', ('cfdi_state', 'not in', ['signed',
                     'done']), ('state', '=', 'cancel')]}"/>-->
-- 
GitLab