diff --git a/intrastat_base/models/intrastat_common.py b/intrastat_base/models/intrastat_common.py
index 00ac4b1..45ad7c6 100644
--- a/intrastat_base/models/intrastat_common.py
+++ b/intrastat_base/models/intrastat_common.py
@@ -148,7 +148,7 @@ class IntrastatCommon(models.AbstractModel):
_("Cannot delete the declaration %s " "because it is in Done state")
% self.year_month
)
- return super(IntrastatCommon, self).unlink()
+ return super().unlink()
class IntrastatResultView(models.TransientModel):
diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py
index 3423077..4535b78 100644
--- a/intrastat_product/models/intrastat_product_declaration.py
+++ b/intrastat_product/models/intrastat_product_declaration.py
@@ -18,7 +18,7 @@ class IntrastatProductDeclaration(models.Model):
_name = "intrastat.product.declaration"
_description = "Intrastat Product Report Base Object"
_rec_name = "year_month"
- _inherit = ["mail.thread", "intrastat.common"]
+ _inherit = ["mail.thread", "mail.activity.mixin", "intrastat.common"]
_order = "year_month desc, type, revision"
_sql_constraints = [
(
@@ -32,7 +32,7 @@ class IntrastatProductDeclaration(models.Model):
@api.model
def default_get(self, fields_list):
- res = super(IntrastatProductDeclaration, self).default_get(fields_list)
+ res = super().default_get(fields_list)
decl_date = fields.Date.context_today(self) - relativedelta(months=1)
res.update(
{"year": str(decl_date.year), "month": str(decl_date.month).rjust(2, "0")}
@@ -150,6 +150,7 @@ class IntrastatProductDeclaration(models.Model):
states={"done": [("readonly", True)]},
)
valid = fields.Boolean(compute="_compute_check_validity", string="Valid")
+ xml_attachment_id = fields.Many2one("ir.attachment", string="XML Export")
@api.model
def _default_company_id(self):
@@ -225,7 +226,7 @@ class IntrastatProductDeclaration(models.Model):
self.ensure_one()
default = default or {}
default["revision"] = self.revision + 1
- return super(IntrastatProductDeclaration, self).copy(default)
+ return super().copy(default)
def _account_config_warning(self, msg):
action = self.env.ref("account.action_account_config")
@@ -805,6 +806,14 @@ class IntrastatProductDeclaration(models.Model):
def generate_xml(self):
""" generate the INTRASTAT Declaration XML file """
self.ensure_one()
+ if self.xml_attachment_id:
+ raise UserError(
+ _(
+ "An XML Export already exists for %s. "
+ "To re-generate it, you must first delete it."
+ )
+ % self.display_name
+ )
self.message_post(body=_("Generate XML Declaration File"))
self._check_generate_xml()
self._unlink_attachments()
@@ -813,6 +822,7 @@ class IntrastatProductDeclaration(models.Model):
attach_id = self._attach_xml_file(
xml_string, "{}_{}".format(self.type, self.revision)
)
+ self.write({"xml_attachment_id": attach_id})
return self._open_attach_view(attach_id)
else:
raise UserError(_("No XML File has been generated."))
diff --git a/intrastat_product/models/sale_order.py b/intrastat_product/models/sale_order.py
index eebbeb4..9add6e4 100644
--- a/intrastat_product/models/sale_order.py
+++ b/intrastat_product/models/sale_order.py
@@ -19,7 +19,7 @@ class SaleOrder(models.Model):
def _prepare_invoice(self):
"""Copy destination country to invoice"""
- vals = super(SaleOrder, self)._prepare_invoice()
+ vals = super()._prepare_invoice()
if self.intrastat_transport_id:
vals["intrastat_transport_id"] = self.intrastat_transport_id.id
if self.warehouse_id.region_id:
diff --git a/intrastat_product/security/intrastat_security.xml b/intrastat_product/security/intrastat_security.xml
index f4c714a..b1e9d11 100644
--- a/intrastat_product/security/intrastat_security.xml
+++ b/intrastat_product/security/intrastat_security.xml
@@ -5,20 +5,20 @@
['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]
+ >['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
Intrastat Region Company rule
['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]
+ >['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
Intrastat Product Declaration Company rule
['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]
+ >['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
diff --git a/intrastat_product/views/intrastat_product_declaration.xml b/intrastat_product/views/intrastat_product_declaration.xml
index 0a75377..9934bed 100644
--- a/intrastat_product/views/intrastat_product_declaration.xml
+++ b/intrastat_product/views/intrastat_product_declaration.xml
@@ -23,7 +23,7 @@
name="generate_xml"
string="Generate XML Declaration File"
type="object"
- attrs="{'invisible': [('state', '!=', 'draft')]}"
+ attrs="{'invisible': [('xml_attachment_id', '!=', False)]}"
invisible="context.get('generic_intrastat_product_declaration')"
/>
+
@@ -115,6 +119,7 @@
+
diff --git a/product_harmonized_system/models/hs_code.py b/product_harmonized_system/models/hs_code.py
index b2ee7c8..475c399 100644
--- a/product_harmonized_system/models/hs_code.py
+++ b/product_harmonized_system/models/hs_code.py
@@ -99,9 +99,9 @@ class HSCode(models.Model):
def create(self, vals):
if vals.get("local_code"):
vals["local_code"] = vals["local_code"].replace(" ", "")
- return super(HSCode, self).create(vals)
+ return super().create(vals)
def write(self, vals):
if vals.get("local_code"):
vals["local_code"] = vals["local_code"].replace(" ", "")
- return super(HSCode, self).write(vals)
+ return super().write(vals)
diff --git a/product_harmonized_system/security/product_hs_security.xml b/product_harmonized_system/security/product_hs_security.xml
index fc1a5e0..42c7761 100644
--- a/product_harmonized_system/security/product_hs_security.xml
+++ b/product_harmonized_system/security/product_hs_security.xml
@@ -5,6 +5,6 @@
['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]
+ >['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
diff --git a/product_harmonized_system/views/hs_code.xml b/product_harmonized_system/views/hs_code.xml
index 1841ced..4b0316c 100644
--- a/product_harmonized_system/views/hs_code.xml
+++ b/product_harmonized_system/views/hs_code.xml
@@ -55,6 +55,13 @@
hs.code