summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2021-02-05 10:32:49 +0000
committerRaphael Collet <rco@odoo.com>2021-02-05 17:28:22 +0000
commit4e444568df68c0e36c1ab7f2668270002e30747e (patch)
treeee8bf9751728363ad7c6dc0d7c32765329dcf3d5 /odoo
parentd8eaa852fa1fc154303f71554ee4411c6454426d (diff)
[FIX] core: writing on one2many field on new record
When using command "6" (SET), the one2many field's inverse was not assigned on the lines. closes odoo/odoo#65656 X-original-commit: 330b885c4fd8570429d1cc4b59db1be00c26507b Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py7
-rw-r--r--odoo/fields.py11
2 files changed, 14 insertions, 4 deletions
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 652ae349ae0..c8956245aa6 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1690,6 +1690,13 @@ class TestFields(TransactionCaseWithUserDemo):
self.assertFalse(new_move.line_ids.id)
self.assertEqual(new_move.line_ids.quantity, 2)
+ # assign line to new move without origin
+ new_move = move.new()
+ new_move.line_ids = line
+ self.assertFalse(new_move.line_ids.id)
+ self.assertEqual(new_move.line_ids._origin, line)
+ self.assertEqual(new_move.line_ids.move_id, new_move)
+
@mute_logger('odoo.addons.base.models.ir_model')
def test_41_new_related(self):
""" test the behavior of related fields starting on new records. """
diff --git a/odoo/fields.py b/odoo/fields.py
index f541ea008cd..126108fc12b 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -3303,11 +3303,14 @@ class One2many(_RelationalMulti):
browse([command[1]])[inverse] = False
elif command[0] == 4:
browse([command[1]])[inverse] = recs[-1]
- elif command[0] in (5, 6):
+ elif command[0] == 5:
+ cache.update(recs, self, itertools.repeat(()))
+ elif command[0] == 6:
# assign the given lines to the last record only
- cache.update(recs, self, [()] * len(recs))
- lines = comodel.browse(command[2] if command[0] == 6 else [])
- cache.set(recs[-1], self, lines._ids)
+ cache.update(recs, self, itertools.repeat(()))
+ last, lines = recs[-1], browse(command[2])
+ cache.set(last, self, lines._ids)
+ cache.update(lines, inverse_field, itertools.repeat(last.id))
else:
def link(record, lines):