diff --git a/odoo/addons/test_new_api/models/test_new_api.py b/odoo/addons/test_new_api/models/test_new_api.py index 22234f298f3..13485aa9aee 100644 --- a/odoo/addons/test_new_api/models/test_new_api.py +++ b/odoo/addons/test_new_api/models/test_new_api.py @@ -149,12 +149,19 @@ class Message(models.Model): label = fields.Char(translate=True) priority = fields.Integer() active = fields.Boolean(default=True) + has_important_sibling = fields.Boolean(compute='_compute_has_important_sibling') attributes = fields.Properties( string='Properties', definition='discussion.attributes_definition', ) + @api.depends('discussion.messages.important') + def _compute_has_important_sibling(self): + for record in self: + siblings = record.discussion.messages - record + record.has_important_sibling = any(siblings.mapped('important')) + @api.constrains('author', 'discussion') def _check_author(self): for message in self.with_context(active_test=False): diff --git a/odoo/addons/test_new_api/tests/test_onchange.py b/odoo/addons/test_new_api/tests/test_onchange.py index 50674a434bd..2fdd9ba7c43 100644 --- a/odoo/addons/test_new_api/tests/test_onchange.py +++ b/odoo/addons/test_new_api/tests/test_onchange.py @@ -1236,3 +1236,19 @@ class TestComputeOnchange2(common.TransactionCase): ) with Form(record) as form: form.precision_rounding = 0.0001 + + def test_new_one2many_on_existing_record(self): + discussion = self.env['test_new_api.discussion'].create({ + 'messages': [Command.create({'body': 'Required Body', 'important': True})], + 'name': 'Required field', + 'participants': [Command.set(self.env.user.ids)], + }) + + with Form(discussion, 'test_new_api.discussion_form_2') as discussion_form: + self.assertEqual(len(discussion_form.messages), 1) + with discussion_form.messages.new() as message_form: + # this actually checks that during the onchange, the new message + # has access to its sibling messages through the discussion + self.assertEqual(message_form.has_important_sibling, True) + message_form.body = 'Required Body' + self.assertEqual(len(discussion_form.messages), 2) diff --git a/odoo/addons/test_new_api/tests/test_views.py b/odoo/addons/test_new_api/tests/test_views.py index 51cb4705bb9..f45258700ef 100644 --- a/odoo/addons/test_new_api/tests/test_views.py +++ b/odoo/addons/test_new_api/tests/test_views.py @@ -10,7 +10,7 @@ class TestDefaultView(common.TransactionCase): def test_default_form_view(self): self.assertEqual( etree.tostring(self.env['test_new_api.message']._get_default_form_view()), - b'
' + b'' ) self.assertEqual( etree.tostring(self.env['test_new_api.creativework.edition']._get_default_form_view()), diff --git a/odoo/addons/test_new_api/views/test_new_api_views.xml b/odoo/addons/test_new_api/views/test_new_api_views.xml index 88d45351ce5..2acac075393 100644 --- a/odoo/addons/test_new_api/views/test_new_api_views.xml +++ b/odoo/addons/test_new_api/views/test_new_api_views.xml @@ -128,6 +128,7 @@