diff --git a/l10n_mx_facturae/models/account_invoice.py b/l10n_mx_facturae/models/account_invoice.py index bdaad6984c7f5b920d7ee7711932a2d09aa375f7..dce5d0560af2ece90d3d44285f1a4b485b311a6e 100644 --- a/l10n_mx_facturae/models/account_invoice.py +++ b/l10n_mx_facturae/models/account_invoice.py @@ -17,6 +17,11 @@ class AccountInvoice(models.Model): _name = "account.invoice" _inherit = ["account.invoice", "base.cfdi"] + cfdi_fiscal_regime_id = fields.Many2one( + "cfdi.fiscal.regime", + states={"draft": [("readonly", False)]}, + ) + @property def formapago(self): """Return payment type for display on CFDI""" @@ -89,7 +94,7 @@ class AccountInvoice(models.Model): # Classify taxes for CFDI for dummy, tax in tax_grouped.items(): - if tax.group in ["IVA", "IEPS", "ISR"]: + if tax.group in ["IVA", "IEPS"]: if tax.amount >= 0: taxes["traslados"].append(tax) taxes["total_traslados"] += tax.amount @@ -274,6 +279,8 @@ class AccountInvoice(models.Model): for invoice in self.filtered(lambda i: i.type in ("out_invoice", "out_refund")): partner = invoice.partner_id if partner: + if partner.cfdi_fiscal_regime_id.id: + invoice.cfdi_fiscal_regime_id = partner.cfdi_fiscal_regime_id.id if partner.cfdi_use.id: invoice.cfdi_use = partner.cfdi_use.id invoice.payment_method_id = partner.payment_method_id.id @@ -322,7 +329,7 @@ class AccountInvoice(models.Model): lambda i: i.journal_id.sign_sat and i.cfdi_id - and i.cfdi_id.state not in ["draft", "cancel"] + and i.cfdi_id.state != "cancel" ) for invoice in cfdis: # Ensure we can cancel this invoice @@ -334,15 +341,14 @@ class AccountInvoice(models.Model): ) cancelacion = invoice.cancel_cfdi()[0] if cancelacion: - # CFDI cancelled (cancelacion == True) must cancel invoice too super(AccountInvoice, invoice).action_cancel() elif cancelacion is None: - # CFDI set to approval (cancelacion == None) must set invoice - # to waiting too - invoice.write({"state": "waiting"}) + if invoice.cfdi_id.state == "waiting": + invoice.write({"state": "waiting"}) + else: + super(AccountInvoice, invoice).action_cancel() + invoice.write({"state": "cancel"}) 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 @@ -360,30 +366,18 @@ class AccountInvoice(models.Model): def action_consult_cancellation_status(self): """Verify cancellation status""" # TODO: Is this really needed? Maybe we can reuse the action_cancel - for invoice in self: - try: - with self.env.cr.savepoint(): - status_cancelacion = invoice.consult_cfdi_cancellation_status() - if status_cancelacion is None: - invoice.message_post( - body=_("No status update found on SAT") - ) - elif status_cancelacion is False: - self.undo_waiting_state() - else: - try: - invoice.action_cancel() - except Exception as e: - invoice.message_post( - body=_("The invoice could not be canceled") - ) - except Exception as e: - invoice.message_post( - body=_( - "Could not check SAT invoice status " - "due to the following error: %s." - ) % (e) - ) + for account_invoice in self: + status_cancelacion = account_invoice.consult_cfdi_cancellation_status() + if status_cancelacion is None: + continue + elif status_cancelacion is False: + self.undo_waiting_state() + else: + try: + account_invoice.action_cancel() + except Exception as e: + _logger.info(e) + continue @api.multi def _validate_cfdi_data(self): @@ -400,7 +394,7 @@ class AccountInvoice(models.Model): [ "cfdi_use", "partner_id", - "fiscal_position", + "cfdi_fiscal_regime_id", "payment_type_ids", "address_issued_id", "journal_id", @@ -536,7 +530,7 @@ class AccountInvoiceLine(models.Model): self.ensure_one() taxes = {"traslados": [], "retenciones": [], "locales": []} for tax in self.export_invoice_line_for_xml().taxes: - if tax.group in ["IVA", "IEPS", "ISR"]: + if tax.group in ["IVA", "IEPS"]: if tax.amount >= 0: taxes["traslados"].append(tax) else: diff --git a/l10n_mx_facturae/models/account_voucher.py b/l10n_mx_facturae/models/account_voucher.py index 41beaa6f8954b8fdc1da06dc11593ae5f3b769e0..fe396e134e1145594f100f0ea6701b709b244f5a 100644 --- a/l10n_mx_facturae/models/account_voucher.py +++ b/l10n_mx_facturae/models/account_voucher.py @@ -375,7 +375,7 @@ class AccountVoucher(models.Model): required = [ "vat", "name", - "property_account_position" + "cfdi_fiscal_regime_id" ] for record in self: diff --git a/l10n_mx_facturae/report/account_invoice.odt b/l10n_mx_facturae/report/account_invoice.odt index 3efe308cf518b595be70a73921ca909af467c243..ec71d2033dffc14e430a46911877896b5467ca97 100644 Binary files a/l10n_mx_facturae/report/account_invoice.odt and b/l10n_mx_facturae/report/account_invoice.odt differ diff --git a/l10n_mx_facturae/report/account_voucher.odt b/l10n_mx_facturae/report/account_voucher.odt index c04f5282bc64fd5f71a14153b71dfc2638f182fc..798bbb24e8d3ac4c37554d6dfa515ff1fac80107 100644 Binary files a/l10n_mx_facturae/report/account_voucher.odt and b/l10n_mx_facturae/report/account_voucher.odt differ diff --git a/l10n_mx_facturae/templates/account_invoice.txt b/l10n_mx_facturae/templates/account_invoice.txt index 990b91c371369ddb12a8f244fe4ae65460a34f6c..900442c2af5aa848d36c30a47eef3af544c4b39b 100644 --- a/l10n_mx_facturae/templates/account_invoice.txt +++ b/l10n_mx_facturae/templates/account_invoice.txt @@ -69,7 +69,7 @@ <cfdi:Emisor Rfc="${ html_escape(o.company_id.partner_id.vat_split) }" Nombre="${ html_escape(o.company_id.partner_id.name.upper()) }" - RegimenFiscal="${ o.company_id.partner_id.property_account_position.code }"/> + RegimenFiscal="${ o.company_id.partner_id.cfdi_fiscal_regime_id.code }"/> <cfdi:Receptor Nombre="${ html_escape(o.commercial_partner_id.name.upper()) }" {% choose o.commercial_partner_id.country_id and o.commercial_partner_id.country_id.code_alpha3 %} @@ -85,7 +85,7 @@ DomicilioFiscalReceptor="${ o.commercial_partner_id.zip }" {% end %} {% end %} - RegimenFiscalReceptor="${ o.commercial_partner_id.property_account_position.code }" + RegimenFiscalReceptor="${ o.commercial_partner_id.cfdi_fiscal_regime_id.code }" {% end %} {% otherwise %} Rfc="XEXX010101000" diff --git a/l10n_mx_facturae/templates/account_voucher.txt b/l10n_mx_facturae/templates/account_voucher.txt index ccb3744a894ef306510ae9fa957a642db5e437ba..2a30569ab86b540dba6a2af4dc8e0b8dc515a631 100644 --- a/l10n_mx_facturae/templates/account_voucher.txt +++ b/l10n_mx_facturae/templates/account_voucher.txt @@ -34,7 +34,7 @@ {% end %} <cfdi:Emisor Nombre="${ html_escape(o.company_id.name.upper()) }" - RegimenFiscal="$o.company_id.partner_id.property_account_position.code" + RegimenFiscal="$o.company_id.partner_id.cfdi_fiscal_regime_id.code" Rfc="${ html_escape(o.company_id.partner_id.vat_split) }" /> <cfdi:Receptor Nombre="${ html_escape(o.partner_id.name.upper()) }" @@ -54,7 +54,7 @@ DomicilioFiscalReceptor="${ o.partner_id.zip }" {% end %} {% end %} - RegimenFiscalReceptor="${ o.partner_id.property_account_position.code }" + RegimenFiscalReceptor="${ o.partner_id.cfdi_fiscal_regime_id.code }" {% end %} {% otherwise %} Rfc="XEXX010101000" diff --git a/l10n_mx_facturae/views/account_invoice.xml b/l10n_mx_facturae/views/account_invoice.xml index d686cc7da20c257a57771d79f9caf4eca8232e24..57c81295ae6db4a1c6a5a8550a6d7ce5bb8ffac8 100644 --- a/l10n_mx_facturae/views/account_invoice.xml +++ b/l10n_mx_facturae/views/account_invoice.xml @@ -120,6 +120,11 @@ </div> </xpath> <field name="fiscal_position" position="after"> + <field name="cfdi_fiscal_regime_id" + attrs="{ + 'readonly': [('cfdi_state','in', ['signed', 'cancel', 'done'])], + 'invisible': [('is_cfdi_candidate', '=', False)] + }" /> <field name="cfdi_use" attrs="{ 'readonly': [('cfdi_state','in', ['signed', 'cancel', 'done'])],