[FIX] Migration fixes + full migration scripts

This commit is contained in:
mreficent
2020-12-11 15:09:32 +01:00
committed by João Marques
parent 5a4296a386
commit bcb71216c0
5 changed files with 77 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
{
"name": "Intrastat Product",
"version": "13.0.1.1.0",
"version": "13.0.1.1.1",
"category": "Intrastat",
"license": "AGPL-3",
"summary": "Base module for Intrastat Product",

View File

@@ -2,9 +2,61 @@
from openupgradelib import openupgrade # pylint: disable=W7936
_months = [
(1, "01"),
(2, "02"),
(3, "03"),
(4, "04"),
(5, "05"),
(6, "06"),
(7, "07"),
(8, "08"),
(9, "09"),
(10, "10"),
(11, "11"),
(12, "12"),
]
def map_intrastat_product_declaration_month(env):
openupgrade.map_values(
env.cr,
openupgrade.get_legacy_name("month"),
"month",
_months,
table="intrastat_product_declaration",
)
def update_invoice_relation_fields(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET (intrastat_transaction_id, intrastat_transport_id,
src_dest_country_id, intrastat_country, src_dest_region_id
) = (ai.intrastat_transaction_id,
ai.intrastat_transport_id, ai.src_dest_country_id,
ai.intrastat_country, ai.src_dest_region_id)
FROM account_invoice ai
WHERE am.old_invoice_id = ai.id""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE intrastat_product_computation_line ipcl
SET invoice_line_id = aml.id
FROM account_invoice_line ail
JOIN account_move_line aml ON aml.old_invoice_line_id = ail.id
WHERE ipcl.%(old_line_id)s = ail.id"""
% {"old_line_id": openupgrade.get_legacy_name("invoice_line_id")},
)
@openupgrade.migrate()
def migrate(env, version):
map_intrastat_product_declaration_month(env)
update_invoice_relation_fields(env)
openupgrade.load_data(
env.cr, "intrastat_product", "migrations/13.0.1.0.3/noupdate_changes.xml"
)

View File

@@ -0,0 +1,13 @@
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
_column_renames = {
"intrastat_product_declaration": [("month", None)],
"intrastat_product_computation_line": [("invoice_line_id", None)],
}
@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_columns(env.cr, _column_renames)

View File

@@ -13,7 +13,7 @@ class AccountMove(models.Model):
comodel_name="intrastat.transaction",
string="Intrastat Transaction Type",
ondelete="restrict",
track_visibility="onchange",
tracking=True,
help="Intrastat nature of transaction",
)
intrastat_transport_id = fields.Many2one(

View File

@@ -83,7 +83,7 @@ class IntrastatProductDeclaration(models.Model):
compute="_compute_year_month",
string="Period",
readonly=True,
track_visibility="onchange",
tracking=True,
store=True,
help="Year and month of the declaration.",
)
@@ -92,7 +92,7 @@ class IntrastatProductDeclaration(models.Model):
string="Type",
required=True,
states={"done": [("readonly", True)]},
track_visibility="onchange",
tracking=True,
help="Select the declaration type.",
)
action = fields.Selection(
@@ -101,7 +101,7 @@ class IntrastatProductDeclaration(models.Model):
required=True,
default="replace",
states={"done": [("readonly", True)]},
track_visibility="onchange",
tracking=True,
)
revision = fields.Integer(
string="Revision",
@@ -125,7 +125,7 @@ class IntrastatProductDeclaration(models.Model):
compute="_compute_numbers",
string="Number of Declaration Lines",
store=True,
track_visibility="onchange",
tracking=True,
)
total_amount = fields.Integer(
compute="_compute_numbers",
@@ -140,7 +140,7 @@ class IntrastatProductDeclaration(models.Model):
selection=[("draft", "Draft"), ("done", "Done")],
string="State",
readonly=True,
track_visibility="onchange",
tracking=True,
copy=False,
default="draft",
help="State of the declaration. When the state is set to 'Done', "
@@ -350,7 +350,7 @@ class IntrastatProductDeclaration(models.Model):
inv_line.price_subtotal,
self.company_id.currency_id,
self.company_id,
invoice.date,
invoice.invoice_date,
)
return amount
@@ -477,11 +477,12 @@ class IntrastatProductDeclaration(models.Model):
start_date = date(int(self.year), int(self.month), 1)
end_date = start_date + relativedelta(day=1, months=+1, days=-1)
domain = [
("date", ">=", start_date),
("date", "<=", end_date),
("invoice_date", ">=", start_date),
("invoice_date", "<=", end_date),
("state", "=", "posted"),
("intrastat_country", "=", True),
("company_id", "=", self.company_id.id),
("type", "!=", "entry"),
]
return domain
@@ -538,7 +539,7 @@ class IntrastatProductDeclaration(models.Model):
inv_line.price_subtotal,
self.company_id.currency_id,
self.company_id,
invoice.date_invoice,
invoice.invoice_date,
)
total_inv_accessory_costs_cc += acost