diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-02-27 10:15:25 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-03-10 11:15:09 +0000 |
| commit | c6003af73409e2cd124f641fb7714fefa9dc8b01 (patch) | |
| tree | 751065a124cebdf7c94f2b9b3ce50235beb529bf /addons/event/tests | |
| parent | 5e4efef3ca3f2e9f02ec40c746c0d43aa3e97b79 (diff) | |
[IMP] event: set an explicit onchange on partner_id of registration
RATIONALE
Manual onchange is necessary because you spot an issue (or customer complains).
Automatic update through computed feild is only there to try to add missing
pieces of information but cannot decide which is the correct field value to keep.
SPECIFICATIONS
Keep an explicit onchange on partner_id. Rationale : if user explicitly
changes the partner in interface, he wants to update the whole customer
information. If partner_id is updated in code (e.g. updating your personal
information after registeration in website_event_sale) fields with a value
should not be reset as we do not know which one is the correct one.
How it should behave as following
* computed fields based on partner_id should only update missing
information. Indeed automated code cannot decide which information
is more accurate;
* interface should allow to update all customer related information
at once. We consider event users really want to update all fields
Tests are added to ensure behavior is not modified without notice.
LINKS
Task ID 2089156
Community PR odoo/odoo#42911
Diffstat (limited to 'addons/event/tests')
| -rw-r--r-- | addons/event/tests/test_event_flow.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/addons/event/tests/test_event_flow.py b/addons/event/tests/test_event_flow.py index 1ec9208e1b3..ff114bb4196 100644 --- a/addons/event/tests/test_event_flow.py +++ b/addons/event/tests/test_event_flow.py @@ -7,9 +7,69 @@ from dateutil.relativedelta import relativedelta from odoo.addons.event.tests.common import TestEventCommon from odoo.exceptions import ValidationError +from odoo.tests.common import Form from odoo.tools import mute_logger +class TestEventUI(TestEventCommon): + + def test_event_registration_partner_sync(self): + """ Ensure onchange on partner_id is kept for interface, not for computed + fields. """ + registration_form = Form(self.env['event.registration'].with_context( + default_name='WrongName', + default_event_id=self.event_0.id + )) + self.assertEqual(registration_form.event_id, self.event_0) + self.assertEqual(registration_form.name, 'WrongName') + self.assertFalse(registration_form.email) + self.assertFalse(registration_form.phone) + self.assertFalse(registration_form.mobile) + + # trigger onchange + registration_form.partner_id = self.customer + self.assertEqual(registration_form.name, self.customer.name) + self.assertEqual(registration_form.email, self.customer.email) + self.assertEqual(registration_form.phone, self.customer.phone) + self.assertEqual(registration_form.mobile, self.customer.mobile) + + # save, check record matches Form values + registration = registration_form.save() + self.assertEqual(registration.partner_id, self.customer) + self.assertEqual(registration.name, self.customer.name) + self.assertEqual(registration.email, self.customer.email) + self.assertEqual(registration.phone, self.customer.phone) + self.assertEqual(registration.mobile, self.customer.mobile) + + # allow writing on some fields independently from customer config + registration.write({'phone': False, 'mobile': False}) + self.assertFalse(registration.phone) + self.assertFalse(registration.mobile) + + # reset partner should not reset other fields + registration.write({'partner_id': False}) + self.assertEqual(registration.partner_id, self.env['res.partner']) + self.assertEqual(registration.name, self.customer.name) + self.assertEqual(registration.email, self.customer.email) + self.assertFalse(registration.phone) + self.assertFalse(registration.mobile) + + # update to a new partner not through UI -> update only void feilds + customer2 = self.env['res.partner'].create({ + 'name': 'Constantin Customer 2', + 'email': 'constantin2@test.example.com', + 'country_id': self.env.ref('base.be').id, + 'phone': '0456987654', + 'mobile': '0456654321', + }) + registration.write({'partner_id': customer2.id}) + self.assertEqual(registration.partner_id, customer2) + self.assertEqual(registration.name, self.customer.name) + self.assertEqual(registration.email, self.customer.email) + self.assertEqual(registration.phone, customer2.phone) + self.assertEqual(registration.mobile, customer2.mobile) + + class TestEventFlow(TestEventCommon): @mute_logger('odoo.addons.base.models.ir_model', 'odoo.models') |
