diff --git a/intrastat_product/__manifest__.py b/intrastat_product/__manifest__.py index 5bafc9e..f47596b 100644 --- a/intrastat_product/__manifest__.py +++ b/intrastat_product/__manifest__.py @@ -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", diff --git a/intrastat_product/migrations/13.0.1.0.3/post-migration.py b/intrastat_product/migrations/13.0.1.0.3/post-migration.py index 9264a91..b9347a7 100644 --- a/intrastat_product/migrations/13.0.1.0.3/post-migration.py +++ b/intrastat_product/migrations/13.0.1.0.3/post-migration.py @@ -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" ) diff --git a/intrastat_product/migrations/13.0.1.0.3/pre-migration.py b/intrastat_product/migrations/13.0.1.0.3/pre-migration.py new file mode 100644 index 0000000..4f0b78e --- /dev/null +++ b/intrastat_product/migrations/13.0.1.0.3/pre-migration.py @@ -0,0 +1,13 @@ +# Copyright 2020 ForgeFlow +# 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) diff --git a/intrastat_product/models/account_move.py b/intrastat_product/models/account_move.py index cca4c99..14bf855 100644 --- a/intrastat_product/models/account_move.py +++ b/intrastat_product/models/account_move.py @@ -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( diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index bab8276..b33bc4a 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -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