diff --git a/l10n_mx_facturae/migrations/3.5.0/post-migration.py b/l10n_mx_facturae/migrations/3.5.0/post-migration.py index 444b5f4c66eb0e046d64d75f6c76b95b957e5dc2..6579f6e7229f7354d66a14cba71290d1a414ae86 100644 --- a/l10n_mx_facturae/migrations/3.5.0/post-migration.py +++ b/l10n_mx_facturae/migrations/3.5.0/post-migration.py @@ -7,48 +7,50 @@ from openerp import SUPERUSER_ID @tools.migrate(use_env=True, uid=SUPERUSER_ID) def migrate(env, installed_version): - tools.logged_query( - env.cr, - """ - WITH account_regimen_code as ( - SELECT - ai.id AS invoice_id, - fr.id AS fiscal_regime_id - FROM account_invoice as ai - LEFT JOIN account_fiscal_position as afp ON afp.id = ai.fiscal_position - LEFT JOIN cfdi_fiscal_regime AS fr ON afp.code = fr.code - WHERE afp.code in ( - '601','603','605','606','607','608','609','610','611','612','614', - '615','616','620','621','622','623','624','628','629','630' + legacy_name = tools.get_legacy_name("cfdi_fiscal_regime_id") + if tools.column_exists(env.cr, "account_invoice", legacy_name): + tools.logged_query( + env.cr, + """ + WITH account_regimen_code as ( + SELECT + ai.id AS invoice_id, + fr.id AS fiscal_regime_id + FROM account_invoice as ai + LEFT JOIN account_fiscal_position as afp ON afp.id = ai.fiscal_position + LEFT JOIN cfdi_fiscal_regime AS fr ON afp.code = fr.code + WHERE afp.code in ( + '601','603','605','606','607','608','609','610','611','612','614', + '615','616','620','621','622','623','624','628','629','630' + ) ) - ) - UPDATE account_invoice AS ai - SET cfdi_fiscal_regime_id=fr.fiscal_regime_id - FROM account_regimen_code AS fr - WHERE ai.id=fr.invoice_id - """, - ) + UPDATE account_invoice AS ai + SET cfdi_fiscal_regime_id=fr.fiscal_regime_id + FROM account_regimen_code AS fr + WHERE ai.id=fr.invoice_id + """, + ) - tools.logged_query( - env.cr, - """ - WITH account_regimen_code as ( - SELECT - ai.id AS invoice_id, - fr.id AS fiscal_regime_id - FROM account_invoice as ai - LEFT JOIN account_fiscal_position as afp ON afp.id = ai.fiscal_position - LEFT JOIN cfdi_fiscal_regime AS fr ON afp.code = fr.code - WHERE afp.code in ( - '601','603','605','606','607','608','609','610','611','612','614', - '615','616','620','621','622','623','624','628','629','630' + tools.logged_query( + env.cr, + """ + WITH account_regimen_code as ( + SELECT + ai.id AS invoice_id, + fr.id AS fiscal_regime_id + FROM account_invoice as ai + LEFT JOIN account_fiscal_position as afp ON afp.id = ai.fiscal_position + LEFT JOIN cfdi_fiscal_regime AS fr ON afp.code = fr.code + WHERE afp.code in ( + '601','603','605','606','607','608','609','610','611','612','614', + '615','616','620','621','622','623','624','628','629','630' + ) ) - ) - UPDATE account_invoice AS ai - SET fiscal_position=Null - FROM account_regimen_code AS fr - WHERE ai.id=fr.invoice_id - """, - ) + UPDATE account_invoice AS ai + SET fiscal_position=Null + FROM account_regimen_code AS fr + WHERE ai.id=fr.invoice_id + """, + ) diff --git a/l10n_mx_facturae/models/account_invoice.py b/l10n_mx_facturae/models/account_invoice.py index 294f08df6aaedeba15a29d3b9d09db892c182d08..57faf12cd2eda488cfd78fba38a6fbcc52b75d09 100644 --- a/l10n_mx_facturae/models/account_invoice.py +++ b/l10n_mx_facturae/models/account_invoice.py @@ -274,8 +274,6 @@ 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 @@ -402,7 +400,6 @@ class AccountInvoice(models.Model): [ "cfdi_use", "partner_id", - "cfdi_fiscal_regime_id", "payment_type_ids", "address_issued_id", "journal_id",