diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-02-26 16:39:30 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-02-26 16:39:30 +0100 |
| commit | ff9c9341d6ed4e9ab18a0aa02e79441999d658f1 (patch) | |
| tree | 47ffd01e071d3783cff6013cfc4b6c3d8e47a841 /odoo/addons/test_testing_utilities | |
| parent | bc84fdf71b15ad419f8693861aea682ee751f85c (diff) | |
| parent | fcb972db9dc778eeaf7d6b6ba3638c78d93998ad (diff) | |
[MERGE] forward port branch saas-12.2 up to fcb972db9dc
Diffstat (limited to 'odoo/addons/test_testing_utilities')
| -rw-r--r-- | odoo/addons/test_testing_utilities/menu.xml | 13 | ||||
| -rw-r--r-- | odoo/addons/test_testing_utilities/models.py | 7 | ||||
| -rw-r--r-- | odoo/addons/test_testing_utilities/tests/test_form_impl.py | 26 |
3 files changed, 29 insertions, 17 deletions
diff --git a/odoo/addons/test_testing_utilities/menu.xml b/odoo/addons/test_testing_utilities/menu.xml index 99e409708c2..3ca18ef2a50 100644 --- a/odoo/addons/test_testing_utilities/menu.xml +++ b/odoo/addons/test_testing_utilities/menu.xml @@ -10,6 +10,17 @@ name="O2M onchange test thing" action="action_test_o2m_onchange"/> + <record id="action_test_m2o_onchange" model="ir.actions.act_window"> + <field name="name">test_default_and_onchange</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">test_testing_utilities.d</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_m2o" parent="base.menu_tests" + name="test_default_and_onchange" + action="action_test_m2o_onchange"/> + <record id="o2m_parent" model="ir.ui.view"> <field name="name">Parent External Form</field> <field name="priority">1</field> @@ -98,7 +109,7 @@ <field name="arch" type="xml"> <form> <field name="f1"/> - <field name="f2" attrs="{'readonly': [['f1', '=', 63], ['f3', '=', 5]]}"/> + <field name="f2" attrs="{'readonly': [['f1', '=', '63'], ['f3', '=', 5]]}"/> <field name="f3"/> <field name="f4"/> <field name="f5" readonly="1"/> diff --git a/odoo/addons/test_testing_utilities/models.py b/odoo/addons/test_testing_utilities/models.py index 98a9fea7e7f..324b8d62c9f 100644 --- a/odoo/addons/test_testing_utilities/models.py +++ b/odoo/addons/test_testing_utilities/models.py @@ -6,7 +6,7 @@ class A(models.Model): _name = 'test_testing_utilities.a' _description = 'Testing Utilities A' - f1 = fields.Integer(required=True) + f1 = fields.Char(required=True) f2 = fields.Integer(default=42) f3 = fields.Integer() f4 = fields.Integer(compute='_compute_f4') @@ -22,7 +22,7 @@ class A(models.Model): @api.depends('f1', 'f2') def _compute_f4(self): for r in self: - r.f4 = r.f2 / (r.f1 or 1) + r.f4 = r.f2 / (int(r.f1) or 1) class B(models.Model): _name = 'test_testing_utilities.readonly' @@ -71,7 +71,7 @@ class M2Onchange(models.Model): def _on_change_f2(self): self.f = self.env['test_testing_utilities.m2o'].search([ ('name', 'ilike', self.f2), - ], limit=1) + ], limit=1) if self.f2 else False class M2MChange(models.Model): _name = 'test_testing_utilities.e' @@ -154,7 +154,6 @@ class O2MSub(models.Model): @api.onchange('has_parent') def _onchange_has_parent(self): - self.has_parent = bool(self.parent_id) if self.has_parent: self.value = self.parent_id.value diff --git a/odoo/addons/test_testing_utilities/tests/test_form_impl.py b/odoo/addons/test_testing_utilities/tests/test_form_impl.py index e2f0d0d89d3..344ae62f4d2 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -24,7 +24,7 @@ class TestBasic(TransactionCase): self.assertEqual(f.f3, 21) self.assertEqual(f.f4, 42) - f.f1 = 4 + f.f1 = '4' self.assertEqual(f.f2, 42) self.assertEqual(f.f3, 21) self.assertEqual(f.f4, 10) @@ -36,7 +36,7 @@ class TestBasic(TransactionCase): r = f.save() self.assertEqual( (r.f1, r.f2, r.f3, r.f4), - (4, 8, 4, 2), + ('4', 8, 4, 2), ) def test_required(self): @@ -45,12 +45,12 @@ class TestBasic(TransactionCase): with self.assertRaisesRegexp(AssertionError, 'f1 is a required field'): f.save() # set f1 and unset f2 => should work - f.f1 = 1 + f.f1 = '1' f.f2 = False r = f.save() self.assertEqual( (r.f1, r.f2, r.f3, r.f4), - (1, 0, 0, 0) + ('1', 0, 0, 0) ) def test_readonly(self): @@ -61,7 +61,7 @@ class TestBasic(TransactionCase): f = Form(self.env['test_testing_utilities.readonly']) with self.assertRaises(AssertionError): - f.f1 = 5 + f.f1 = '5' with self.assertRaises(AssertionError): f.f2 = 42 @@ -70,7 +70,7 @@ class TestBasic(TransactionCase): """ f = Form(self.env['test_testing_utilities.a'], view='test_testing_utilities.non_normalized_attrs') - f.f1 = 1 + f.f1 = '1' f.f2 = 987 self.assertEqual(f.f5, 987) self.assertEqual(f.f6, 987) @@ -86,7 +86,7 @@ class TestBasic(TransactionCase): # not readonly yet, should work f.f2 = 5 # make f2 readonly - f.f1 = 63 + f.f1 = '63' f.f3 = 5 with self.assertRaises(AssertionError): f.f2 = 6 @@ -101,9 +101,9 @@ class TestM2O(TransactionCase): f = Form(self.env['test_testing_utilities.d']) - self.assertEqual( - f.f, a, - "The default value for the m2o should be the first Sub record" + self.assertFalse( + f.f, + "The default value gets overridden by the onchange" ) f.f2 = "B" self.assertEqual( @@ -271,6 +271,7 @@ class TestO2M(TransactionCase): [get(s) for s in r.subs], [("2", 2, 2), ("2", 2, 2)] ) + self.assertEqual(r.v, 5) with Form(r, view='test_testing_utilities.o2m_parent') as f: with f.subs.new() as sub: @@ -286,6 +287,7 @@ class TestO2M(TransactionCase): [get(s) for s in r.subs], [("2", 2, 2), ("5", 5, 5), ("2", 2, 2)] ) + self.assertEqual(r.v, 10) with Form(r, view='test_testing_utilities.o2m_parent') as f, \ f.subs.edit(index=0) as sub,\ @@ -439,12 +441,12 @@ class TestEdition(TransactionCase): """ def test_trivial(self): r = self.env['test_testing_utilities.a'].create({ - 'f1': 5, + 'f1': '5', }) with Form(r) as f: self.assertEqual(f.id, r.id) - self.assertEqual(f.f1, 5) + self.assertEqual(f.f1, '5') self.assertEqual(f.f4, 8) f.f2 = 5 |
