mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_import_match: black, isort, prettier
This commit is contained in:
committed by
Augusto Weiss
parent
0480ef2a5e
commit
d45407817b
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user