mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
Avoid UnicodeEncodeError. (#544)
* Fix wrong README format. * [FIX][base_import_match] Avoid UnicodeEncodeError. When the model or field you chose was translated and had some non-ascii character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 15: ordinal not in range(128)`. Now, using unicode strings, that won't happen again. * Do not require a hidden field. * Further unicode protection, add ondelete clause.
This commit is contained in:
committed by
Jesus Ramoneda
parent
57a82e554a
commit
82bb1e33a3
@@ -29,18 +29,18 @@ After installing this module, the import logic will be changed to:
|
|||||||
- Discard the rules that require fields you are not 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.
|
- 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
|
- Skip the rule if it requires a special condition that is not
|
||||||
satisfied.
|
satisfied.
|
||||||
- If one match is found:
|
- If one match is found:
|
||||||
|
|
||||||
- Stop traversing the rest of valid rules.
|
- Stop traversing the rest of valid rules.
|
||||||
- **Update** that record.
|
- **Update** that record.
|
||||||
- If zero or multiple matches are found:
|
- If zero or multiple matches are found:
|
||||||
|
|
||||||
- Continue with the next rule.
|
- Continue with the next rule.
|
||||||
- If all rules are exhausted and no single match is found:
|
- If all rules are exhausted and no single match is found:
|
||||||
|
|
||||||
- **Create** a new record.
|
- **Create** a new record.
|
||||||
- If there are no match rules for your model:
|
- If there are no match rules for your model:
|
||||||
|
|
||||||
- **Create** a new record.
|
- **Create** a new record.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Base Import Match",
|
"name": "Base Import Match",
|
||||||
"summary": "Try to avoid duplicates before importing",
|
"summary": "Try to avoid duplicates before importing",
|
||||||
"version": "8.0.1.0.0",
|
"version": "8.0.1.0.1",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
"website": "https://grupoesoc.es",
|
"website": "https://grupoesoc.es",
|
||||||
"author": "Grupo ESOC Ingeniería de Servicios, "
|
"author": "Grupo ESOC Ingeniería de Servicios, "
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from openerp import api, fields, models
|
from openerp import api, fields, models
|
||||||
from openerp import SUPERUSER_ID # TODO remove in v10
|
from openerp import SUPERUSER_ID # TODO remove in v10
|
||||||
|
|
||||||
@@ -83,14 +82,14 @@ class BaseImportMatch(models.Model):
|
|||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
"""Automatic self-descriptive name for the setting records."""
|
"""Automatic self-descriptive name for the setting records."""
|
||||||
for s in self:
|
for s in self:
|
||||||
s.name = "{}: {}".format(
|
s.name = u"{}: {}".format(
|
||||||
s.model_id.display_name,
|
s.model_id.display_name,
|
||||||
" + ".join(
|
" + ".join(
|
||||||
s.field_ids.mapped(
|
s.field_ids.mapped(
|
||||||
lambda r: (
|
lambda r: (
|
||||||
str(r.field_id.name) +
|
(u"{} ({})" if r.conditional else u"{}").format(
|
||||||
(" ({})".format(r.imported_value)
|
r.field_id.name,
|
||||||
if r.conditional else "")))))
|
r.imported_value)))))
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _match_find(self, model, converted_row, imported_row):
|
def _match_find(self, model, converted_row, imported_row):
|
||||||
@@ -279,6 +278,7 @@ class BaseImportMatchField(models.Model):
|
|||||||
match_id = fields.Many2one(
|
match_id = fields.Many2one(
|
||||||
comodel_name="base_import.match",
|
comodel_name="base_import.match",
|
||||||
string="Match",
|
string="Match",
|
||||||
|
ondelete="cascade",
|
||||||
required=True)
|
required=True)
|
||||||
model_id = fields.Many2one(
|
model_id = fields.Many2one(
|
||||||
related="match_id.model_id")
|
related="match_id.model_id")
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
<tree editable="bottom">
|
<tree editable="bottom">
|
||||||
<field name="field_id"
|
<field name="field_id"
|
||||||
options="{'no_create': True}"/>
|
options="{'no_create': True}"/>
|
||||||
<field name="match_id" invisible="True"/>
|
<field name="match_id"
|
||||||
|
invisible="True"
|
||||||
|
required="False"/>
|
||||||
<field name="model_id" invisible="True"/>
|
<field name="model_id" invisible="True"/>
|
||||||
<field name="conditional"/>
|
<field name="conditional"/>
|
||||||
<field
|
<field
|
||||||
|
|||||||
Reference in New Issue
Block a user