Skip to content

Commit

Permalink
[ADD] migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
corredato committed Sep 19, 2024
1 parent 34d3b42 commit 310b6fe
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions l10n_br_fiscal/migrations/14.0.23.3.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""
Script de migração para remover os campos das tabelas e
ajustar o relacionamento com as estimativas de imposto.
"""

openupgrade.logged_query(
env.cr,
"""
ALTER TABLE l10n_br_fiscal_ncm DROP COLUMN IF EXISTS estimate_tax_national;
ALTER TABLE l10n_br_fiscal_ncm DROP COLUMN IF EXISTS estimate_tax_imported;
ALTER TABLE l10n_br_fiscal_nbs DROP COLUMN IF EXISTS estimate_tax_national;
ALTER TABLE l10n_br_fiscal_nbs DROP COLUMN IF EXISTS estimate_tax_imported;
""",
)

openupgrade.logged_query(
env.cr,
"""
ALTER TABLE l10n_br_fiscal_tax_estimate DROP COLUMN IF EXISTS company_id;
""",
)

models_to_update = ["l10n_br_fiscal.ncm", "l10n_br_fiscal.nbs"]
for model_name in models_to_update:
records = env[model_name].search([])
for record in records:
last_estimated = record.tax_estimate_ids.sorted(
key="create_date", reverse=True
)[:1]
if last_estimated:
last_estimated.write({"active": True})
(record.tax_estimate_ids - last_estimated).write({"active": False})

0 comments on commit 310b6fe

Please sign in to comment.