From 6080d1792d6d5f09b8499c5d66c49f4751992274 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 8 Jun 2020 22:39:46 +0200 Subject: [PATCH] intrastat_product: Add xml_attachment_id field intrastat_product: add mail.activity.mixin and widget in form view product_harmonized_system: remove archive button (use Action menu) All modules: - use super() instead of super(class, self) - Update domain_force in multi-company ir.rule to v13 standard --- intrastat_base/models/intrastat_common.py | 2 +- .../models/intrastat_product_declaration.py | 16 +++++++++++++--- intrastat_product/models/sale_order.py | 2 +- .../security/intrastat_security.xml | 6 +++--- .../views/intrastat_product_declaration.xml | 7 ++++++- product_harmonized_system/models/hs_code.py | 4 ++-- .../security/product_hs_security.xml | 2 +- product_harmonized_system/views/hs_code.xml | 19 +++++++------------ 8 files changed, 34 insertions(+), 24 deletions(-) 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')" /> -