From f15ec4ed444cd99dd426781d85d542e4dc8190e5 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 24 Jan 2023 16:22:44 +0100 Subject: [PATCH] intrastat_product: Backport updates from v15 Make tests work --- intrastat_product/models/account_move.py | 6 +---- .../models/intrastat_product_declaration.py | 27 +++++++------------ intrastat_product/models/intrastat_region.py | 22 +++++---------- .../models/intrastat_transaction.py | 14 +++------- .../models/intrastat_transport_mode.py | 6 ++--- intrastat_product/models/intrastat_unit.py | 4 +-- intrastat_product/tests/common.py | 24 +++++++++++------ .../tests/test_intrastat_product.py | 4 ++- intrastat_product/views/hs_code.xml | 2 +- intrastat_product/views/intrastat_region.xml | 26 ++++++++++++++++-- .../views/intrastat_transaction.xml | 6 ++--- .../views/intrastat_transport_mode.xml | 6 ++--- intrastat_product/views/intrastat_unit.xml | 6 ++--- 13 files changed, 77 insertions(+), 76 deletions(-) diff --git a/intrastat_product/models/account_move.py b/intrastat_product/models/account_move.py index 2dbad13..ab8b9bb 100644 --- a/intrastat_product/models/account_move.py +++ b/intrastat_product/models/account_move.py @@ -33,7 +33,7 @@ class AccountMove(models.Model): src_dest_region_id = fields.Many2one( comodel_name="intrastat.region", string="Origin/Destination Region", - default=lambda self: self._default_src_dest_region_id(), + default=lambda self: self.env.company.intrastat_region_id, help="Origin region for dispatches, destination region for " "arrivals. This field is used for the Intrastat Declaration.", ondelete="restrict", @@ -55,10 +55,6 @@ class AccountMove(models.Model): country = inv.company_id.country_id inv.src_dest_country_id = country.id - @api.model - def _default_src_dest_region_id(self): - return self.env.company.intrastat_region_id - def compute_intrastat_lines(self): """ Compute the Intrastat Lines so that they can be modified diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index b312e94..f482a7a 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -56,7 +56,6 @@ class IntrastatProductDeclaration(models.Model): ) state = fields.Selection( selection=[("draft", "Draft"), ("done", "Done")], - string="State", readonly=True, tracking=True, copy=False, @@ -67,9 +66,7 @@ class IntrastatProductDeclaration(models.Model): note = fields.Text( string="Notes", help="You can add some comments here if you want." ) - year = fields.Char( - string="Year", required=True, states={"done": [("readonly", True)]} - ) + year = fields.Char(required=True, states={"done": [("readonly", True)]}) month = fields.Selection( selection=[ ("01", "01"), @@ -85,7 +82,6 @@ class IntrastatProductDeclaration(models.Model): ("11", "11"), ("12", "12"), ], - string="Month", required=True, states={"done": [("readonly", True)]}, ) @@ -106,14 +102,12 @@ class IntrastatProductDeclaration(models.Model): ) action = fields.Selection( selection="_get_action", - string="Action", required=True, default="replace", states={"done": [("readonly", True)]}, tracking=True, ) revision = fields.Integer( - string="Revision", default=1, states={"done": [("readonly", True)]}, help="Used to keep track of changes", @@ -149,7 +143,6 @@ class IntrastatProductDeclaration(models.Model): selection="_get_reporting_level", compute="_compute_reporting_level", readonly=False, - string="Reporting Level", states={"done": [("readonly", True)]}, ) xml_attachment_id = fields.Many2one("ir.attachment", string="XML Attachment") @@ -322,12 +315,12 @@ class IntrastatProductDeclaration(models.Model): msg = _( "No Intrastat Transaction Type on invoice. " "No Default Intrastat Transaction Type on " - "the fiscal position of the invoice (%s), " - "nor on the accounting configuration page of the company %s." - ) % ( - invoice.fiscal_position_id.display_name, - invoice.company_id.display_name, - ) + "the fiscal position of the invoice (%(fiscal_position)s), " + "nor on the accounting configuration page of the company %(company)s." + ) % { + "fiscal_position": invoice.fiscal_position_id.display_name, + "company": invoice.company_id.display_name, + } notedict["invoice"][notedict["inv_origin"]].add(msg) return transaction @@ -1081,9 +1074,7 @@ class IntrastatProductComputationLine(models.Model): string="Suppl. Unit", help="Intrastat Supplementary Unit", ) - weight = fields.Float( - string="Weight", digits="Stock Weight", help="Net weight in Kg" - ) + weight = fields.Float(digits="Stock Weight", help="Net weight in Kg") suppl_unit_qty = fields.Float( string="Suppl. Unit Qty", digits="Product Unit of Measure", @@ -1204,7 +1195,7 @@ class IntrastatProductDeclarationLine(models.Model): string="Suppl. Unit", help="Intrastat Supplementary Unit", ) - weight = fields.Integer(string="Weight", help="Net weight in Kg") + weight = fields.Integer(help="Net weight in Kg") suppl_unit_qty = fields.Integer( string="Suppl. Unit Qty", help="Supplementary Units Quantity" ) diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py index 648db55..14b5105 100644 --- a/intrastat_product/models/intrastat_region.py +++ b/intrastat_product/models/intrastat_region.py @@ -1,7 +1,7 @@ # Copyright 2009-2020 Noviat nv/sa (www.noviat.com). # @author Luc de Meyer -from odoo import api, fields, models +from odoo import fields, models class IntrastatRegion(models.Model): @@ -15,18 +15,8 @@ class IntrastatRegion(models.Model): ) ] - code = fields.Char(string="Code", required=True) - country_id = fields.Many2one( - comodel_name="res.country", string="Country", required=True - ) - name = fields.Char(string="Name", translate=True) - description = fields.Char(string="Description") - company_id = fields.Many2one( - comodel_name="res.company", - string="Company", - default=lambda self: self._default_company_id(), - ) - - @api.model - def _default_company_id(self): - return self.env.company + code = fields.Char(required=True) + country_id = fields.Many2one(comodel_name="res.country", required=True) + name = fields.Char(translate=True) + description = fields.Char() + company_id = fields.Many2one("res.company", default=lambda self: self.env.company) diff --git a/intrastat_product/models/intrastat_transaction.py b/intrastat_product/models/intrastat_transaction.py index 6b75f96..1d8b291 100644 --- a/intrastat_product/models/intrastat_transaction.py +++ b/intrastat_product/models/intrastat_transaction.py @@ -19,19 +19,11 @@ class IntrastatTransaction(models.Model): ) ] - code = fields.Char(string="Code", required=True) - description = fields.Text(string="Description") - company_id = fields.Many2one( - comodel_name="res.company", - string="Company", - default=lambda self: self._default_company_id(), - ) + code = fields.Char(required=True) + description = fields.Text() + company_id = fields.Many2one("res.company", default=lambda self: self.env.company) active = fields.Boolean(default=True) - @api.model - def _default_company_id(self): - return self.env.company - @api.depends("code", "description") def name_get(self): res = [] diff --git a/intrastat_product/models/intrastat_transport_mode.py b/intrastat_product/models/intrastat_transport_mode.py index 1d816b9..7f688b1 100644 --- a/intrastat_product/models/intrastat_transport_mode.py +++ b/intrastat_product/models/intrastat_transport_mode.py @@ -14,9 +14,9 @@ class IntrastatTransportMode(models.Model): ("intrastat_transport_code_unique", "UNIQUE(code)", "Code must be unique.") ] - code = fields.Char(string="Code", required=True) - name = fields.Char(string="Name", required=True, translate=True) - description = fields.Char(string="Description", translate=True) + code = fields.Char(required=True) + name = fields.Char(required=True, translate=True) + description = fields.Char(translate=True) @api.depends("name", "code") def name_get(self): diff --git a/intrastat_product/models/intrastat_unit.py b/intrastat_product/models/intrastat_unit.py index c83fa5e..eb5706c 100644 --- a/intrastat_product/models/intrastat_unit.py +++ b/intrastat_product/models/intrastat_unit.py @@ -10,8 +10,8 @@ class IntrastatUnit(models.Model): _name = "intrastat.unit" _description = "Intrastat Supplementary Units" - name = fields.Char(string="Name", required=True) - description = fields.Char(string="Description", required=True) + name = fields.Char(required=True) + description = fields.Char(required=True) uom_id = fields.Many2one( comodel_name="uom.uom", string="Regular UoM", diff --git a/intrastat_product/tests/common.py b/intrastat_product/tests/common.py index 17518d5..45e21fb 100644 --- a/intrastat_product/tests/common.py +++ b/intrastat_product/tests/common.py @@ -52,6 +52,15 @@ class IntrastatProductCommon(IntrastatCommon): } cls._create_region(vals) + @classmethod + def _init_transaction(cls): + vals = { + "code": "9X", + "company_id": cls.env.company.id, + "description": "Test 9X", + } + cls._create_transaction(vals) + @classmethod def setUpClass(cls): super().setUpClass() @@ -77,6 +86,7 @@ class IntrastatProductCommon(IntrastatCommon): cls._init_company() cls._init_fiscal_position() cls._init_products() + cls._init_transaction() @classmethod def _create_xls(cls, declaration=False): @@ -99,16 +109,14 @@ class IntrastatProductCommon(IntrastatCommon): data = {} encoded_data = "report/report_xlsx/" + report_name + "?" + url_encode(data) datas["data"] = encoded_data - context = { - "active_model": cls.declaration._name, - } + active_model = cls.declaration._name if not declaration: - context.update({"computation_lines": True}) + computation_lines = True else: - context.update({"declaration_lines": True}) - file_data = cls.xls_declaration.with_context(context).create_xlsx_report( - None, datas - ) + computation_lines = False + file_data = cls.xls_declaration.with_context( + computation_lines=computation_lines, active_model=active_model + ).create_xlsx_report(None, datas) return file_data def check_xls(self, xls, declaration=False): diff --git a/intrastat_product/tests/test_intrastat_product.py b/intrastat_product/tests/test_intrastat_product.py index a8b4e22..afeea08 100644 --- a/intrastat_product/tests/test_intrastat_product.py +++ b/intrastat_product/tests/test_intrastat_product.py @@ -72,12 +72,14 @@ class TestIntrastatProduct(IntrastatProductCommon): def test_declaration_manual_lines(self): vals = {"declaration_type": "dispatches"} self._create_declaration(vals) + self.declaration.write({"reporting_level": "standard"}) computation_line_form = Form( self.env["intrastat.product.computation.line"].with_context( default_parent_id=self.declaration.id ) ) - computation_line_form.src_dest_country_code = "FR" + computation_line_form.src_dest_country_id = self.env.ref("base.fr") + computation_line_form.transaction_id = self.transaction computation_line = computation_line_form.save() self.assertEqual(computation_line.src_dest_country_code, "FR") declaration_line_form = Form( diff --git a/intrastat_product/views/hs_code.xml b/intrastat_product/views/hs_code.xml index c72c324..9a80dbe 100644 --- a/intrastat_product/views/hs_code.xml +++ b/intrastat_product/views/hs_code.xml @@ -21,7 +21,7 @@ - + diff --git a/intrastat_product/views/intrastat_region.xml b/intrastat_product/views/intrastat_region.xml index 6f77b18..2b1d6de 100644 --- a/intrastat_product/views/intrastat_region.xml +++ b/intrastat_product/views/intrastat_region.xml @@ -4,7 +4,7 @@ intrastat.region.form intrastat.region -
+ @@ -19,7 +19,7 @@ intrastat.region.tree intrastat.region - + @@ -28,6 +28,28 @@ + + intrastat.region.search + intrastat.region + + + + + + + + + + + Intrastat Regions intrastat.region diff --git a/intrastat_product/views/intrastat_transaction.xml b/intrastat_product/views/intrastat_transaction.xml index 2c5468b..fc06983 100644 --- a/intrastat_product/views/intrastat_transaction.xml +++ b/intrastat_product/views/intrastat_transaction.xml @@ -12,7 +12,7 @@ intrastat.transaction_form intrastat.transaction - + intrastat.transaction_tree intrastat.transaction - + @@ -45,7 +45,7 @@ intrastat.transaction.mode.search intrastat.transaction - + intrastat.transport.mode.form intrastat.transport_mode - + @@ -25,7 +25,7 @@ intrastat.transport.mode.tree intrastat.transport_mode - + @@ -36,7 +36,7 @@ intrastat.transport.mode.search intrastat.transport_mode - + intrastat.unit.form intrastat.unit - + intrastat.unit.tree intrastat.unit - + @@ -43,7 +43,7 @@ intrastat.unit.search intrastat.unit - +