-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import wizards |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2009-2023 Noviat (http://www.noviat.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Intrastat Product - HS Codes Import", | ||
"version": "15.0.1.0.0", | ||
"category": "Intrastat", | ||
"license": "AGPL-3", | ||
"summary": "Module used to import HS Codes for Intrastat Product", | ||
"author": "Noviat, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/intrastat-extrastat", | ||
"depends": [ | ||
"intrastat_product", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"wizards/intrastat_hscodes_import_installer_views.xml", | ||
], | ||
"installable": True, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_intrastat_hscodes_import_installer_admin,access_intrastat_hscodes_import_installer_admin,model_intrastat_hscodes_import_installer,base.group_system,1,1,1,1 | ||
access_intrastat_hscodes_import_installer_account_manager,access_intrastat_hscodes_import_installer_account_manager,model_intrastat_hscodes_import_installer,account.group_account_manager,1,1,1,0 |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import intrastat_hscodes_import_installer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright 2009-2023 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import csv | ||
import io | ||
import os | ||
|
||
import odoo | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
from odoo.osv.expression import OR | ||
|
||
|
||
class IntrastatHSCodesImportInstaller(models.TransientModel): | ||
_name = "intrastat.hscodes.import.installer" | ||
_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 " | ||
"Legal Entities defined in this Odoo Database.\n", | ||
) | ||
company_id = fields.Many2one( | ||
comodel_name="res.company", | ||
string="Company", | ||
) | ||
|
||
def _hscodes_vals_domain(self): | ||
domain = [("company_id", "=", False)] | ||
if self.company_id: | ||
domain = OR([domain, ("company_id", "=", self.company_id.id)]) | ||
return domain | ||
Check warning on line 35 in intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py Codecov / codecov/patchintrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py#L34-L35
|
||
|
||
@api.model | ||
def _intrastat_file_available_langs(self): | ||
return ["en", "fr", "fr", "de"] | ||
|
||
@api.model | ||
def _load_code(self, row, hs_codes): | ||
company_id = self.company_id.id or False | ||
vals = { | ||
Check warning on line 44 in intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py Codecov / codecov/patchintrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py#L43-L44
|
||
"description": row["description"], | ||
"company_id": company_id, | ||
} | ||
intrastat_unit_id = row["unit_id"] | ||
if intrastat_unit_id: | ||
intrastat_unit_ref = "intrastat_product." + intrastat_unit_id | ||
intrastat_unit = self.env.ref(intrastat_unit_ref) | ||
vals["intrastat_unit_id"] = intrastat_unit.id | ||
intrastat_code = row["code"] | ||
Check warning on line 53 in intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py Codecov / codecov/patchintrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py#L50-L53
|
||
hscode_rec = hs_codes.filtered(lambda h: h.local_code == intrastat_code) | ||
if hscode_rec: | ||
hscode_rec.write(vals) | ||
else: | ||
vals["local_code"] = intrastat_code | ||
hscode_rec = self.env["hs.code"].create(vals) | ||
hs_codes |= hscode_rec | ||
return hs_codes | ||
Check warning on line 61 in intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py Codecov / codecov/patchintrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py#L58-L61
|
||
|
||
def execute(self): | ||
res = super().execute() | ||
# get path for intrastat hs codes files | ||
module = __name__.split("addons.")[1].split(".")[0] | ||
for adp in odoo.addons.__path__: | ||
module_path = adp + os.sep + module | ||
if os.path.isdir(module_path): | ||
break | ||
# load existing intrastat codes | ||
hs_codes = self.env["hs.code"].search(self._hscodes_vals_domain()) | ||
# load csv files from data | ||
lang_found = False | ||
for lang in self._intrastat_file_available_langs(): | ||
lang_recs = self.env["res.lang"].search([("code", "=like", lang + "_%")]) | ||
if not lang_recs: | ||
continue | ||
lang_found = True | ||
intrastat_filename = ( | ||
Check warning on line 80 in intrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py Codecov / codecov/patchintrastat_product_hscodes_import/wizards/intrastat_hscodes_import_installer.py#L78-L80
|
||
self.intrastat_file_year + "_" + lang + "_intrastat_codes.csv" | ||
) | ||
intrastat_file_path = ( | ||
module_path + os.sep + "static/data" + os.sep + intrastat_filename | ||
) | ||
with io.open( | ||
intrastat_file_path, mode="r", encoding="Windows-1252" | ||
) as CN_file: | ||
intrastat_codes = csv.DictReader( | ||
CN_file, delimiter=self.intrastat_file_delimiter | ||
) | ||
for lang_rec in lang_recs: | ||
hs_codes = hs_codes.with_context(lang=lang_rec.code) | ||
for row in intrastat_codes: | ||
hs_codes = self._load_code(row, hs_codes) | ||
if not lang_found: | ||
raise UserError( | ||
_( | ||
"Any Language active on your system is available in intrastat codes files [%s]" | ||
) | ||
% ",".join(self._intrastat_file_available_langs()) | ||
) | ||
return res | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="intrastat_hscodes_import_installer_view_form" model="ir.ui.view"> | ||
<field name="name">intrastat.hscodes.import.installer.view</field> | ||
<field name="model">intrastat.hscodes.import.installer</field> | ||
<field name="inherit_id" ref="base.res_config_installer" /> | ||
<field name="arch" type="xml"> | ||
<form position="attributes"> | ||
<attribute name="string">Load Intrastat Codes</attribute> | ||
</form> | ||
<xpath expr="/form/separator[@colspan='4']" position="after"> | ||
<group position="inside"> | ||
<field name="share_codes" /> | ||
<field | ||
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)]}" | ||
/> | ||
<field name="intrastat_file_year" invisible="1" /> | ||
<field name="intrastat_file_delimiter" invisible="1" /> | ||
</group> | ||
</xpath> | ||
<xpath expr="/form/separator[@colspan='4']" position="attributes"> | ||
<attribute name="string">Load Intrastat Codes</attribute> | ||
</xpath> | ||
<xpath expr="//button[@name='action_next']" position="attributes"> | ||
<attribute name="string">Load</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record | ||
id="intrastat_hscodes_import_installer_action" | ||
model="ir.actions.act_window" | ||
> | ||
<field name="name">Load Intrastat Codes</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">intrastat.hscodes.import.installer</field> | ||
<field name="view_id" ref="intrastat_hscodes_import_installer_view_form" /> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
</record> | ||
|
||
<record id="intrastat_installer_todo" model="ir.actions.todo"> | ||
<field name="action_id" ref="intrastat_hscodes_import_installer_action" /> | ||
<field name="sequence">10</field> | ||
</record> | ||
|
||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../intrastat_product_hscodes_import |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |