Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] Big simplification, update and cleanup #198

Closed
6 changes: 1 addition & 5 deletions intrastat_product/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -55,10 +55,6 @@ def _compute_src_dest_country_id(self):
country = inv.company_id.country_id
inv.src_dest_country_id = country.id

@api.model
def _default_src_dest_region_id(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook was done for a reason, so it's not good to remove it.

return self.env.company.intrastat_region_id

def compute_intrastat_lines(self):
"""
Compute the Intrastat Lines so that they can be modified
Expand Down
27 changes: 9 additions & 18 deletions intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def default_get(self, fields_list):
)
state = fields.Selection(
selection=[("draft", "Draft"), ("done", "Done")],
string="State",
readonly=True,
tracking=True,
copy=False,
Expand All @@ -67,9 +66,7 @@ def default_get(self, fields_list):
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"),
Expand All @@ -85,7 +82,6 @@ def default_get(self, fields_list):
("11", "11"),
("12", "12"),
],
string="Month",
required=True,
states={"done": [("readonly", True)]},
)
Expand All @@ -106,14 +102,12 @@ def default_get(self, fields_list):
)
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",
Expand Down Expand Up @@ -149,7 +143,6 @@ def default_get(self, fields_list):
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")
Expand Down Expand Up @@ -322,12 +315,12 @@ def _get_intrastat_transaction(self, inv_line, notedict):
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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
)
Expand Down
22 changes: 6 additions & 16 deletions intrastat_product/models/intrastat_region.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
14 changes: 3 additions & 11 deletions intrastat_product/models/intrastat_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
6 changes: 3 additions & 3 deletions intrastat_product/models/intrastat_transport_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions intrastat_product/models/intrastat_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 16 additions & 8 deletions intrastat_product/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def _init_regions(cls):
}
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()
Expand All @@ -77,6 +86,7 @@ def setUpClass(cls):
cls._init_company()
cls._init_fiscal_position()
cls._init_products()
cls._init_transaction()

@classmethod
def _create_xls(cls, declaration=False):
Expand All @@ -99,16 +109,14 @@ def _create_xls(cls, declaration=False):
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):
Expand Down
4 changes: 3 additions & 1 deletion intrastat_product/tests/test_intrastat_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ def test_copy(self):
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(
Expand Down
2 changes: 1 addition & 1 deletion intrastat_product/views/hs_code.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 24 additions & 2 deletions intrastat_product/views/intrastat_region.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add sheet.

<group name="main">
<field name="code" />
<field name="name" />
Expand All @@ -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" />
Expand All @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions intrastat_product/views/intrastat_transaction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" />
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions intrastat_product/views/intrastat_transport_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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" />
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions intrastat_product/views/intrastat_unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" />
Expand All @@ -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)]"
Expand Down