Skip to content

Commit d962827

Browse files
authored
Merge pull request #649 from Tecnativa/9.0-mig-base_import_match
[9.0] [MIG] base_import_match module
2 parents 73c0884 + ab03a74 commit d962827

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+9492
-0
lines changed

base_import_match/README.rst

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
=================
6+
Base Import Match
7+
=================
8+
9+
By default, when importing data (like CSV import) with the ``base_import``
10+
module, Odoo follows this rule:
11+
12+
- If you import the XMLID of a record, make an **update**.
13+
- If you do not, **create** a new record.
14+
15+
This module allows you to set additional rules to match if a given import is an
16+
update or a new record.
17+
18+
This is useful when you need to sync heterogeneous databases, and the field you
19+
use to match records in those databases with Odoo's is not the XMLID but the
20+
name, VAT, email, etc.
21+
22+
After installing this module, the import logic will be changed to:
23+
24+
- If you import the XMLID of a record, make an **update**.
25+
- If you do not:
26+
27+
- If there are import match rules for the model you are importing:
28+
29+
- Discard the rules that require fields you are not importing.
30+
- Traverse the remaining rules one by one in order to find a match in the database.
31+
32+
- Skip the rule if it requires a special condition that is not
33+
satisfied.
34+
- If one match is found:
35+
36+
- Stop traversing the rest of valid rules.
37+
- **Update** that record.
38+
- If zero or multiple matches are found:
39+
40+
- Continue with the next rule.
41+
- If all rules are exhausted and no single match is found:
42+
43+
- **Create** a new record.
44+
- If there are no match rules for your model:
45+
46+
- **Create** a new record.
47+
48+
By default 2 rules are installed for production instances:
49+
50+
- One rule that will allow you to update companies based on their VAT, when
51+
``is_company`` is ``True``.
52+
- One rule that will allow you to update users based on their login.
53+
54+
In demo instances there are more examples.
55+
56+
Configuration
57+
=============
58+
59+
To configure this module, you need to:
60+
61+
#. Go to *Settings > Technical > Database Structure > Import Match*.
62+
#. *Create*.
63+
#. Choose a *Model*.
64+
#. Choose the *Fields* that conform an unique key in that model.
65+
#. If the rule must be used only for certain imported values, check
66+
*Conditional* and enter the **exact string** that is going to be imported
67+
in *Imported value*.
68+
69+
#. Keep in mind that the match here is evaluated as a case sensitive
70+
**text string** always. If you enter e.g. ``True``, it will match that
71+
string, but will not match ``1`` or ``true``.
72+
#. *Save*.
73+
74+
In that list view, you can sort rules by drag and drop.
75+
76+
Usage
77+
=====
78+
79+
To use this module, you need to:
80+
81+
#. Follow steps in **Configuration** section above.
82+
#. Go to any list view.
83+
#. Press *Import* and follow the import procedure as usual.
84+
85+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
86+
:alt: Try me on Runbot
87+
:target: https://runbot.odoo-community.org/runbot/149/9.0
88+
89+
Known Issues / Roadmap
90+
======================
91+
92+
* Add a setting to throw an error when multiple matches are found, instead of
93+
falling back to creation of new record.
94+
95+
Bug Tracker
96+
===========
97+
98+
Bugs are tracked on `GitHub Issues
99+
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
100+
check there if your issue has already been reported. If you spotted it first,
101+
help us smashing it by providing a detailed and welcomed feedback.
102+
103+
Credits
104+
=======
105+
106+
Contributors
107+
------------
108+
109+
* Jairo Llopis <[email protected]>
110+
* Vicent Cubells <[email protected]>
111+
112+
Maintainer
113+
----------
114+
115+
.. image:: https://odoo-community.org/logo.png
116+
:alt: Odoo Community Association
117+
:target: https://odoo-community.org
118+
119+
This module is maintained by the OCA.
120+
121+
OCA, or the Odoo Community Association, is a nonprofit organization whose
122+
mission is to support the collaborative development of Odoo features and
123+
promote its widespread use.
124+
125+
To contribute to this module, please visit https://odoo-community.org.

base_import_match/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
3+
# Copyright 2016 Tecnativa - Vicent Cubells
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
6+
from . import models

base_import_match/__openerp__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
3+
# Copyright 2016 Tecnativa - Vicent Cubells
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
{
6+
"name": "Base Import Match",
7+
"summary": "Try to avoid duplicates before importing",
8+
"version": "9.0.1.0.0",
9+
"category": "Tools",
10+
"website": "https://tecnativa.com",
11+
"author": "Grupo ESOC Ingeniería de Servicios,"
12+
"Tecnativa, "
13+
"Odoo Community Association (OCA)",
14+
"license": "AGPL-3",
15+
"application": False,
16+
"installable": True,
17+
"depends": [
18+
"base_import",
19+
],
20+
"data": [
21+
"security/ir.model.access.csv",
22+
"data/base_import_match.xml",
23+
"views/base_import_match_view.xml",
24+
],
25+
"demo": [
26+
"demo/base_import_match.xml",
27+
],
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
3+
Copyright 2016 Tecnativa - Vicent Cubells
4+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
5+
6+
<odoo noupdate="1">
7+
<!-- Match partners by VAT when is_company is True -->
8+
<record model="base_import.match" id="res_partner_vat">
9+
<field name="model_id" eval="ref('base.model_res_partner')"/>
10+
<field name="sequence" type="int">10</field>
11+
</record>
12+
<record model="base_import.match.field" id="res_partner_vat_vat">
13+
<field name="match_id" ref="base_import_match.res_partner_vat"/>
14+
<field name="field_id" ref="base.field_res_partner_vat"/>
15+
</record>
16+
<record model="base_import.match.field" id="res_partner_vat_is_company">
17+
<field name="match_id" ref="base_import_match.res_partner_vat"/>
18+
<field name="field_id" ref="base.field_res_partner_is_company"/>
19+
<field name="conditional">True</field>
20+
<field name="imported_value">True</field>
21+
</record>
22+
23+
<!-- Match users by login -->
24+
<record model="base_import.match" id="res_users_login">
25+
<field name="model_id" eval="ref('base.model_res_users')"/>
26+
<field name="sequence" type="int">50</field>
27+
</record>
28+
<record model="base_import.match.field" id="res_users_login_login">
29+
<field name="match_id" ref="base_import_match.res_users_login"/>
30+
<field name="field_id" ref="base.field_res_users_login"/>
31+
</record>
32+
33+
</odoo>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
3+
Copyright 2016 Tecnativa - Vicent Cubells
4+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
5+
<odoo noupdate="1">
6+
7+
<!-- Match partners by name, parent_id and is_company -->
8+
<record model="base_import.match" id="res_partner_parent_name_is_company">
9+
<field name="model_id" eval="ref('base.model_res_partner')"/>
10+
<field name="sequence" type="int">20</field>
11+
</record>
12+
<record model="base_import.match.field" id="res_partner_parent_name_is_company_name">
13+
<field name="match_id" ref="res_partner_parent_name_is_company"/>
14+
<field name="field_id" ref="base.field_res_partner_name"/>
15+
</record>
16+
<record model="base_import.match.field" id="res_partner_parent_name_is_company_parent">
17+
<field name="match_id" ref="res_partner_parent_name_is_company"/>
18+
<field name="field_id" ref="base.field_res_partner_parent_id"/>
19+
</record>
20+
<record model="base_import.match.field" id="res_partner_parent_name_is_company_is_company">
21+
<field name="match_id" ref="res_partner_parent_name_is_company"/>
22+
<field name="field_id" ref="base.field_res_partner_is_company"/>
23+
</record>
24+
25+
<!-- Match partner by email -->
26+
<record model="base_import.match" id="res_partner_email">
27+
<field name="model_id" eval="ref('base.model_res_partner')"/>
28+
<field name="sequence" type="int">30</field>
29+
</record>
30+
<record model="base_import.match.field" id="res_partner_email_email">
31+
<field name="match_id" ref="base_import_match.res_partner_email"/>
32+
<field name="field_id" ref="base.field_res_partner_email"/>
33+
</record>
34+
35+
<!-- Match partner by name -->
36+
<record model="base_import.match" id="res_partner_name">
37+
<field name="model_id" eval="ref('base.model_res_partner')"/>
38+
<field name="sequence" type="int">40</field>
39+
</record>
40+
<record model="base_import.match.field" id="res_partner_name_name">
41+
<field name="match_id" ref="base_import_match.res_partner_name"/>
42+
<field name="field_id" ref="base.field_res_partner_name"/>
43+
</record>
44+
45+
</odoo>

base_import_match/i18n/am.po

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * base_import_match
4+
#
5+
# Translators:
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: server-tools (8.0)\n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2016-09-16 09:29+0000\n"
11+
"PO-Revision-Date: 2016-05-27 15:24+0000\n"
12+
"Last-Translator: <>\n"
13+
"Language-Team: Amharic (http://www.transifex.com/oca/OCA-server-tools-8-0/language/am/)\n"
14+
"MIME-Version: 1.0\n"
15+
"Content-Type: text/plain; charset=UTF-8\n"
16+
"Content-Transfer-Encoding: \n"
17+
"Language: am\n"
18+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
19+
20+
#. module: base_import_match
21+
#: field:base_import.match.field,conditional:0
22+
msgid "Conditional"
23+
msgstr ""
24+
25+
#. module: base_import_match
26+
#: field:base_import.match,create_uid:0
27+
#: field:base_import.match.field,create_uid:0
28+
msgid "Created by"
29+
msgstr "Creado por"
30+
31+
#. module: base_import_match
32+
#: field:base_import.match,create_date:0
33+
#: field:base_import.match.field,create_date:0
34+
msgid "Created on"
35+
msgstr "Creado en"
36+
37+
#. module: base_import_match
38+
#: model:ir.model,name:base_import_match.model_base_import_match
39+
msgid "Deduplicate settings prior to CSV imports."
40+
msgstr ""
41+
42+
#. module: base_import_match
43+
#: field:base_import.match,display_name:0
44+
#: field:base_import.match.field,display_name:0
45+
msgid "Display Name"
46+
msgstr ""
47+
48+
#. module: base_import_match
49+
#: help:base_import.match.field,conditional:0
50+
msgid "Enable if you want to use this field only in some conditions."
51+
msgstr ""
52+
53+
#. module: base_import_match
54+
#: field:base_import.match.field,field_id:0
55+
msgid "Field"
56+
msgstr ""
57+
58+
#. module: base_import_match
59+
#: model:ir.model,name:base_import_match.model_base_import_match_field
60+
msgid "Field import match definition"
61+
msgstr ""
62+
63+
#. module: base_import_match
64+
#: help:base_import.match.field,field_id:0
65+
msgid "Field that will be part of an unique key."
66+
msgstr ""
67+
68+
#. module: base_import_match
69+
#: field:base_import.match,field_ids:0
70+
msgid "Fields"
71+
msgstr ""
72+
73+
#. module: base_import_match
74+
#: help:base_import.match,field_ids:0
75+
msgid "Fields that will define an unique key."
76+
msgstr ""
77+
78+
#. module: base_import_match
79+
#: view:base_import.match:base_import_match.match_search_view
80+
msgid "Group By"
81+
msgstr ""
82+
83+
#. module: base_import_match
84+
#: field:base_import.match,id:0 field:base_import.match.field,id:0
85+
msgid "ID"
86+
msgstr "ID"
87+
88+
#. module: base_import_match
89+
#: help:base_import.match.field,imported_value:0
90+
msgid ""
91+
"If the imported value is not this, the whole matching rule will be "
92+
"discarded. Be careful, this data is always treated as a string, and "
93+
"comparison is case-sensitive so if you set 'True', it will NOT match '1' nor"
94+
" 'true', only EXACTLY 'True'."
95+
msgstr ""
96+
97+
#. module: base_import_match
98+
#: view:base_import.match:base_import_match.match_form_view
99+
#: view:base_import.match:base_import_match.match_search_view
100+
#: view:base_import.match:base_import_match.match_tree_view
101+
#: model:ir.actions.act_window,name:base_import_match.match_action
102+
#: model:ir.ui.menu,name:base_import_match.match_menu
103+
msgid "Import Match"
104+
msgstr ""
105+
106+
#. module: base_import_match
107+
#: field:base_import.match.field,imported_value:0
108+
msgid "Imported value"
109+
msgstr ""
110+
111+
#. module: base_import_match
112+
#: help:base_import.match,model_id:0 help:base_import.match.field,model_id:0
113+
msgid "In this model you will apply the match."
114+
msgstr ""
115+
116+
#. module: base_import_match
117+
#: field:base_import.match,__last_update:0
118+
#: field:base_import.match.field,__last_update:0
119+
msgid "Last Modified on"
120+
msgstr ""
121+
122+
#. module: base_import_match
123+
#: field:base_import.match,write_uid:0
124+
#: field:base_import.match.field,write_uid:0
125+
msgid "Last Updated by"
126+
msgstr "Última actualización por"
127+
128+
#. module: base_import_match
129+
#: field:base_import.match,write_date:0
130+
#: field:base_import.match.field,write_date:0
131+
msgid "Last Updated on"
132+
msgstr "Última actualización en"
133+
134+
#. module: base_import_match
135+
#: field:base_import.match.field,match_id:0
136+
msgid "Match"
137+
msgstr ""
138+
139+
#. module: base_import_match
140+
#: view:base_import.match:base_import_match.match_search_view
141+
#: field:base_import.match,model_id:0 field:base_import.match,model_name:0
142+
#: field:base_import.match.field,model_id:0
143+
msgid "Model"
144+
msgstr ""
145+
146+
#. module: base_import_match
147+
#: field:base_import.match,name:0 field:base_import.match.field,name:0
148+
msgid "Name"
149+
msgstr ""
150+
151+
#. module: base_import_match
152+
#: field:base_import.match,sequence:0
153+
msgid "Sequence"
154+
msgstr ""

0 commit comments

Comments
 (0)