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:
Jairo Llopis
2016-09-20 13:41:56 +02:00
committed by Radovan Skolnik
parent 62090284d9
commit 2d092b454d
4 changed files with 18 additions and 16 deletions

View File

@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# © 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).
from openerp import api, fields, models
from openerp import SUPERUSER_ID # TODO remove in v10
@@ -83,14 +82,14 @@ class BaseImportMatch(models.Model):
def _compute_name(self):
"""Automatic self-descriptive name for the setting records."""
for s in self:
s.name = "{}: {}".format(
s.name = u"{}: {}".format(
s.model_id.display_name,
" + ".join(
s.field_ids.mapped(
lambda r: (
str(r.field_id.name) +
(" ({})".format(r.imported_value)
if r.conditional else "")))))
(u"{} ({})" if r.conditional else u"{}").format(
r.field_id.name,
r.imported_value)))))
@api.model
def _match_find(self, model, converted_row, imported_row):
@@ -279,6 +278,7 @@ class BaseImportMatchField(models.Model):
match_id = fields.Many2one(
comodel_name="base_import.match",
string="Match",
ondelete="cascade",
required=True)
model_id = fields.Many2one(
related="match_id.model_id")