当前位置: 首页>>代码示例>>Python>>正文


Python common.Form类代码示例

本文整理汇总了Python中odoo.tests.common.Form的典型用法代码示例。如果您正苦于以下问题:Python Form类的具体用法?Python Form怎么用?Python Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_invoice_from_file

 def _create_invoice_from_file(self, attachment):
     self = self.with_context(default_journal_id=self.journal_id.id)
     invoice_form = Form(self.env['account.invoice'], view='account.invoice_supplier_form')
     invoice = invoice_form.save()
     attachment.write({'res_model': 'account.invoice', 'res_id': invoice.id})
     invoice.message_post(attachment_ids=[attachment.id])
     return invoice
开发者ID:Vauxoo,项目名称:odoo,代码行数:7,代码来源:account_invoice_import.py

示例2: test_defaults

    def test_defaults(self):
        """
        Checks that we can load a default form view and perform trivial
        default_get & onchanges & computations
        """
        f = Form(self.env['test_testing_utilities.a'])
        self.assertEqual(f.id, False, "check that our record is not in db (yet)")

        self.assertEqual(f.f2, 42)
        self.assertEqual(f.f3, 21)
        self.assertEqual(f.f4, 42)

        f.f1 = 4
        self.assertEqual(f.f2, 42)
        self.assertEqual(f.f3, 21)
        self.assertEqual(f.f4, 10)

        f.f2 = 8
        self.assertEqual(f.f3, 4)
        self.assertEqual(f.f4, 2)

        r = f.save()
        self.assertEqual(
            (r.f1, r.f2, r.f3, r.f4),
            (4, 8, 4, 2),
        )
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:26,代码来源:test_form_impl.py

示例3: test_o2m_editable_list

    def test_o2m_editable_list(self):
        """ Tests the o2m proxy when the list view is editable rather than
        delegating to a separate form view
        """
        f = Form(self.env['test_testing_utilities.parent'], view='test_testing_utilities.o2m_parent_ed')
        custom_tree = self.env.ref('test_testing_utilities.editable_external').id

        subs_field = f._view['fields']['subs']
        tree_view = subs_field['views']['tree']
        self.assertEqual(tree_view['type'], 'tree')
        self.assertEqual(
            tree_view['view_id'], custom_tree,
            'check that the tree view is the one referenced by tree_view_ref'
        )
        self.assertIs(subs_field['views']['edition'], tree_view, "check that the edition view is the tree view")
        self.assertEqual(
            subs_field['views']['edition']['view_id'],
            custom_tree
        )

        with f.subs.new() as s:
            s.value = 1
        with f.subs.new() as s:
            s.value = 3
        with f.subs.new() as s:
            s.value = 7

        r = f.save()

        self.assertEqual(r.v, 12)
        self.assertEqual(
            [get(s) for s in r.subs],
            [('1', 1, 1), ('3', 3, 3), ('7', 7, 7)]
        )
开发者ID:Tecnativa,项目名称:odoo,代码行数:34,代码来源:test_form_impl.py

示例4: create_payment

 def create_payment(self, invoices):
     payment_register = Form(self.env['account.payment'].with_context(active_model='account.invoice', active_ids=invoices.ids))
     payment_register.payment_date = time.strftime('%Y') + '-07-15'
     payment_register.journal_id = self.bank_journal
     payment_register.payment_method_id = self.payment_method_check
     payment = payment_register.save()
     payment.post()
     return payment
开发者ID:brain-tec,项目名称:odoo,代码行数:8,代码来源:test_print_check.py

示例5: test_readonly

    def test_readonly(self):
        """
        Checks that fields with readonly modifiers (marked as readonly or
        computed w/o set) raise an error when set.
        """
        f = Form(self.env['test_testing_utilities.readonly'])

        with self.assertRaises(AssertionError):
            f.f1 = 5
        with self.assertRaises(AssertionError):
            f.f2 = 42
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:11,代码来源:test_form_impl.py

示例6: test_readonly_save

    def test_readonly_save(self):
        """ Should not save readonly fields unless they're force_save
        """
        f = Form(self.env['test_testing_utilities.a'], view='test_testing_utilities.non_normalized_attrs')

        f.f1 = '1'
        f.f2 = 987
        self.assertEqual(f.f5, 987)
        self.assertEqual(f.f6, 987)
        r = f.save()
        self.assertEqual(r.f5, 0)
        self.assertEqual(r.f6, 987)
开发者ID:Tecnativa,项目名称:odoo,代码行数:12,代码来源:test_form_impl.py

示例7: test_department_leave

 def test_department_leave(self):
     """ Create a department leave """
     self.employee_hrmanager.write({'department_id': self.hr_dept.id})
     self.assertFalse(self.env['hr.leave'].search([('employee_id', 'in', self.hr_dept.member_ids.ids)]))
     leave_form = Form(self.env['hr.leave'].sudo(self.user_hrmanager), view='hr_holidays.hr_leave_view_form_manager')
     leave_form.holiday_status_id = self.holidays_type_1
     leave_form.holiday_type = 'department'
     leave_form.department_id = self.hr_dept
     leave = leave_form.save()
     leave.action_approve()
     member_ids = self.hr_dept.member_ids.ids
     self.assertEqual(self.env['hr.leave'].search_count([('employee_id', 'in', member_ids)]), len(member_ids), "Leave should be created for members of department")
开发者ID:Vauxoo,项目名称:odoo,代码行数:12,代码来源:test_leave_requests.py

示例8: test_attrs

    def test_attrs(self):
        """ Checks that attrs/modifiers with non-normalized domains work
        """
        f = Form(self.env['test_testing_utilities.a'], view='test_testing_utilities.non_normalized_attrs')

        # not readonly yet, should work
        f.f2 = 5
        # make f2 readonly
        f.f1 = 63
        f.f3 = 5
        with self.assertRaises(AssertionError):
            f.f2 = 6
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:12,代码来源:test_form_impl.py

示例9: test_onchange_taxes_2

    def test_onchange_taxes_2(self):
        '''
        Test the amount of tax account.move.line is adapted when editing the account.move.line amount.
        This test uses the following scenario:
            - Create manually a debit line of 1000 having a tax.
            - Assume a line containing the tax amount is created automatically.
            - Set the debit amount to 2000 in the first created line.
            - Assume the line containing the tax amount has been updated automatically.
            - Create manually a credit line to balance the two previous lines.
            - Save the move.

        tax = 10%

        Name            | Debit     | Credit    | Tax_ids       | Tax_line_id's name
        ----------------|-----------|-----------|---------------|-------------------
        debit_line_1    | 2000      |           | tax           |
        tax_line        | 200       |           |               | tax_line
        debit_line_1    |           | 2200      |               |
        '''
        move_form = Form(self.env['account.move'], view='account.view_move_form')
        move_form.ref = 'azerty'
        move_form.journal_id = self.journal

        # Create a new account.move.line with debit amount.
        with move_form.line_ids.new() as debit_line:
            debit_line.name = 'debit_line_1'
            debit_line.account_id = self.account
            debit_line.debit = 1000
            debit_line.tax_ids.clear()
            debit_line.tax_ids.add(self.percent_tax)

            self.assertTrue(debit_line.recompute_tax_line)

            debit_line.debit = 2000

            self.assertTrue(debit_line.recompute_tax_line)

        # Create a third account.move.line with credit amount.
        with move_form.line_ids.new() as credit_line:
            credit_line.name = 'credit_line_1'
            credit_line.account_id = self.account
            credit_line.credit = 2200

        move = move_form.save()

        self.check_complete_move(move, [
            ['debit_line_1',    2000,   0,      [self.percent_tax.id],  None],
            ['tax_line',        200,    0,      None,                   self.percent_tax.id],
            ['credit_line_1',   0,      2200,   None,                   None],
        ], fields_name=['name', 'debit', 'credit', 'tax_ids', 'tax_line_id'])
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:50,代码来源:test_account_move_taxes_edition.py

示例10: test_o2m_default

    def test_o2m_default(self):
        """ Tests that default_get can return defaults for the o2m
        """
        f = Form(self.env['test_testing_utilities.default'])

        with f.subs.edit(index=0) as s:
            self.assertEqual(s.v, 5)
            self.assertEqual(s.value, False)

        r = f.save()

        self.assertEqual(
            [get(s) for s in r.subs],
            [("5", 2, 5)]
        )
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:15,代码来源:test_form_impl.py

示例11: test_m2m_changed

    def test_m2m_changed(self):
        Sub = self.env['test_testing_utilities.sub2']
        a = Sub.create({'name': 'a'})
        b = Sub.create({'name': 'b'})
        c = Sub.create({'name': 'c'})
        d = Sub.create({'name': 'd'})

        f = Form(self.env['test_testing_utilities.f'])
        # check default_get
        self.assertEqual(f.m2m[:], a | b)

        f.m2o = c
        self.assertEqual(f.m2m[:], a | b | c)

        f.m2o = d
        self.assertEqual(f.m2m[:], a | b | c | d)
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:16,代码来源:test_form_impl.py

示例12: test_o2m_inline

    def test_o2m_inline(self):
        """ Tests the o2m proxy when the list and form views are provided
        inline rather than fetched separately
        """
        f = Form(self.env['test_testing_utilities.parent'], view='test_testing_utilities.o2m_parent_inline')

        with f.subs.new() as s:
            s.value = 42

        r = f.save()

        self.assertEqual(
            [get(s) for s in r.subs],
            [("0", 42, 0)],
            "should not have set v (and thus not name)"
        )
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:16,代码来源:test_form_impl.py

示例13: test_add

    def test_add(self):
        Sub = self.env['test_testing_utilities.sub2']
        f = Form(self.env['test_testing_utilities.e'])

        r1 = Sub.create({'name': "Item"})
        r2 = Sub.create({'name': "Item2"})

        f.m2m.add(r1)
        f.m2m.add(r2)

        r = f.save()

        self.assertEqual(
            r.m2m,
            r1 | r2
        )
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:16,代码来源:test_form_impl.py

示例14: test_remove_by_index

    def test_remove_by_index(self):
        Sub = self.env['test_testing_utilities.sub2']
        f = Form(self.env['test_testing_utilities.e'])

        r1 = Sub.create({'name': "Item"})
        r2 = Sub.create({'name': "Item2"})

        f.m2m.add(r1)
        f.m2m.add(r2)
        f.m2m.remove(index=0)

        r = f.save()

        self.assertEqual(
            r.m2m,
            r2
        )
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:17,代码来源:test_form_impl.py

示例15: test_m2m_readonly

    def test_m2m_readonly(self):
        Sub = self.env['test_testing_utilities.sub3']
        a = Sub.create({'name': 'a'})
        b = Sub.create({'name': 'b'})
        r = self.env['test_testing_utilities.g'].create({
            'm2m': [(6, 0, a.ids)]
        })

        f = Form(r)

        with self.assertRaises(AssertionError):
            f.m2m.add(b)
        with self.assertRaises(AssertionError):
            f.m2m.remove(id=a.id)

        f.save()
        self.assertEqual(r.m2m, a)
开发者ID:PieterPaulussen,项目名称:odoo,代码行数:17,代码来源:test_form_impl.py


注:本文中的odoo.tests.common.Form类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。