diff --git a/base_import_match/README.rst b/base_import_match/README.rst index c11ff80b..b3bdf41a 100644 --- a/base_import_match/README.rst +++ b/base_import_match/README.rst @@ -84,7 +84,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/149/10.0 + :target: https://runbot.odoo-community.org/runbot/149/11.0 Known Issues / Roadmap ====================== @@ -108,6 +108,7 @@ Contributors * Jairo Llopis * Vicent Cubells +* Marçal Isern Maintainer ---------- diff --git a/base_import_match/__init__.py b/base_import_match/__init__.py index 197214cd..4724f5f1 100644 --- a/base_import_match/__init__.py +++ b/base_import_match/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/base_import_match/__manifest__.py b/base_import_match/__manifest__.py index a9068280..99359c3a 100644 --- a/base_import_match/__manifest__.py +++ b/base_import_match/__manifest__.py @@ -1,11 +1,11 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells +# Copyright 2018 QubiQ - Marçal Isern # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Base Import Match", "summary": "Try to avoid duplicates before importing", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "category": "Tools", "website": "https://tecnativa.com", "author": "Grupo ESOC Ingeniería de Servicios," diff --git a/base_import_match/models/__init__.py b/base_import_match/models/__init__.py index 45ac4f35..09759b3a 100644 --- a/base_import_match/models/__init__.py +++ b/base_import_match/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/base_import_match/models/base.py b/base_import_match/models/base.py index 62dff40b..55bb21c0 100644 --- a/base_import_match/models/base.py +++ b/base_import_match/models/base.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Jairo Llopis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, models @@ -20,7 +19,8 @@ class Base(models.AbstractModel): if self.env["base_import.match"]._usable_rules(self._name, fields): newdata = list() # Data conversion to ORM format - import_fields = map(models.fix_import_export_id_paths, fields) + import_fields = list( + map(models.fix_import_export_id_paths, fields)) converted_data = self._convert_records( self._extract_records(import_fields, data)) # Mock Odoo to believe the user is importing the ID field @@ -44,7 +44,10 @@ class Base(models.AbstractModel): match = self.env["base_import.match"]._match_find( self, record, row) # Give a valid XMLID to this row if a match was found - row["id"] = (match._BaseModel__export_xml_id() + # To generate externals IDS. + match.export_data(fields) + ext_id = match.get_external_id() + row["id"] = (ext_id[match.id] if match else row.get("id", u"")) # Store the modified row, in the same order as fields newdata.append(tuple(row[f] for f in clean_fields)) diff --git a/base_import_match/models/base_import.py b/base_import_match/models/base_import.py index 9350ce5a..e23ffd7d 100644 --- a/base_import_match/models/base_import.py +++ b/base_import_match/models/base_import.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/base_import_match/readme/CONFIGURE.rst b/base_import_match/readme/CONFIGURE.rst new file mode 100644 index 00000000..371f3219 --- /dev/null +++ b/base_import_match/readme/CONFIGURE.rst @@ -0,0 +1,16 @@ +To configure this module, you need to: + +#. Go to *Settings > Technical > Database Structure > Import Match*. +#. *Create*. +#. Choose a *Model*. +#. Choose the *Fields* that conform a unique key in that model. +#. If the rule must be used only for certain imported values, check + *Conditional* and enter the **exact string** that is going to be imported + in *Imported value*. + + #. Keep in mind that the match here is evaluated as a case sensitive + **text string** always. If you enter e.g. ``True``, it will match that + string, but will not match ``1`` or ``true``. +#. *Save*. + +In that list view, you can sort rules by drag and drop. \ No newline at end of file diff --git a/base_import_match/readme/DESCRIPTION.rst b/base_import_match/readme/DESCRIPTION.rst new file mode 100644 index 00000000..ef757f8d --- /dev/null +++ b/base_import_match/readme/DESCRIPTION.rst @@ -0,0 +1,46 @@ +By default, when importing data (like CSV import) with the ``base_import`` +module, Odoo follows this rule: + +- If you import the XMLID of a record, make an **update**. +- If you do not, **create** a new record. + +This module allows you to set additional rules to match if a given import is an +update or a new record. + +This is useful when you need to sync heterogeneous databases, and the field you +use to match records in those databases with Odoo's is not the XMLID but the +name, VAT, email, etc. + +After installing this module, the import logic will be changed to: + +- If you import the XMLID of a record, make an **update**. +- If you do not: + + - If there are import match rules for the model you are importing: + + - Discard the rules that require fields you are not importing. + - Traverse the remaining rules one by one in order to find a match in the database. + + - Skip the rule if it requires a special condition that is not + satisfied. + - If one match is found: + + - Stop traversing the rest of valid rules. + - **Update** that record. + - If zero or multiple matches are found: + + - Continue with the next rule. + - If all rules are exhausted and no single match is found: + + - **Create** a new record. + - If there are no match rules for your model: + + - **Create** a new record. + +By default 2 rules are installed for production instances: + +- One rule that will allow you to update companies based on their VAT, when + ``is_company`` is ``True``. +- One rule that will allow you to update users based on their login. + +In demo instances there are more examples. \ No newline at end of file diff --git a/base_import_match/readme/ROADMAP.rst b/base_import_match/readme/ROADMAP.rst new file mode 100644 index 00000000..7a0de732 --- /dev/null +++ b/base_import_match/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Add a setting to throw an error when multiple matches are found, instead of + falling back to creation of new record. \ No newline at end of file diff --git a/base_import_match/readme/USAGE.rst b/base_import_match/readme/USAGE.rst new file mode 100644 index 00000000..301d01a2 --- /dev/null +++ b/base_import_match/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. Follow steps in **Configuration** section above. +#. Go to any list view. +#. Press *Import* and follow the import procedure as usual. \ No newline at end of file diff --git a/base_import_match/tests/__init__.py b/base_import_match/tests/__init__.py index 1d8b5f1b..ff1f96e7 100644 --- a/base_import_match/tests/__init__.py +++ b/base_import_match/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/base_import_match/tests/test_import.py b/base_import_match/tests/test_import.py index b7d977fa..eb344f79 100644 --- a/base_import_match/tests/test_import.py +++ b/base_import_match/tests/test_import.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -32,7 +31,7 @@ class ImportCase(TransactionCase): agrolait.vat = "BE0477472701" record = self._base_import_record("res.partner", "res_partner_vat") record.do(["name", "vat", "is_company"], OPTIONS) - agrolait.env.invalidate_all() + agrolait.env.clear() self.assertEqual(agrolait.name, "Agrolait Changed") def test_res_partner_parent_name_is_company(self):