mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
[FIX] Migration fixes + full migration scripts
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Intrastat Product",
|
"name": "Intrastat Product",
|
||||||
"version": "13.0.1.1.0",
|
"version": "13.0.1.1.1",
|
||||||
"category": "Intrastat",
|
"category": "Intrastat",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"summary": "Base module for Intrastat Product",
|
"summary": "Base module for Intrastat Product",
|
||||||
|
|||||||
@@ -2,9 +2,61 @@
|
|||||||
|
|
||||||
from openupgradelib import openupgrade # pylint: disable=W7936
|
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()
|
@openupgrade.migrate()
|
||||||
def migrate(env, version):
|
def migrate(env, version):
|
||||||
|
map_intrastat_product_declaration_month(env)
|
||||||
|
update_invoice_relation_fields(env)
|
||||||
openupgrade.load_data(
|
openupgrade.load_data(
|
||||||
env.cr, "intrastat_product", "migrations/13.0.1.0.3/noupdate_changes.xml"
|
env.cr, "intrastat_product", "migrations/13.0.1.0.3/noupdate_changes.xml"
|
||||||
)
|
)
|
||||||
|
|||||||
13
intrastat_product/migrations/13.0.1.0.3/pre-migration.py
Normal file
13
intrastat_product/migrations/13.0.1.0.3/pre-migration.py
Normal 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)
|
||||||
@@ -13,7 +13,7 @@ class AccountMove(models.Model):
|
|||||||
comodel_name="intrastat.transaction",
|
comodel_name="intrastat.transaction",
|
||||||
string="Intrastat Transaction Type",
|
string="Intrastat Transaction Type",
|
||||||
ondelete="restrict",
|
ondelete="restrict",
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
help="Intrastat nature of transaction",
|
help="Intrastat nature of transaction",
|
||||||
)
|
)
|
||||||
intrastat_transport_id = fields.Many2one(
|
intrastat_transport_id = fields.Many2one(
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
compute="_compute_year_month",
|
compute="_compute_year_month",
|
||||||
string="Period",
|
string="Period",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
store=True,
|
store=True,
|
||||||
help="Year and month of the declaration.",
|
help="Year and month of the declaration.",
|
||||||
)
|
)
|
||||||
@@ -92,7 +92,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
string="Type",
|
string="Type",
|
||||||
required=True,
|
required=True,
|
||||||
states={"done": [("readonly", True)]},
|
states={"done": [("readonly", True)]},
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
help="Select the declaration type.",
|
help="Select the declaration type.",
|
||||||
)
|
)
|
||||||
action = fields.Selection(
|
action = fields.Selection(
|
||||||
@@ -101,7 +101,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
required=True,
|
required=True,
|
||||||
default="replace",
|
default="replace",
|
||||||
states={"done": [("readonly", True)]},
|
states={"done": [("readonly", True)]},
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
)
|
)
|
||||||
revision = fields.Integer(
|
revision = fields.Integer(
|
||||||
string="Revision",
|
string="Revision",
|
||||||
@@ -125,7 +125,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
compute="_compute_numbers",
|
compute="_compute_numbers",
|
||||||
string="Number of Declaration Lines",
|
string="Number of Declaration Lines",
|
||||||
store=True,
|
store=True,
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
)
|
)
|
||||||
total_amount = fields.Integer(
|
total_amount = fields.Integer(
|
||||||
compute="_compute_numbers",
|
compute="_compute_numbers",
|
||||||
@@ -140,7 +140,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
selection=[("draft", "Draft"), ("done", "Done")],
|
selection=[("draft", "Draft"), ("done", "Done")],
|
||||||
string="State",
|
string="State",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
track_visibility="onchange",
|
tracking=True,
|
||||||
copy=False,
|
copy=False,
|
||||||
default="draft",
|
default="draft",
|
||||||
help="State of the declaration. When the state is set to 'Done', "
|
help="State of the declaration. When the state is set to 'Done', "
|
||||||
@@ -350,7 +350,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
inv_line.price_subtotal,
|
inv_line.price_subtotal,
|
||||||
self.company_id.currency_id,
|
self.company_id.currency_id,
|
||||||
self.company_id,
|
self.company_id,
|
||||||
invoice.date,
|
invoice.invoice_date,
|
||||||
)
|
)
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
@@ -477,11 +477,12 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
start_date = date(int(self.year), int(self.month), 1)
|
start_date = date(int(self.year), int(self.month), 1)
|
||||||
end_date = start_date + relativedelta(day=1, months=+1, days=-1)
|
end_date = start_date + relativedelta(day=1, months=+1, days=-1)
|
||||||
domain = [
|
domain = [
|
||||||
("date", ">=", start_date),
|
("invoice_date", ">=", start_date),
|
||||||
("date", "<=", end_date),
|
("invoice_date", "<=", end_date),
|
||||||
("state", "=", "posted"),
|
("state", "=", "posted"),
|
||||||
("intrastat_country", "=", True),
|
("intrastat_country", "=", True),
|
||||||
("company_id", "=", self.company_id.id),
|
("company_id", "=", self.company_id.id),
|
||||||
|
("type", "!=", "entry"),
|
||||||
]
|
]
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
@@ -538,7 +539,7 @@ class IntrastatProductDeclaration(models.Model):
|
|||||||
inv_line.price_subtotal,
|
inv_line.price_subtotal,
|
||||||
self.company_id.currency_id,
|
self.company_id.currency_id,
|
||||||
self.company_id,
|
self.company_id,
|
||||||
invoice.date_invoice,
|
invoice.invoice_date,
|
||||||
)
|
)
|
||||||
total_inv_accessory_costs_cc += acost
|
total_inv_accessory_costs_cc += acost
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user