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

[16.0] intrastat_product: add confirmed state + several small fixes/improvements #260

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def default_get(self, fields_list):
comodel_name="res.company",
string="Company",
required=True,
states={"done": [("readonly", True)]},
readonly=True,
states={"draft": [("readonly", False)]},
default=lambda self: self.env.company,
)
company_country_code = fields.Char(
Expand All @@ -55,18 +56,20 @@ def default_get(self, fields_list):
store=True,
)
state = fields.Selection(
selection=[("draft", "Draft"), ("done", "Done")],
selection=[("draft", "Draft"), ("confirmed", "Confirmed"), ("done", "Done")],
readonly=True,
tracking=True,
copy=False,
default="draft",
help="State of the declaration. When the state is set to 'Done', "
"the parameters become read-only.",
)
note = fields.Text(
string="Notes", help="You can add some comments here if you want."
note = fields.Html(
string="Notes",
)
year = fields.Char(
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
)
year = fields.Char(required=True, states={"done": [("readonly", True)]})
month = fields.Selection(
selection=[
("01", "01"),
Expand All @@ -83,7 +86,8 @@ def default_get(self, fields_list):
("12", "12"),
],
required=True,
states={"done": [("readonly", True)]},
readonly=True,
states={"draft": [("readonly", False)]},
)
year_month = fields.Char(
compute="_compute_year_month",
Expand All @@ -96,8 +100,9 @@ def default_get(self, fields_list):
selection="_get_declaration_type",
string="Type",
required=True,
states={"done": [("readonly", True)]},
tracking=True,
readonly=True,
states={"draft": [("readonly", False)]},
)
action = fields.Selection(
selection="_get_action",
Expand All @@ -115,7 +120,8 @@ def default_get(self, fields_list):
comodel_name="intrastat.product.computation.line",
inverse_name="parent_id",
string="Intrastat Product Computation Lines",
states={"done": [("readonly", True)]},
readonly=True,
states={"draft": [("readonly", False)]},
)
declaration_line_ids = fields.One2many(
comodel_name="intrastat.product.declaration.line",
Expand All @@ -141,8 +147,9 @@ def default_get(self, fields_list):
reporting_level = fields.Selection(
selection="_get_reporting_level",
compute="_compute_reporting_level",
readonly=False,
states={"done": [("readonly", True)]},
readonly=True,
store=True,
states={"draft": [("readonly", False)]},
)
xml_attachment_id = fields.Many2one("ir.attachment", string="XML Attachment")
xml_attachment_datas = fields.Binary(
Expand Down Expand Up @@ -233,6 +240,7 @@ def _compute_reporting_level(self):
)
this.reporting_level = reporting_level

@api.depends("declaration_type", "year_month")
def name_get(self):
res = []
type2label = dict(
Expand All @@ -241,7 +249,11 @@ def name_get(self):
]
)
for rec in self:
name = "%s %s" % (rec.year_month, type2label.get(rec.declaration_type))
name = _(
"Intrastat Product Declaration %(declaration_type)s %(year_month)s",
year_month=rec.year_month,
declaration_type=type2label.get(rec.declaration_type),
)
res.append((rec.id, name))
return res

Expand Down Expand Up @@ -839,10 +851,16 @@ def generate_declaration(self):
else:
dl_group[hashcode] |= cl
ipdl = self.declaration_line_ids
line_number = 1
for cl_lines in dl_group.values():
# TODO v17: pass line_number as argument of _prepare_declaration_line()
# we can't afford to modify the proto of _prepare_declaration_line() in v16
vals = cl_lines._prepare_declaration_line()
declaration_line = ipdl.create(vals)
declaration_line = ipdl.with_context(
default_line_number=line_number
).create(vals)
cl_lines.write({"declaration_line_id": declaration_line.id})
line_number += 1

def _check_generate_xml(self):
self.ensure_one()
Expand Down Expand Up @@ -960,9 +978,13 @@ def _get_xlsx_report_filename(self):
)
return filename

def done(self):
def draft2confirmed(self):
for decl in self:
decl.generate_declaration()
self.write({"state": "confirmed"})

def confirmed2done(self):
for decl in self:
decl.generate_xml()
self.write({"state": "done"})

Expand Down Expand Up @@ -1017,8 +1039,8 @@ class IntrastatProductComputationLine(models.Model):
src_dest_country_code = fields.Char(
compute="_compute_src_dest_country_code",
string="Country Code",
required=True,
readonly=False,
store=True,
help="2 letters code of the country of origin/destination.\n"
"Specify 'XI' for Northern Ireland.",
)
Expand Down Expand Up @@ -1075,8 +1097,8 @@ class IntrastatProductComputationLine(models.Model):
compute="_compute_product_origin_country_code",
string="Country Code of Origin of the Product",
size=2,
required=True,
readonly=False,
store=True,
help="2 letters ISO code of the country of origin of the product.\n"
"Specify 'QU' when the country of origin is unknown.\n",
)
Expand Down Expand Up @@ -1211,6 +1233,9 @@ class IntrastatProductDeclarationLine(models.Model):
ondelete="cascade",
readonly=True,
)
# line_number is used by localization modules to point the user to a specific
# declaration line in an error messages when generation the XML file
line_number = fields.Integer(readonly=True)
company_id = fields.Many2one(related="parent_id.company_id")
company_currency_id = fields.Many2one(
related="company_id.currency_id", string="Company currency"
Expand All @@ -1229,7 +1254,6 @@ class IntrastatProductDeclarationLine(models.Model):
)
src_dest_country_code = fields.Char(
string="Country Code",
required=True,
help="2 letters ISO code of the country of origin/destination.\n"
"Specify 'XI' for Northern Ireland and 'XU' for Great Britain.",
)
Expand Down Expand Up @@ -1260,8 +1284,6 @@ class IntrastatProductDeclarationLine(models.Model):
product_origin_country_code = fields.Char(
string="Country of Origin of the Product",
size=2,
required=True,
default="QU",
help="2 letters ISO code of the country of origin of the product except for the UK.\n"
"Specify 'XI' for Northern Ireland and 'XU' for Great Britain.\n"
"Specify 'QU' when the country is unknown.\n",
Expand Down
3 changes: 3 additions & 0 deletions intrastat_product/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ access_read_purchase_move_intrastat_line,Read access to Purchase User on Invoice
access_read_account_move_intrastat_line,Read access on Invoice Intrastat Lines,model_account_move_intrastat_line,account.group_account_readonly,1,0,0,0
access_account_move_intrastat_line,Full access on Invoice Intrastat Lines,model_account_move_intrastat_line,account.group_account_invoice,1,1,1,1
access_intrastat_product_declaration,Full access on Intrastat Product Declarations to Accountant,model_intrastat_product_declaration,account.group_account_user,1,1,1,1
access_intrastat_product_declaration_readonly,Read-only access on Intrastat Product Declarations to Auditor,model_intrastat_product_declaration,account.group_account_readonly,1,0,0,0
access_intrastat_product_computation_line,Full access on Intrastat Product Computation Lines to Accountant,model_intrastat_product_computation_line,account.group_account_user,1,1,1,1
access_intrastat_product_computation_line_readonly,Readon-only access on Intrastat Product Computation Lines to Auditor,model_intrastat_product_computation_line,account.group_account_readonly,1,0,0,0
access_intrastat_product_declaration_line,Full access on Intrastat Product Declaration Lines to Accountant,model_intrastat_product_declaration_line,account.group_account_user,1,1,1,1
access_intrastat_product_declaration_line_readonly,Read-only access on Intrastat Product Declaration Lines to Auditor,model_intrastat_product_declaration_line,account.group_account_readonly,1,0,0,0
access_intrastat_result_view,Access on intrastat.result.view,model_intrastat_result_view,account.group_account_user,1,1,1,0
6 changes: 4 additions & 2 deletions intrastat_product/tests/test_brexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_brexit_sale(self):
}
)
self.declaration.action_gather()
self.declaration.done()
self.declaration.draft2confirmed()
self.declaration.confirmed2done()
cline = self.declaration.computation_line_ids
dline = self.declaration.declaration_line_ids
self.assertEqual(cline.src_dest_country_code, "XI")
Expand All @@ -84,7 +85,8 @@ def test_brexit_purchase(self):
}
)
self.declaration.action_gather()
self.declaration.done()
self.declaration.draft2confirmed()
self.declaration.confirmed2done()
clines = self.declaration.computation_line_ids
cl_uk = clines.filtered(lambda r: r.product_id == self.product_uk)
dlines = self.declaration.declaration_line_ids
Expand Down
3 changes: 2 additions & 1 deletion intrastat_product/tests/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def test_purchase_to_invoice_default(self):
self.declaration.action_gather()

self._check_line_values()
self.declaration.done()
self.declaration.draft2confirmed()
self.declaration.confirmed2done()
self._check_line_values(final=True)

# Check the Excel file
Expand Down
3 changes: 2 additions & 1 deletion intrastat_product/tests/test_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def test_sale_declaration(self):
self.declaration.action_gather()

self._check_line_values()
self.declaration.done()
self.declaration.draft2confirmed()
self.declaration.confirmed2done()
self._check_line_values(final=True)

# Check the Excel file
Expand Down
46 changes: 39 additions & 7 deletions intrastat_product/views/intrastat_product_declaration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,33 @@
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('action', '=', 'nihil')]}"
string="Generate Lines from Invoices"
class="btn-primary"
groups="account.group_account_user"
/>
<button
name="done"
name="draft2confirmed"
string="Confirm"
type="object"
class="btn-primary"
states="draft"
help="Generate declaration lines, generate XML export and set declaration to 'Done'"
help="Generate declaration lines"
groups="account.group_account_user"
/>
<button
name="confirmed2done"
string="Generate XML File"
type="object"
class="btn-primary"
states="confirmed"
help="Generate XML file and set declaration to 'Done'"
groups="account.group_account_user"
/>
<button
name="back2draft"
string="Back to Draft"
type="object"
states="done"
states="confirmed,done"
confirm="Are you sure you want to go back to draft?"
groups="account.group_account_user"
/>
<button
name="%(intrastat_product.intrastat_product_xlsx_report)d"
Expand All @@ -38,8 +50,7 @@
<sheet>
<div class="oe_title">
<h1>
<span>Intrastat Product Declaration </span>
<field name="year_month" class="oe_inline" />
<field name="display_name" />
</h1>
</div>
<group name="top-block">
Expand Down Expand Up @@ -81,15 +92,19 @@
nolabel="1"
/>
</page>
<page string="Declaration Lines" name="declaration_lines">
<page
string="Declaration Lines"
name="declaration_lines"
states="confirmed,done"
>
<field
name="declaration_line_ids"
context="{'declaration_type': declaration_type, 'reporting_level': reporting_level}"
nolabel="1"
/>
</page>
<page string="Notes" name="note">
<field name="note" widget="html" />
<field name="note" />
</page>
</notebook>
</sheet>
Expand Down Expand Up @@ -150,6 +165,11 @@
string="Draft"
domain="[('state', '=', 'draft')]"
/>
<filter
name="confirmed"
string="Confirmed"
domain="[('state', '=', 'confirmed')]"
/>
<filter name="done" string="Done" domain="[('state', '=', 'done')]" />
<group string="Group By" name="group_by">
<filter
Expand All @@ -162,6 +182,11 @@
string="Type"
context="{'group_by': 'declaration_type'}"
/>
<filter
name="state_group_by"
string="State"
context="{'group_by': 'state'}"
/>
</group>
</search>
</field>
Expand Down Expand Up @@ -368,6 +393,7 @@
name="parent_id"
invisible="not context.get('intrastat_product_declaration_line_main_view')"
/>
<field name="line_number" />
<field name="declaration_type" invisible="1" />
<field name="reporting_level" invisible="1" />
<field name="company_country_code" invisible="1" />
Expand Down Expand Up @@ -437,6 +463,12 @@
<field name="declaration_type" invisible="1" />
<field name="reporting_level" invisible="1" />
<field name="company_country_code" invisible="1" />
<field
name="line_number"
optional="show"
string="Line"
decoration-bf="1"
/>
<field
name="hs_code_id"
attrs="{'column_invisible': [('parent.reporting_level', '!=', 'extended')]}"
Expand Down
Loading