diff options
| author | Raphael Collet <rco@odoo.com> | 2019-08-27 13:54:14 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-08-27 14:25:44 +0000 |
| commit | c3ebc0b9872c86ae2011bd71ae5d3b3ea97ad1ab (patch) | |
| tree | 9a21593bcbcf0930b0b2204bdcc376deaf0f8b91 | |
| parent | a893a51771ff0ac669d6b8e0df8f5f709441acd0 (diff) | |
[FIX] fields: do not update translations for no record
When a translated field is set on new records, one should not update
translations in 'ir.translation'.
closes odoo/odoo#36138
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
| -rw-r--r-- | odoo/fields.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index f05fccd8a06..cea568421db 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1418,6 +1418,10 @@ class _String(Field): if not self.store: return records + real_recs = records.filtered('id') + if not real_recs._ids: + return records + update_column = True update_trans = False single_lang = len(records.env['res.lang'].get_installed()) <= 1 @@ -1438,25 +1442,22 @@ class _String(Field): # update towrite if modifying the source if update_column: towrite = records.env.all.towrite[self.model_name] - real_record_ids = [r.id for r in records if r.id] - for rid in real_record_ids: + for rid in real_recs._ids: # cache_value is already in database format towrite[rid][self.name] = cache_value - if self.translate is True and real_record_ids: + if self.translate is True: tname = "%s,%s" % (records._name, self.name) - records.env['ir.translation']._set_source(tname, real_record_ids, value) + records.env['ir.translation']._set_source(tname, real_recs._ids, value) if update_trans: if callable(self.translate): # the source value of self has been updated, synchronize # translated terms when possible - real_recs = records.filtered('id') - records.env['ir.translation']._sync_terms_translations(self, records) + records.env['ir.translation']._sync_terms_translations(self, real_recs) else: # update translations value = self.convert_to_column(value, records) - real_recs = records.filtered('id') source_recs = real_recs.with_context(lang='en_US') source_value = first(source_recs)[self.name] if not source_value: @@ -1471,10 +1472,10 @@ class _String(Field): lang=lang, type='model', state='translated', - res_id=res_id) for res_id in real_recs.ids]) + res_id=res_id) for res_id in real_recs._ids]) else: records.env['ir.translation']._set_ids( - tname, 'model', lang, real_recs.ids, value, source_value, + tname, 'model', lang, real_recs._ids, value, source_value, ) return records |
