From 1526714bb26b1a4926fe768e332e6131c676d433 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Fri, 10 Nov 2023 18:16:51 +0100 Subject: [PATCH 1/2] [IMP] intrastat_product_hscodes_import: simplify install wizard --- .../intrastat_hscodes_import_installer.py | 25 ++++++------------- ...trastat_hscodes_import_installer_views.xml | 2 -- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py index 3b28040..a0a048e 100644 --- a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py +++ b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py @@ -16,8 +16,6 @@ class IntrastatHSCodesImportInstaller(models.TransientModel): _inherit = "res.config.installer" _description = "Intrastat HS Codes Import Installer" - intrastat_file_year = fields.Selection(selection=[("2022", "2022")], default="2022") - intrastat_file_delimiter = fields.Selection(selection=[(";", ";")], default=";") share_codes = fields.Boolean( default=True, help="Set this flag to share the Intrastat Codes between all " @@ -34,10 +32,6 @@ class IntrastatHSCodesImportInstaller(models.TransientModel): domain = OR([domain, ("company_id", "=", self.company_id.id)]) return domain - @api.model - def _intrastat_file_available_langs(self): - return ["en", "fr", "fr", "de"] - @api.model def _load_code(self, row, hs_codes, hscodes_lookup): company_id = self.company_id.id or False @@ -65,10 +59,12 @@ class IntrastatHSCodesImportInstaller(models.TransientModel): res = super().execute() # get path for intrastat hs codes files module = __name__.split("addons.")[1].split(".")[0] + module_path = "" for adp in odoo.addons.__path__: module_path = adp + os.sep + module if os.path.isdir(module_path): break + module_path += os.sep + "static/data" + os.sep # load existing intrastat codes hs_codes = self.env["hs.code"].search(self._hscodes_vals_domain()) hscodes_lookup = {} @@ -76,23 +72,18 @@ class IntrastatHSCodesImportInstaller(models.TransientModel): hscodes_lookup[c.local_code] = i # load csv files from data lang_found = False - for lang in self._intrastat_file_available_langs(): + CN_fns = os.listdir(module_path) + langs = {x[5:7] for x in CN_fns} + for lang in langs: lang_recs = self.env["res.lang"].search([("code", "=like", lang + "_%")]) if not lang_recs: continue lang_found = True - intrastat_filename = ( - self.intrastat_file_year + "_" + lang + "_intrastat_codes.csv" - ) - intrastat_file_path = ( - module_path + os.sep + "static/data" + os.sep + intrastat_filename - ) + CN_fn = [x for x in CN_fns if x[5:7] == lang][0] with io.open( - intrastat_file_path, mode="r", encoding="Windows-1252" + module_path + CN_fn, mode="r", encoding="Windows-1252" ) as CN_file: - intrastat_codes = csv.DictReader( - CN_file, delimiter=self.intrastat_file_delimiter - ) + intrastat_codes = csv.DictReader(CN_file, delimiter=";") for lang_rec in lang_recs: hs_codes = hs_codes.with_context(lang=lang_rec.code) for row in intrastat_codes: diff --git a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml index 5b7f5cd..9509bfd 100644 --- a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml +++ b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml @@ -19,8 +19,6 @@ groups="base.group_multi_company" attrs="{'required': [('share_codes','=',False)],'invisible': [('share_codes','=',True)]}" /> - - From e3d7e6183b71c814a3f2fbd97afe5a252ae20042 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Fri, 10 Nov 2023 18:23:08 +0100 Subject: [PATCH 2/2] [IMP] hscodes import: company always visible in install wizard Module intrastat_product_hscodes_import, install wizard: The Company is a required field unchecking the 'Share Codes' flag. User having access to the Configuration Wizards will now be able to set the company field even if they do not belong to the multi-company usability group. --- .../wizards/intrastat_hscodes_import_installer_views.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml index 9509bfd..f228b0d 100644 --- a/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml +++ b/intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer_views.xml @@ -16,7 +16,6 @@ name="company_id" options="{'no_create': True, 'no_open': True}" domain="[('id', 'in', allowed_company_ids)]" - groups="base.group_multi_company" attrs="{'required': [('share_codes','=',False)],'invisible': [('share_codes','=',True)]}" />