mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] [11.0] base_import_match
This commit is contained in:
@@ -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 <yajo.sk8@gmail.com>
|
||||
* Vicent Cubells <vicent.cubells@tecnativa.com>
|
||||
* Marçal Isern <marsal.isern@qubiq.es>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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,"
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||
# 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))
|
||||
|
||||
@@ -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).
|
||||
|
||||
16
base_import_match/readme/CONFIGURE.rst
Normal file
16
base_import_match/readme/CONFIGURE.rst
Normal file
@@ -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.
|
||||
46
base_import_match/readme/DESCRIPTION.rst
Normal file
46
base_import_match/readme/DESCRIPTION.rst
Normal file
@@ -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.
|
||||
2
base_import_match/readme/ROADMAP.rst
Normal file
2
base_import_match/readme/ROADMAP.rst
Normal file
@@ -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.
|
||||
5
base_import_match/readme/USAGE.rst
Normal file
5
base_import_match/readme/USAGE.rst
Normal file
@@ -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.
|
||||
@@ -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).
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user