diff options
| author | Adrian Torres <adt@odoo.com> | 2020-11-25 08:47:23 +0000 |
|---|---|---|
| committer | Adrian Torres <adt@odoo.com> | 2020-11-25 14:24:03 +0000 |
| commit | 76bf9dc94165c79be873a8864bfdb50a0a636084 (patch) | |
| tree | d2b51c6aa7b26c2e6349779b1b8ad169fb3d518e | |
| parent | c0e082ee1fba7cecc711f724974d79ed65bab29b (diff) | |
[FIX] core: allow writing to delegated m2o fields on records
Before this commit, it was impossible to write to a delegated m2o field
if the length of the recordset was greater than 1.
The reason was because the special case for delegated fields inside
fields.Many2one.convert_to_cache would check for `record.id` which is a
bit misleading, since record can be greater than one.
The solution is to check whether any of the records are real records
instead, as if all of the records are NewRecords, then the parent is a
NewRecord too.
Fixes #62069
closes odoo/odoo#62321
X-original-commit: fd211958a28d886626552ec976253f9f9267dacf
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
| -rw-r--r-- | odoo/addons/test_inherits/tests/test_inherits.py | 10 | ||||
| -rw-r--r-- | odoo/fields.py | 4 |
2 files changed, 12 insertions, 2 deletions
diff --git a/odoo/addons/test_inherits/tests/test_inherits.py b/odoo/addons/test_inherits/tests/test_inherits.py index 9822ab19020..614b7f08852 100644 --- a/odoo/addons/test_inherits/tests/test_inherits.py +++ b/odoo/addons/test_inherits/tests/test_inherits.py @@ -138,3 +138,13 @@ class test_inherits(common.TransactionCase): self.assertIn('lang', Unit.display_name.depends_context) self.assertIn('lang', Box.display_name.depends_context) self.assertIn('lang', Pallet.display_name.depends_context) + + def test_multi_write_m2o_inherits(self): + """Verify that an inherits m2o field can be written to in batch""" + unit_foo = self.env['test.unit'].create({'name': 'foo'}) + boxes = self.env['test.box'].create([{'unit_id': unit_foo.id}] * 5) + + unit_bar = self.env['test.unit'].create({'name': 'bar'}) + boxes.unit_id = unit_bar + + self.assertEqual(boxes.mapped('unit_id.name'), ['bar']) diff --git a/odoo/fields.py b/odoo/fields.py index 1aec507f21a..e601dfc50d6 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2597,8 +2597,8 @@ class Many2one(_Relational): else: id_ = None - if self.delegate and record and not record.id: - # the parent record of a new record is a new record + if self.delegate and record and not any(record._ids): + # if all records are new, then so is the parent id_ = id_ and NewId(id_) return id_ |
