Пример #1
0
    def test_o2m_remove(self):
        def commands():
            return [c[0] for c in f._values['line_ids']]
        f = Form(self.env['test_testing_utilities.onchange_count'])

        self.assertEqual(f.count, 0)
        self.assertEqual(len(f.line_ids), 0)

        f.count = 5
        self.assertEqual(f.count, 5)
        self.assertEqual(len(f.line_ids), 5)

        f.count = 2
        self.assertEqual(f.count, 2)
        self.assertEqual(len(f.line_ids), 2)

        f.count = 4

        r = f.save()

        previous = r.line_ids
        self.assertEqual(len(previous), 4)

        with Form(r) as f:
            f.count = 2
            self.assertEqual(commands(), [0, 0, 2, 2, 2, 2], "Should contain 2 creations and 4 deletions")
        self.assertEqual(len(r.line_ids), 2)

        with Form(r) as f:
            f.line_ids.remove(0)
            self.assertEqual(commands(), [2, 1])
            f.count = 1
            self.assertEqual(commands(), [0, 2, 2], "should contain 1 '0' command and 2 deletions")
        self.assertEqual(len(r.line_ids), 1)
Пример #2
0
    def test_basic_alterations(self):
        """ Tests that the o2m proxy allows adding, removing and editing o2m
        records
        """
        f = Form(self.env['test_testing_utilities.parent'],
                 view='test_testing_utilities.o2m_parent')

        f.subs.new().save()
        f.subs.new().save()
        f.subs.new().save()
        f.subs.remove(index=0)

        r = f.save()

        self.assertEqual([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:
                sub.value = 5
            f.subs.new().save()

            with f.subs.edit(index=2) as sub:
                self.assertEqual(sub.v, 5)

            f.subs.remove(index=0)

        self.assertEqual([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,\
            self.assertRaises(AssertionError):
            sub.name = "whop whop"
Пример #3
0
    def test_state(self):
        # In order to test Confirm Draft Invoice wizard I create an invoice
        # and confirm it with this wizard
        f = Form(self.env['account.invoice'])
        f.partner_id = self.env.ref('base.res_partner_12')
        with f.invoice_line_ids.new() as l:
            l.product_id = self.env.ref('product.product_product_3')
        invoice = f.save()

        # I check that Initially customer invoice state is "Draft"
        self.assertEqual(invoice.state, 'draft')

        # I called the "Confirm Draft Invoices" wizard
        w = Form(self.env['account.invoice.confirm']).save()
        # I clicked on Confirm Invoices Button
        w.with_context(
            active_model='account.invoice',
            active_id=invoice.id,
            active_ids=invoice.ids,
            type='out_invoice',
        ).invoice_confirm()

        # I check that customer invoice state is "Open"
        self.assertEqual(invoice.state, 'open')

        # I check the journal associated and put this journal as not
        moves = self.env['account.move.line'].search([('invoice_id', '=',
                                                       invoice.id)])
        self.assertGreater(len(moves), 0, 'You should have multiple moves')
        moves[0].journal_id.write({'update_posted': True})

        # I cancelled this open invoice using the button on invoice
        invoice.action_invoice_cancel()
        # I check that customer invoice is in the cancel state
        self.assertEqual(invoice.state, 'cancel')
    def test_multiple_shipments_invoices(self):
        """ Tests the case into which we receive part of the goods first, then 2 invoices at different rates, and finally the remaining quantities
        """
        test_product = self.test_product_delivery
        date_po_and_delivery0 = '2017-01-01'
        purchase_order = self._create_purchase(test_product,
                                               date_po_and_delivery0,
                                               quantity=5.0)
        self._process_pickings(purchase_order.picking_ids,
                               quantity=2.0,
                               date=date_po_and_delivery0)
        picking = self.env['stock.picking'].search(
            [('purchase_id', '=', purchase_order.id)], order="id asc", limit=1)

        invoice = self._create_invoice_for_po(purchase_order, '2017-01-15')
        move_form = Form(invoice)
        with move_form.invoice_line_ids.edit(0) as line_form:
            line_form.quantity = 3.0
        invoice = move_form.save()

        self.env['res.currency.rate'].create({
            'currency_id': self.currency_one.id,
            'company_id': self.company.id,
            'rate': 7.76435463,
            'name': '2017-02-01',
        })
        invoice.post()
        self.check_reconciliation(invoice, picking, full_reconcile=False)

        invoice2 = self._create_invoice_for_po(purchase_order, '2017-02-15')
        move_form = Form(invoice2)
        with move_form.invoice_line_ids.edit(0) as line_form:
            line_form.quantity = 2.0
        invoice2 = move_form.save()

        self.env['res.currency.rate'].create({
            'currency_id': self.currency_one.id,
            'company_id': self.company.id,
            'rate': 13.834739702,
            'name': '2017-03-01',
        })
        invoice2.post()
        self.check_reconciliation(invoice2, picking, full_reconcile=False)

        self.env['res.currency.rate'].create({
            'currency_id': self.currency_one.id,
            'company_id': self.company.id,
            'rate': 12.195747002,
            'name': '2017-04-01',
        })
        # We don't need to make the date of processing explicit since the very last rate
        # will be taken
        self._process_pickings(
            purchase_order.picking_ids.filtered(lambda x: x.state != 'done'),
            quantity=3.0)
        picking = self.env['stock.picking'].search(
            [('purchase_id', '=', purchase_order.id)],
            order='id desc',
            limit=1)
        self.check_reconciliation(invoice2, picking)
Пример #5
0
    def test_state(self):
        f = Form(self.env['account.invoice'])
        f.partner_id = self.env.ref('base.res_partner_12')
        with f.invoice_line_ids.new() as l:
            l.product_id = self.env.ref('product.product_product_3')
        invoice = f.save()

        # I check that Initially customer invoice state is "Draft"
        self.assertEqual(invoice.state, 'draft')

        # I called the "Confirm Draft Invoices" wizard
        w = Form(self.env['account.invoice.confirm']).save()
        # I clicked on Confirm Invoices Button
        w.with_context(
            active_model='account.invoice',
            active_id=invoice.id,
            active_ids=invoice.ids,
            type='out_invoice',
        ).invoice_confirm()

        # I check that customer invoice state is "Open"
        self.assertEqual(invoice.state, 'open')

        # Electronic invoice must be present and have the same name as l10n_it_einvoice_name
        self.assertEqual(invoice.l10n_it_einvoice_id.name,
                         invoice.l10n_it_einvoice_name)
Пример #6
0
    def test_required_bool(self):
        f = Form(self.env['test_testing_utilities.req_bool'])
        f.f_bool = False
        r = f.save()
        self.assertEqual(r.f_bool, 0)

        f2 = Form(self.env['test_testing_utilities.req_bool'])
        r2 = f2.save()
        self.assertEqual(r2.f_bool, 0)
Пример #7
0
    def test_2weeks_calendar(self):
        calendar = self.env['resource.calendar'].create({
            'name': 'auto next day',
            'two_weeks_calendar': True,
            'attendance_ids': [(5, 0, 0),
                               (0, 0, {
                                   'name': 'monday morning odd week',
                                   'hour_from': 8,
                                   'hour_to': 12,
                                   'day_period': 'morning',
                                   'dayofweek': '0',
                                   'week_type': '0',
                               }),
                               (0, 0, {
                                   'name': 'monday morning even week',
                                   'hour_from': 10,
                                   'hour_to': 12,
                                   'day_period': 'morning',
                                   'dayofweek': '0',
                                   'week_type': '1',
                               })]
        })
        employee = self.employee_emp
        employee.resource_calendar_id = calendar

        with Form(self.env['hr.leave']) as leave_form:
            leave_form.employee_id = employee
            leave_form.holiday_status_id = self.leave_type
            # even week, works 2 hours
            leave_form.request_date_from = date(2019, 9, 2)
            leave_form.request_date_to = date(2019, 9, 2)
            leave_form.request_unit_half = True
            leave_form.request_date_from_period = 'am'

            self.assertEqual(leave_form.number_of_days_display, 1)
            self.assertEqual(leave_form.number_of_hours_display, 2)
            self.assertEqual(leave_form.date_from, datetime(2019, 9, 2, 8, 0, 0))
            self.assertEqual(leave_form.date_to, datetime(2019, 9, 2, 10, 0, 0))

        with Form(self.env['hr.leave']) as leave_form:
            leave_form.employee_id = employee
            leave_form.holiday_status_id = self.leave_type
            # odd week, works 4 hours
            leave_form.request_date_from = date(2019, 9, 9)
            leave_form.request_date_to = date(2019, 9, 9)
            leave_form.request_unit_half = True
            leave_form.request_date_from_period = 'am'

            self.assertEqual(leave_form.number_of_days_display, 1)
            self.assertEqual(leave_form.number_of_hours_display, 4)
            self.assertEqual(leave_form.date_from, datetime(2019, 9, 9, 6, 0, 0))
            self.assertEqual(leave_form.date_to, datetime(2019, 9, 9, 10, 0, 0))
    def test_sale_mrp(self):
        warehouse0 = self.env.ref('stock.warehouse0')
        # In order to test the sale_mrp module in OpenERP, I start by creating a new product 'Slider Mobile'
        # I define product category Mobile Products Sellable.

        with mute_logger('eagle.tests.common.onchange'):
            # Suppress warning on "Changing your cost method" when creating a
            # product category
            pc = Form(self.env['product.category'])
        pc.name = 'Mobile Products Sellable'
        product_category_allproductssellable0 = pc.save()

        uom_unit = self.env.ref('uom.product_uom_unit')

        self.assertIn("seller_ids", self.env['product.template'].fields_get())

        # I define product for Slider Mobile.
        product = Form(self.env['product.template'])

        product.categ_id = product_category_allproductssellable0
        product.list_price = 200.0
        product.name = 'Slider Mobile'
        product.standard_price = 189.0
        product.type = 'product'
        product.uom_id = uom_unit
        product.uom_po_id = uom_unit
        product.route_ids.clear()
        product.route_ids.add(warehouse0.manufacture_pull_id.route_id)
        product.route_ids.add(warehouse0.mto_pull_id.route_id)
        product_template_slidermobile0 = product.save()

        with Form(self.env['mrp.bom']) as bom:
            bom.product_tmpl_id = product_template_slidermobile0

        # I create a sale order for product Slider mobile
        so_form = Form(self.env['sale.order'])
        so_form.partner_id = self.env.ref('base.res_partner_4')
        with so_form.order_line.new() as line:
            line.product_id = product_template_slidermobile0.product_variant_ids
            line.price_unit = 200
            line.product_uom_qty = 500.0
            line.customer_lead = 7.0
        sale_order_so0 = so_form.save()

        # I confirm the sale order
        sale_order_so0.action_confirm()

        # I verify that a manufacturing order has been generated, and that its name and reference are correct
        mo = self.env['mrp.production'].search([('origin', 'like', sale_order_so0.name)], limit=1)
        self.assertTrue(mo, 'Manufacturing order has not been generated')
Пример #9
0
    def test_attendance_previous_day(self):
        calendar = self.env['resource.calendar'].create({
            'name': 'auto next day',
            'attendance_ids': [(5, 0, 0),
                               (0, 0, {
                                   'name': 'monday morning',
                                   'hour_from': 8,
                                   'hour_to': 12,
                                   'day_period': 'morning',
                                   'dayofweek': '0',
                               })]
        })
        employee = self.employee_emp
        employee.resource_calendar_id = calendar

        with Form(self.env['hr.leave']) as leave_form:
            leave_form.employee_id = employee
            leave_form.holiday_status_id = self.leave_type
            leave_form.request_date_from = date(2019, 9, 3)
            leave_form.request_date_to = date(2019, 9, 3)
            leave_form.request_unit_half = True
            leave_form.request_date_from_period = 'am'


            self.assertEqual(leave_form.number_of_days_display, 0)
            self.assertEqual(leave_form.number_of_hours_display, 0)
            self.assertEqual(leave_form.date_from, datetime(2019, 9, 3, 6, 0, 0))
            self.assertEqual(leave_form.date_to, datetime(2019, 9, 3, 10, 0, 0))
Пример #10
0
    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),
        )
Пример #11
0
    def test_set(self):
        """
        Checks that we get/set recordsets for m2o & that set correctly
        triggers onchange
        """
        r1 = self.env['test_testing_utilities.m2o'].create({'name': "A"})
        r2 = self.env['test_testing_utilities.m2o'].create({'name': "B"})

        f = Form(self.env['test_testing_utilities.c'])

        # check that basic manipulations work
        f.f2 = r1
        self.assertEqual(f.f2, r1)
        self.assertEqual(f.name, 'A')
        f.f2 = r2
        self.assertEqual(f.name, 'B')

        # can't set an int to an m2o field
        with self.assertRaises(AssertionError):
            f.f2 = r1.id
        self.assertEqual(f.f2, r2)
        self.assertEqual(f.name, 'B')

        # can't set a record of the wrong model
        temp = self.env['test_testing_utilities.readonly'].create({})
        with self.assertRaises(AssertionError):
            f.f2 = temp
        self.assertEqual(f.f2, r2)
        self.assertEqual(f.name, 'B')

        r = f.save()
        self.assertEqual(r.f2, r2)
Пример #12
0
    def _create_taxes(self):
        """ Create taxes

        tax7: 7%, excluded in product price
        tax10: 10%, included in product price
        """
        tax7 = self.env['account.tax'].create({'name': 'Tax 7%', 'amount': 7})
        tax10 = self.env['account.tax'].create({
            'name': 'Tax 10%',
            'amount': 10,
            'price_include': True,
            'include_base_amount': False
        })
        (tax7 | tax10).mapped('invoice_repartition_line_ids').write(
            {'account_id': self.tax_received_account.id})
        (tax7 | tax10).mapped('refund_repartition_line_ids').write(
            {'account_id': self.tax_received_account.id})

        tax_group_7_10 = tax7.copy()
        with Form(tax_group_7_10) as tax:
            tax.name = 'Tax 7+10%'
            tax.amount_type = 'group'
            tax.children_tax_ids.add(tax7)
            tax.children_tax_ids.add(tax10)

        return {'tax7': tax7, 'tax10': tax10, 'tax_group_7_10': tax_group_7_10}
Пример #13
0
 def _create_basic_config(self):
     new_config = Form(self.env['pos.config'])
     new_config.name = 'PoS Shop Test'
     new_config.module_account = True
     new_config.invoice_journal_id = self.invoice_journal
     new_config.journal_id = self.pos_sale_journal
     new_config.available_pricelist_ids.clear()
     new_config.available_pricelist_ids.add(self.currency_pricelist)
     new_config.pricelist_id = self.currency_pricelist
     config = new_config.save()
     cash_journal = config.payment_method_ids.filtered(
         lambda pm: pm.is_cash_count)[:1].cash_journal_id
     cash_split_pm = self.env['pos.payment.method'].create({
         'name':
         'Split (Cash) PM',
         'receivable_account_id':
         self.pos_receivable_account.id,
         'split_transactions':
         True,
         'is_cash_count':
         True,
         'cash_journal_id':
         cash_journal.id,
     })
     config.write({'payment_method_ids': [(4, cash_split_pm.id, 0)]})
     return config
Пример #14
0
    def test_attendance_on_morning(self):
        calendar = self.env['resource.calendar'].create({
            'name': 'Morning only',
            'attendance_ids': [(5, 0, 0),
                               (0, 0, {
                                   'name': 'Monday All day',
                                   'hour_from': 8,
                                   'hour_to': 16,
                                   'day_period': 'morning',
                                   'dayofweek': '0',
                               })],
        })
        employee = self.employee_emp
        employee.resource_calendar_id = calendar
        with Form(self.env['hr.leave']) as leave_form:
            leave_form.employee_id = employee
            leave_form.holiday_status_id = self.leave_type
            leave_form.request_date_from = date(2019, 9, 2)
            leave_form.request_date_to = date(2019, 9, 2)
            leave_form.request_unit_half = True
            # Ask for morning
            leave_form.request_date_from_period = 'am'

            self.assertEqual(leave_form.number_of_days_display, 1)
            self.assertEqual(leave_form.number_of_hours_display, 8)

            # Ask for afternoon
            leave_form.request_date_from_period = 'pm'

            self.assertEqual(leave_form.number_of_days_display, 1)
            self.assertEqual(leave_form.number_of_hours_display, 8)
Пример #15
0
    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)])
Пример #16
0
    def test_m2o(self):
        Sub = self.env['test_testing_utilities.m2o']
        a = Sub.create({'name': 'a'})
        b = Sub.create({'name': 'b'})
        c = Sub.create({'name': 'c'})

        r = self.env['test_testing_utilities.d'].create({
            'f': c.id,
            'f2': "OK",
        })

        with Form(r) as f:
            # no default/onchange should have run so loading an incoherent
            # record should still be incoherent
            self.assertEqual(f.f, c)
            self.assertEqual(f.f2, 'OK')

            f.f2 = "b"
            self.assertEqual(f.f, b)
            f.f2 = "Whoops"
            self.assertEqual(f.f, Sub)
            f.f2 = "a"
            self.assertEqual(f.f, a)

        self.assertEqual(r.f2, "a")
        self.assertEqual(r.f, a)
    def test_out_refund_line_onchange_sequence_number_1(self):
        self.assertRecordValues(
            self.invoice, [{
                'invoice_sequence_number_next': '0001',
                'invoice_sequence_number_next_prefix': 'RINV/2019/',
            }])

        move_form = Form(self.invoice)
        move_form.invoice_sequence_number_next = '0042'
        move_form.save()

        self.assertRecordValues(
            self.invoice, [{
                'invoice_sequence_number_next': '0042',
                'invoice_sequence_number_next_prefix': 'RINV/2019/',
            }])

        self.invoice.post()

        self.assertRecordValues(self.invoice, [{'name': 'RINV/2019/0042'}])

        invoice_copy = self.invoice.copy()
        invoice_copy.post()

        self.assertRecordValues(invoice_copy, [{'name': 'RINV/2019/0043'}])
Пример #18
0
 def test_allocation_request(self):
     """ Create an allocation request """
     # employee should be set to current user
     allocation_form = Form(self.env['hr.leave.allocation'].with_user(
         self.user_employee))
     allocation_form.holiday_status_id = self.holidays_type_1
     allocation_form.name = 'New Allocation Request'
     allocation = allocation_form.save()
Пример #19
0
 def create_payment(self, invoices):
     payment_register = Form(self.env['account.payment'].with_context(active_model='account.move', 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
 def _create_invoice_for_po(self, purchase_order, date):
     move_form = Form(
         self.env['account.move'].with_context(default_type='in_invoice'))
     move_form.invoice_date = date
     move_form.partner_id = self.test_partner
     move_form.currency_id = self.currency_two
     move_form.purchase_id = purchase_order
     return move_form.save()
Пример #21
0
    def test_basic(self):
        env = self.env(context=dict(self.env.context, journal_type='bank'))

        # select the period and journal for the bank statement
        journal = env['account.bank.statement'].with_context(
            date=time.strftime("%Y/%m/%d"),  # ???
        )._default_journal()
        self.assertTrue(journal, 'Journal has not been selected')

        f = Form(env['account.bank.statement'])
        # necessary as there may be existing bank statements with a non-zero
        # closing balance which will be used to initialise this one.
        f.balance_start = 0.0
        f.balance_end_real = 0.0
        with f.line_ids.new() as line:
            line.name = 'EXT001'
            line.amount = 1000
            line.partner_id = env.ref('base.res_partner_4')

        statement_id = f.save()

        # process the bank statement line
        account = env['account.account'].create({
            'name':
            'toto',
            'code':
            'bidule',
            'user_type_id':
            env.ref('account.data_account_type_fixed_assets').id
        })
        statement_id.line_ids[0].process_reconciliation(
            new_aml_dicts=[{
                'credit': 1000,
                'debit': 0,
                'name': 'toto',
                'account_id': account.id,
            }])

        with Form(statement_id) as f:
            # modify the bank statement and set the Ending Balance.
            f.balance_end_real = 1000.0

        # confirm the bank statement using Validate button
        statement_id.button_confirm_bank()

        self.assertEqual(statement_id.state, 'confirm')
Пример #22
0
    def test_o2m_inner_default(self):
        """ Tests that creating an o2m record will get defaults for it
        """
        f = Form(self.env['test_testing_utilities.default'])

        with f.subs.new() as s:
            self.assertEqual(s.value, 2)
            self.assertEqual(s.v, 2, "should have onchanged value to v")
Пример #23
0
 def init_invoice(cls, move_type):
     move_form = Form(cls.env['account.move'].with_context(default_type=move_type))
     move_form.invoice_date = fields.Date.from_string('2019-01-01')
     move_form.partner_id = cls.partner_a
     with move_form.invoice_line_ids.new() as line_form:
         line_form.product_id = cls.product_a
     with move_form.invoice_line_ids.new() as line_form:
         line_form.product_id = cls.product_b
     return move_form.save()
Пример #24
0
 def test_o2m_attrs(self):
     Model = self.env['test_testing_utilities.parent'].with_context(
         default_subs=[{
             'value': 5,
         }, {
             'value': 7,
         }])
     f = Form(Model, view='test_testing_utilities.o2m_modifier')
     f.save()
Пример #25
0
    def test_o2m_dyn_onchange(self):
        f = Form(self.env['test_testing_utilities.onchange_parent'], view='test_testing_utilities.m2o_onchange_view')

        with f.line_ids.new() as new_line:
            new_line.dummy = 42
            self.assertTrue(new_line.flag)

        with f.line_ids.edit(index=0) as new_line:
            self.assertTrue(new_line.flag)
Пример #26
0
 def test_o2m_readonly_subfield(self):
     """ Tests that readonly is applied to the field of the o2m = not sent
     as part of the create / write values
     """
     f = Form(self.env['o2m_readonly_subfield_parent'])
     with f.line_ids.new() as new_line:
         new_line.name = "ok"
         self.assertEqual(new_line.f, 2)
     r = f.save()
     self.assertEqual((r.line_ids.name, r.line_ids.f), ('ok', 2))
 def _create_product(self, name, uom_id, routes=()):
     p = Form(self.env['product.product'])
     p.name = name
     p.type = 'product'
     p.uom_id = uom_id
     p.uom_po_id = uom_id
     p.route_ids.clear()
     for r in routes:
         p.route_ids.add(r)
     return p.save()
Пример #28
0
 def test_required(self):
     f = Form(self.env['test_testing_utilities.a'])
     # f1 no default & no value => should fail
     with self.assertRaisesRegexp(AssertionError, 'f1 is a required field'):
         f.save()
     # set f1 and unset f2 => should work
     f.f1 = '1'
     f.f2 = False
     r = f.save()
     self.assertEqual((r.f1, r.f2, r.f3, r.f4), ('1', 0, 0, 0))
Пример #29
0
 def test_attr(self):
     f = Form(self.env['test_testing_utilities.e'],
              view='test_testing_utilities.attrs_using_m2m')
     with self.assertRaises(AssertionError):
         f.count = 5
     f.m2m.add(self.env['test_testing_utilities.sub2'].create(
         {'name': 'ok'}))
     f.count = 5
     r = f.save()
     self.assertEqual(r.m2m.mapped('name'), ['ok', '1', '2', '3', '4'])
Пример #30
0
    def test_m2m_empty(self):
        sub = self.env['test_testing_utilities.sub2'].create({'name': 'a'})

        r = self.env['test_testing_utilities.f'].create({'m2m': []})

        with Form(r) as f:
            f.m2o = sub

        self.assertEqual(r.m2o, sub)
        self.assertEqual(r.m2m, sub)