diff options
| author | Raphael Collet <rco@odoo.com> | 2020-01-08 10:53:51 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-01-16 15:11:57 +0000 |
| commit | a8ea77a771730942909a9d22ed9151cd857be0d6 (patch) | |
| tree | 3177b82a4f14f786b27cec7a5f4c17c9cadb12d1 | |
| parent | 170eaa4743562bdb54a569b492aea632472bd525 (diff) | |
[FIX] base: browse(record) in company-dependent field value
The faulty code modifies a dictionary in-place to apply a formatting
function to each value. In this case, the formatting is `browse`, and
the issue occurs when `ids` contain duplicates:
for id in ids:
result[id] = format(result.get(id, default))
Fix it by returning a new dictionary based on `result`.
X-original-commit: bd4565e227c7196604af9c5c51ce136a2beac088
| -rw-r--r-- | odoo/addons/base/models/ir_property.py | 11 | ||||
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 6 |
2 files changed, 12 insertions, 5 deletions
diff --git a/odoo/addons/base/models/ir_property.py b/odoo/addons/base/models/ir_property.py index a303e6ab4f6..18c8424c952 100644 --- a/odoo/addons/base/models/ir_property.py +++ b/odoo/addons/base/models/ir_property.py @@ -302,11 +302,12 @@ class Property(models.Model): cr.execute(query, params + [sub_refs]) result.update(cr.fetchall()) - # remove default value, add missing values, and format them - default = result.pop(None, None) - for id in ids: - result[id] = clean(result.get(id, default)) - return result + # determine all values and format them + default = result.get(None, None) + return { + id: clean(result.get(id, default)) + for id in ids + } @api.model def set_multi(self, name, model, values, default_value=None): diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index d476f6b843d..e79e3c306fa 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -998,6 +998,12 @@ class TestFields(TransactionCaseWithUserDemo): self.assertEqual(record.with_user(user1).tag_id, tag2) self.assertEqual(record.with_user(user2).tag_id, tag0) + # regression: duplicated records caused values to be browse(browse(id)) + recs = record.create({}) + record + record + recs.invalidate_cache() + for rec in recs.with_user(user0): + self.assertIsInstance(rec.tag_id.id, int) + # unlink value of a many2one (tag2), and check again tag2.unlink() self.assertEqual(record.with_user(user0).tag_id, tag1) |
