mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
intrastat_product: Backport updates from v15
Make tests work
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <em>Intrastat Transaction Type</em> on invoice. "
|
||||
"No Default Intrastat Transaction Type on "
|
||||
"the fiscal position of the invoice (%s), "
|
||||
"nor on the accounting configuration page of the company <i>%s</i>."
|
||||
) % (
|
||||
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 <i>%(company)s</i>."
|
||||
) % {
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright 2009-2020 Noviat nv/sa (www.noviat.com).
|
||||
# @author Luc de Meyer <info@noviat.com>
|
||||
|
||||
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)
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<field name="inherit_id" ref="product_harmonized_system.hs_code_view_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="local_code" position="after">
|
||||
<field name="intrastat_unit_id" />
|
||||
<field name="intrastat_unit_id" optional="show" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<field name="name">intrastat.region.form</field>
|
||||
<field name="model">intrastat.region</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Intrastat Region">
|
||||
<form>
|
||||
<group name="main">
|
||||
<field name="code" />
|
||||
<field name="name" />
|
||||
@@ -19,7 +19,7 @@
|
||||
<field name="name">intrastat.region.tree</field>
|
||||
<field name="model">intrastat.region</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Intrastat Region">
|
||||
<tree>
|
||||
<field name="code" />
|
||||
<field name="name" />
|
||||
<field name="description" optional="show" />
|
||||
@@ -28,6 +28,28 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="intrastat_region_view_search" model="ir.ui.view">
|
||||
<field name="name">intrastat.region.search</field>
|
||||
<field name="model">intrastat.region</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field
|
||||
name="name"
|
||||
string="Name, Code or Description"
|
||||
filter_domain="['|', '|', ('code', 'ilike', self), ('name', 'ilike', self), ('description', 'ilike', self)]"
|
||||
/>
|
||||
<field name="code" />
|
||||
<field name="country_id" />
|
||||
<group name="groupby">
|
||||
<filter
|
||||
name="country_groupby"
|
||||
string="Country"
|
||||
context="{'group_by': 'country_id'}"
|
||||
/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
<record id="intrastat_region_action" model="ir.actions.act_window">
|
||||
<field name="name">Intrastat Regions</field>
|
||||
<field name="res_model">intrastat.region</field>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="name">intrastat.transaction_form</field>
|
||||
<field name="model">intrastat.transaction</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Intrastat Transaction Type">
|
||||
<form>
|
||||
<sheet>
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
@@ -34,7 +34,7 @@
|
||||
<field name="name">intrastat.transaction_tree</field>
|
||||
<field name="model">intrastat.transaction</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Intrastat Transaction Types">
|
||||
<tree>
|
||||
<field name="code" />
|
||||
<field name="description" />
|
||||
<field name="company_id" groups="base.group_multi_company" />
|
||||
@@ -45,7 +45,7 @@
|
||||
<field name="name">intrastat.transaction.mode.search</field>
|
||||
<field name="model">intrastat.transaction</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Intrastat Transaction Types">
|
||||
<search>
|
||||
<field
|
||||
name="description"
|
||||
string="Code or Description"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="name">intrastat.transport.mode.form</field>
|
||||
<field name="model">intrastat.transport_mode</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Intrastat Transport Mode">
|
||||
<form>
|
||||
<group>
|
||||
<field name="name" />
|
||||
<field name="code" />
|
||||
@@ -25,7 +25,7 @@
|
||||
<field name="name">intrastat.transport.mode.tree</field>
|
||||
<field name="model">intrastat.transport_mode</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Intrastat Transportat Modes">
|
||||
<tree>
|
||||
<field name="code" />
|
||||
<field name="name" />
|
||||
<field name="description" optional="show" />
|
||||
@@ -36,7 +36,7 @@
|
||||
<field name="name">intrastat.transport.mode.search</field>
|
||||
<field name="model">intrastat.transport_mode</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Intrastat Transport Modes">
|
||||
<search>
|
||||
<field
|
||||
name="name"
|
||||
string="Name, Code or Description"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="name">intrastat.unit.form</field>
|
||||
<field name="model">intrastat.unit</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Intrastat Supplementary Unit">
|
||||
<form>
|
||||
<field name="active" invisible="1" />
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
@@ -32,7 +32,7 @@
|
||||
<field name="name">intrastat.unit.tree</field>
|
||||
<field name="model">intrastat.unit</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Intrastat Supplementary Units">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
<field name="uom_id" />
|
||||
<field name="description" optional="show" />
|
||||
@@ -43,7 +43,7 @@
|
||||
<field name="name">intrastat.unit.search</field>
|
||||
<field name="model">intrastat.unit</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Intrastat Supplementary Units">
|
||||
<search>
|
||||
<field
|
||||
name="name"
|
||||
filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"
|
||||
|
||||
Reference in New Issue
Block a user