diff --git a/base_import_match/__manifest__.py b/base_import_match/__manifest__.py
index 2cc6afe6a..26284c6f3 100644
--- a/base_import_match/__manifest__.py
+++ b/base_import_match/__manifest__.py
@@ -7,20 +7,15 @@
"version": "12.0.1.0.0",
"category": "Tools",
"website": "https://tecnativa.com",
- "author": "Tecnativa, "
- "Odoo Community Association (OCA)",
+ "author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
- "depends": [
- "base_import",
- ],
+ "depends": ["base_import",],
"data": [
"security/ir.model.access.csv",
"data/base_import_match.xml",
"views/base_import_match_view.xml",
],
- "demo": [
- "demo/base_import_match.xml",
- ],
+ "demo": ["demo/base_import_match.xml",],
}
diff --git a/base_import_match/data/base_import_match.xml b/base_import_match/data/base_import_match.xml
index 9cc7f91e4..34457e385 100644
--- a/base_import_match/data/base_import_match.xml
+++ b/base_import_match/data/base_import_match.xml
@@ -1,33 +1,30 @@
-
+
-
-
- 10
+
+ 10
-
-
+
+
-
-
- True
- True
+
+
+ True
+ True
-
-
- 50
+
+ 50
-
-
+
+
-
diff --git a/base_import_match/demo/base_import_match.xml b/base_import_match/demo/base_import_match.xml
index 4125a9d0f..ef20521a7 100644
--- a/base_import_match/demo/base_import_match.xml
+++ b/base_import_match/demo/base_import_match.xml
@@ -1,45 +1,50 @@
-
+
-
-
- 20
+
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 30
+
+ 30
-
-
+
+
-
-
- 40
+
+ 40
-
-
+
+
-
diff --git a/base_import_match/models/base.py b/base_import_match/models/base.py
index 55bb21c02..57b589fbd 100644
--- a/base_import_match/models/base.py
+++ b/base_import_match/models/base.py
@@ -19,10 +19,10 @@ class Base(models.AbstractModel):
if self.env["base_import.match"]._usable_rules(self._name, fields):
newdata = list()
# Data conversion to ORM format
- import_fields = list(
- 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))
+ self._extract_records(import_fields, data)
+ )
# Mock Odoo to believe the user is importing the ID field
if "id" not in fields:
fields.append("id")
@@ -41,14 +41,12 @@ class Base(models.AbstractModel):
match = self.browse(dbid)
else:
# Store records that match a combination
- match = self.env["base_import.match"]._match_find(
- self, record, row)
+ match = self.env["base_import.match"]._match_find(self, record, row)
# Give a valid XMLID to this row if a match was found
# 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""))
+ 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))
# We will import the patched data to get updates on matches
diff --git a/base_import_match/models/base_import.py b/base_import_match/models/base_import.py
index e07e6cfca..0fe7ef568 100644
--- a/base_import_match/models/base_import.py
+++ b/base_import_match/models/base_import.py
@@ -2,6 +2,7 @@
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
+
from odoo import api, fields, models, tools
_logger = logging.getLogger(__name__)
@@ -12,10 +13,7 @@ class BaseImportMatch(models.Model):
_description = "Deduplicate settings prior to CSV imports."
_order = "sequence, name"
- name = fields.Char(
- compute="_compute_name",
- store=True,
- index=True)
+ name = fields.Char(compute="_compute_name", store=True, index=True)
sequence = fields.Integer(index=True)
model_id = fields.Many2one(
"ir.model",
@@ -23,18 +21,18 @@ class BaseImportMatch(models.Model):
required=True,
ondelete="cascade",
domain=[("transient", "=", False)],
- help="In this model you will apply the match.")
+ help="In this model you will apply the match.",
+ )
model_name = fields.Char(
- string="Model name",
- related="model_id.model",
- store=True,
- index=True)
+ string="Model name", related="model_id.model", store=True, index=True
+ )
field_ids = fields.One2many(
comodel_name="base_import.match.field",
inverse_name="match_id",
string="Fields",
required=True,
- help="Fields that will define an unique key.")
+ help="Fields that will define an unique key.",
+ )
@api.onchange("model_id")
def _onchange_model_id(self):
@@ -135,37 +133,38 @@ class BaseImportMatchField(models.Model):
_name = "base_import.match.field"
_description = "Field import match definition"
- name = fields.Char(
- related="field_id.name")
+ name = fields.Char(related="field_id.name")
field_id = fields.Many2one(
comodel_name="ir.model.fields",
string="Field",
required=True,
ondelete="cascade",
domain="[('model_id', '=', model_id)]",
- help="Field that will be part of an unique key.")
+ help="Field that will be part of an unique key.",
+ )
match_id = fields.Many2one(
comodel_name="base_import.match",
string="Match",
ondelete="cascade",
- required=True)
- model_id = fields.Many2one(
- related="match_id.model_id")
+ required=True,
+ )
+ model_id = fields.Many2one(related="match_id.model_id")
conditional = fields.Boolean(
- help="Enable if you want to use this field only in some conditions.")
+ help="Enable if you want to use this field only in some conditions."
+ )
imported_value = fields.Char(
help="If the imported value is not this, the whole matching rule will "
- "be discarded. Be careful, this data is always treated as a "
- "string, and comparison is case-sensitive so if you set 'True', "
- "it will NOT match '1' nor 'true', only EXACTLY 'True'.")
+ "be discarded. Be careful, this data is always treated as a "
+ "string, and comparison is case-sensitive so if you set 'True', "
+ "it will NOT match '1' nor 'true', only EXACTLY 'True'."
+ )
@api.depends("conditional", "field_id", "imported_value")
def _compute_display_name(self):
for one in self:
pattern = u"{name} ({cond})" if one.conditional else u"{name}"
one.display_name = pattern.format(
- name=one.field_id.name,
- cond=one.imported_value,
+ name=one.field_id.name, cond=one.imported_value,
)
@api.onchange("field_id", "match_id", "conditional", "imported_value")
diff --git a/base_import_match/tests/test_import.py b/base_import_match/tests/test_import.py
index e266084d7..43a5ff4c9 100644
--- a/base_import_match/tests/test_import.py
+++ b/base_import_match/tests/test_import.py
@@ -3,8 +3,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from os import path
-from odoo.tests.common import TransactionCase
+from odoo.tests.common import TransactionCase
PATH = path.join(path.dirname(__file__), "import_data", "%s.csv")
OPTIONS = {
@@ -18,12 +18,14 @@ class ImportCase(TransactionCase):
def _base_import_record(self, res_model, file_name):
"""Create and return a ``base_import.import`` record."""
with open(PATH % file_name) as demo_file:
- return self.env["base_import.import"].create({
- "res_model": res_model,
- "file": demo_file.read(),
- "file_name": "%s.csv" % file_name,
- "file_type": "csv",
- })
+ return self.env["base_import.import"].create(
+ {
+ "res_model": res_model,
+ "file": demo_file.read(),
+ "file_name": "%s.csv" % file_name,
+ "file_type": "csv",
+ }
+ )
def test_res_partner_vat(self):
"""Change name based on VAT."""
@@ -37,32 +39,32 @@ class ImportCase(TransactionCase):
def test_res_partner_parent_name_is_company(self):
"""Change email based on parent_id, name and is_company."""
record = self._base_import_record(
- "res.partner", "res_partner_parent_name_is_company")
+ "res.partner", "res_partner_parent_name_is_company"
+ )
record.do(["name", "is_company", "parent_id/id", "email"], [], OPTIONS)
self.assertEqual(
self.env.ref("base.res_partner_address_4").email,
- "floyd.steward34.changed@example.com")
+ "floyd.steward34.changed@example.com",
+ )
def test_res_partner_email(self):
"""Change name based on email."""
record = self._base_import_record("res.partner", "res_partner_email")
record.do(["email", "name"], [], OPTIONS)
self.assertEqual(
- self.env.ref("base.res_partner_address_4").name,
- "Floyd Steward Changed")
+ self.env.ref("base.res_partner_address_4").name, "Floyd Steward Changed"
+ )
def test_res_partner_name(self):
"""Change function based on name."""
record = self._base_import_record("res.partner", "res_partner_name")
record.do(["function", "name"], [], OPTIONS)
self.assertEqual(
- self.env.ref("base.res_partner_address_4").function,
- "Function Changed")
+ self.env.ref("base.res_partner_address_4").function, "Function Changed"
+ )
def test_res_users_login(self):
"""Change name based on login."""
record = self._base_import_record("res.users", "res_users_login")
record.do(["login", "name"], [], OPTIONS)
- self.assertEqual(
- self.env.ref("base.user_demo").name,
- "Demo User Changed")
+ self.assertEqual(self.env.ref("base.user_demo").name, "Demo User Changed")
diff --git a/base_import_match/views/base_import_match_view.xml b/base_import_match/views/base_import_match_view.xml
index 88cb9b354..ce5ec9477 100644
--- a/base_import_match/views/base_import_match_view.xml
+++ b/base_import_match/views/base_import_match_view.xml
@@ -1,81 +1,74 @@
-
+
-
-
-
- Import match form view
- base_import.match
-
-
+
+
+
+ Import match tree view
+ base_import.match
+
+
+
+
+
+
+
+
+ Import match search view
+ base_import.match
+
+
+
+
+
+
+
+
-
-
-
-
-
-
- Import match tree view
- base_import.match
-
-
-
-
-
-
-
-
-
- Import match search view
- base_import.match
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+