예제 #1
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)])
    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'}])
예제 #3
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),
        )
예제 #4
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"
예제 #5
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)
예제 #6
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()
예제 #7
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()
예제 #8
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()
예제 #9
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))
예제 #10
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'])
예제 #11
0
 def test_picking_1(self):
     """As a user of Company A, create a picking and use a picking type of Company B, check the
     create picking belongs to Company B.
     """
     picking_type_company_b = self.env['stock.picking.type'].search(
         [('company_id', '=', self.company_b.id)], limit=1)
     picking_form = Form(self.env['stock.picking'].with_user(self.user_a))
     picking_form.picking_type_id = picking_type_company_b
     picking = picking_form.save()
     self.assertEqual(picking.company_id, self.company_b)
예제 #12
0
 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
예제 #13
0
    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
예제 #14
0
    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)
예제 #15
0
    def test_o2m_widget(self):
        create = self.env['test_testing_utilities.sub'].create
        a, b, c = create({'v': 1}), create({'v': 2}), create({'v': 3})

        f = Form(self.env['test_testing_utilities.parent'],
                 view='test_testing_utilities.o2m_widget_m2m')
        f.subs.add(a)
        f.subs.add(b)
        f.subs.add(c)
        r = f.save()

        self.assertEqual(r.subs, a | b | c)
예제 #16
0
    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", 0, 5)])
예제 #17
0
 def _init_payment(cls, payment_type, partner_type=None):
     payment_form = Form(cls.env['account.payment'])
     payment_form.journal_id = cls.bank_journal
     payment_form.payment_date = fields.Date.from_string('2019-01-01')
     payment_form.amount = 100
     if payment_type == 'transfer':
         payment_form.destination_journal_id = cls.cash_journal
     else:
         payment_form.partner_type = partner_type
         payment_form.partner_id = cls.partner_a
     payment_form.payment_type = payment_type
     return payment_form.save()
예제 #18
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))
예제 #19
0
    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)
예제 #20
0
    def test_subcontracting_account_flow_1(self):
        self.stock_location = self.env.ref('stock.stock_location_stock')
        self.customer_location = self.env.ref('stock.stock_location_customers')
        self.supplier_location = self.env.ref('stock.stock_location_suppliers')
        self.uom_unit = self.env.ref('uom.product_uom_unit')
        self.env.ref('product.product_category_all').property_cost_method = 'fifo'

        # IN 10@10 comp1 10@20 comp2
        move1 = self.env['stock.move'].create({
            'name': 'IN 10 units @ 10.00 per unit',
            'location_id': self.supplier_location.id,
            'location_dest_id': self.env.company.subcontracting_location_id.id,
            'product_id': self.comp1.id,
            'product_uom': self.uom_unit.id,
            'product_uom_qty': 10.0,
            'price_unit': 10.0,
        })
        move1._action_confirm()
        move1._action_assign()
        move1.move_line_ids.qty_done = 10.0
        move1._action_done()
        move2 = self.env['stock.move'].create({
            'name': 'IN 10 units @ 20.00 per unit',
            'location_id': self.supplier_location.id,
            'location_dest_id': self.env.company.subcontracting_location_id.id,
            'product_id': self.comp2.id,
            'product_uom': self.uom_unit.id,
            'product_uom_qty': 10.0,
            'price_unit': 20.0,
        })
        move2._action_confirm()
        move2._action_assign()
        move2.move_line_ids.qty_done = 10.0
        move2._action_done()

        picking_form = Form(self.env['stock.picking'])
        picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
        picking_form.partner_id = self.subcontractor_partner1
        with picking_form.move_ids_without_package.new() as move:
            move.product_id = self.finished
            move.product_uom_qty = 1
        picking_receipt = picking_form.save()
        picking_receipt.move_lines.price_unit = 30.0

        picking_receipt.action_confirm()
        picking_receipt.move_lines.quantity_done = 1.0
        picking_receipt.action_done()

        mo = picking_receipt._get_subcontracted_productions()
        self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 60)
        self.assertEqual(mo.move_finished_ids.product_id.value_svl, 60)
예제 #21
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
예제 #22
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')
예제 #23
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)
예제 #24
0
    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)
예제 #25
0
    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)")
    def test_in_refund_line_onchange_product_1(self):
        move_form = Form(self.invoice)
        with move_form.invoice_line_ids.edit(0) as line_form:
            line_form.product_id = self.product_b
        move_form.save()

        self.assertInvoiceValues(
            self.invoice, [
                {
                    **self.product_line_vals_1,
                    'name': self.product_b.name,
                    'product_id': self.product_b.id,
                    'product_uom_id': self.product_b.uom_id.id,
                    'account_id':
                    self.product_b.property_account_expense_id.id,
                    'price_unit': 160.0,
                    'price_subtotal': 160.0,
                    'price_total': 208.0,
                    'tax_ids': self.product_b.supplier_taxes_id.ids,
                    'credit': 160.0,
                },
                self.product_line_vals_2,
                {
                    **self.tax_line_vals_1,
                    'price_unit': 48.0,
                    'price_subtotal': 48.0,
                    'price_total': 48.0,
                    'credit': 48.0,
                },
                {
                    **self.tax_line_vals_2,
                    'price_unit': 48.0,
                    'price_subtotal': 48.0,
                    'price_total': 48.0,
                    'credit': 48.0,
                },
                {
                    **self.term_line_vals_1,
                    'price_unit': -416.0,
                    'price_subtotal': -416.0,
                    'price_total': -416.0,
                    'debit': 416.0,
                },
            ], {
                **self.move_vals,
                'amount_untaxed': 320.0,
                'amount_tax': 96.0,
                'amount_total': 416.0,
            })
예제 #27
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)
예제 #28
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))
예제 #29
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)
    def test_in_refund_onchange_past_invoice_1(self):
        copy_invoice = self.invoice.copy()

        move_form = Form(self.invoice)
        move_form.invoice_line_ids.remove(0)
        move_form.invoice_line_ids.remove(0)
        move_form.invoice_vendor_bill_id = copy_invoice
        move_form.save()

        self.assertInvoiceValues(self.invoice, [
            self.product_line_vals_1,
            self.product_line_vals_2,
            self.tax_line_vals_1,
            self.tax_line_vals_2,
            self.term_line_vals_1,
        ], self.move_vals)