コード例 #1
0
    def test_onchange(self):
        # check computations of 'bar' (readonly) and 'baz' (editable)
        form = common.Form(self.env['test_new_api.compute.onchange'])
        self.assertEqual(form.bar, "r")
        self.assertEqual(form.baz, False)
        form.active = True
        self.assertEqual(form.bar, "r")
        self.assertEqual(form.baz, "z")
        form.foo = "foo1"
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "foo1z")
        form.baz = "baz2"
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "baz2")
        form.active = False
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "baz2")
        form.foo = "foo3"
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "baz2")
        form.active = True
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "foo3z")

        with form.line_ids.new() as line:
            # check computation of 'bar' (readonly)
            self.assertEqual(line.foo, False)
            self.assertEqual(line.bar, "r")
            line.foo = "foo"
            self.assertEqual(line.foo, "foo")
            self.assertEqual(line.bar, "foor")

        record = form.save()
        self.assertEqual(record.bar, "foo3r")
        self.assertEqual(record.baz, "foo3z")

        form = common.Form(record)
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "foo3z")
        form.foo = "foo4"
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "foo4z")
        form.baz = "baz5"
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "baz5")
        form.active = False
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "baz5")
        form.foo = "foo6"
        self.assertEqual(form.bar, "foo6r")
        self.assertEqual(form.baz, "baz5")
コード例 #2
0
 def test_onchange_default(self):
     form = common.Form(
         self.env['test_new_api.compute.onchange'].with_context(
             default_active=True,
             default_foo="foo",
             default_baz="baz",
         ))
     # 'baz' is computed editable, so when given a default value it should
     # 'not be recomputed, even if a dependency also has a default value
     self.assertEqual(form.foo, "foo")
     self.assertEqual(form.bar, "foor")
     self.assertEqual(form.baz, "baz")
コード例 #3
0
 def test_onchange_one2many_first(self):
     partner = self.env['res.partner'].create({
         'name':
         'X',
         'country_id':
         self.env.ref('base.be').id,
     })
     with common.Form(self.env['test_new_api.multi']) as form:
         form.partner = partner
         self.assertEqual(form.partner, partner)
         self.assertEqual(form.name, partner.name)
         with form.lines.new() as line:
             # the first onchange() must have computed partner
             self.assertEqual(line.partner, partner)
コード例 #4
0
    def test_company_check_no_access(self):
        """ Test that company_check validates correctly the companies on
        the different records, even if the use has no access to one of the
        records, example, a private address set by an onchange
        """

        user = self.env['res.users'].create({
            'name': 'My Classic User',
            'login': '******',
            'groups_id': [(6, 0, self.env.ref('base.group_user').ids)],
        })

        with common.Form(self.env['test_new_api.model_private_address_onchange'].with_user(user)) as form:
            form.name = 'My Classic Name'
            form.company_id = self.env.user.company_id
            with self.assertRaises(AccessError):
                form.address_id.name
            form.save()
コード例 #5
0
    def test_onchange_one2many(self):
        record = self.env['test_new_api.model_parent_m2o'].create({
            'name':
            'Family',
            'child_ids': [
                (0, 0, {
                    'name': 'W',
                    'cost': 10
                }),
                (0, 0, {
                    'name': 'X',
                    'cost': 10
                }),
                (0, 0, {
                    'name': 'Y'
                }),
                (0, 0, {
                    'name': 'Z'
                }),
            ],
        })
        record.flush()
        self.assertEqual(record.child_ids.mapped('name'), list('WXYZ'))
        self.assertEqual(record.cost, 22)

        # modifying a line should not recompute the cost on other lines
        with common.Form(record) as form:
            with form.child_ids.edit(1) as line:
                line.name = 'XXX'
            self.assertEqual(form.cost, 15)

            with form.child_ids.edit(1) as line:
                line.cost = 20
            self.assertEqual(form.cost, 32)

            with form.child_ids.edit(2) as line:
                line.cost = 30
            self.assertEqual(form.cost, 61)