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'}])
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()
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)
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))
def test_generate_with_putaway(self): """ Checks the `location_dest_id` of generated move lines is correclty set in fonction of defined putaway rules. """ nbre_of_lines = 4 shelf_location = self.env['stock.location'].create({ 'name': 'shelf1', 'usage': 'internal', 'location_id': self.location_dest.id, }) # Checks a first time without putaway... move = self.get_new_move(nbre_of_lines) form_wizard = Form(self.env['stock.assign.serial'].with_context( default_move_id=move.id, )) form_wizard.next_serial_count = nbre_of_lines form_wizard.next_serial_number = '001' wiz = form_wizard.save() wiz.generate_serial_numbers() for move_line in move.move_line_nosuggest_ids: self.assertEqual(move_line.qty_done, 1) # The location dest must be the default one. self.assertEqual(move_line.location_dest_id.id, self.location_dest.id) # We need to activate multi-locations to use putaway rules. grp_multi_loc = self.env.ref('stock.group_stock_multi_locations') self.env.user.write({'groups_id': [(4, grp_multi_loc.id)]}) # Creates a putaway rule putaway_product = self.env['stock.putaway.rule'].create({ 'product_id': self.product_serial.id, 'location_in_id': self.location_dest.id, 'location_out_id': shelf_location.id, }) # Checks now with putaway... move = self.get_new_move(nbre_of_lines) form_wizard = Form(self.env['stock.assign.serial'].with_context( default_move_id=move.id, )) form_wizard.next_serial_count = nbre_of_lines form_wizard.next_serial_number = '001' wiz = form_wizard.save() wiz.generate_serial_numbers() for move_line in move.move_line_nosuggest_ids: self.assertEqual(move_line.qty_done, 1) # The location dest must be now the one from the putaway. self.assertEqual(move_line.location_dest_id.id, shelf_location.id)
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, })
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"
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)
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), )
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)
def test_default_and_onchange(self): """ Checks defaults & onchanges impacting m2o fields """ Sub = self.env['test_testing_utilities.m2o'] a = Sub.create({'name': "A"}) b = Sub.create({'name': "B"}) f = Form(self.env['test_testing_utilities.d']) self.assertFalse(f.f, "The default value gets overridden by the onchange") f.f2 = "B" self.assertEqual( f.f, b, "The new m2o value should match the second field by name") f.save()
def test_generate_01_sn(self): """ Creates a move with 5 move lines, then asks for generates 5 Serial Numbers. Checks move has 5 new move lines with each a SN, and the 5 original move lines are still unchanged. """ nbre_of_lines = 5 move = self.get_new_move(nbre_of_lines) form_wizard = Form(self.env['stock.assign.serial'].with_context( default_move_id=move.id, default_next_serial_number='001', default_next_serial_count=nbre_of_lines, )) wiz = form_wizard.save() self.assertEqual(len(move.move_line_ids), nbre_of_lines) wiz.generate_serial_numbers() # Checks new move lines have the right SN generated_numbers = ['001', '002', '003', '004', '005'] self.assertEqual(len(move.move_line_ids), nbre_of_lines + len(generated_numbers)) for move_line in move.move_line_nosuggest_ids: # For a product tracked by SN, the `qty_done` is set on 1 when # `lot_name` is set. self.assertEqual(move_line.qty_done, 1) self.assertEqual(move_line.lot_name, generated_numbers.pop(0)) # Checks pre-generated move lines didn't change for move_line in (move.move_line_ids - move.move_line_nosuggest_ids): self.assertEqual(move_line.qty_done, 0) self.assertEqual(move_line.lot_name, False)
def test_set_multiple_lot_name_01(self): """ Sets five SN in one time in stock move view form, then checks move has five new move lines with the right `lot_name`. """ nbre_of_lines = 10 move = self.get_new_move(nbre_of_lines) # We must begin with a move with 10 move lines. self.assertEqual(len(move.move_line_ids), nbre_of_lines) value_list = [ 'abc-235', 'abc-237', 'abc-238', 'abc-282', 'abc-301', ] values = '\n'.join(value_list) move_form = Form(move, view='stock.view_stock_move_nosuggest_operations') with move_form.move_line_nosuggest_ids.new() as line: line.lot_name = values move = move_form.save() # After we set multiple SN, we must have now 15 move lines. self.assertEqual(len(move.move_line_ids), nbre_of_lines + len(value_list)) # Then we look each SN name is correct. for move_line in move.move_line_nosuggest_ids: self.assertEqual(move_line.lot_name, value_list.pop(0)) for move_line in (move.move_line_ids - move.move_line_nosuggest_ids): self.assertEqual(move_line.lot_name, False)
def test_generate_03_raise_exception(self): """ Tries to generate some SN but with invalid initial number. """ move = self.get_new_move(3) form_wizard = Form(self.env['stock.assign.serial'].with_context( default_move_id=move.id, default_next_serial_number='code-xxx', )) wiz = form_wizard.save() with self.assertRaises(UserError): wiz.generate_serial_numbers() form_wizard.next_serial_count = 0 # Must raise an exception because `next_serial_count` must be greater than 0. with self.assertRaises(ValidationError): form_wizard.save()
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)
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_putaway_1(self): """As a user of Company A, create a putaway rule with locations of Company A and set the company to Company B before saving. Check it is not possible. """ stock_location_a_1 = self.env['stock.location'].with_user( self.user_a).create({ 'location_id': self.stock_location_a.id, 'usage': 'internal', 'name': 'A_1', }) putaway_form = Form(self.env['stock.putaway.rule']) putaway_form.location_in_id = self.stock_location_a putaway_form.location_out_id = stock_location_a_1 putaway_form.company_id = self.company_b with self.assertRaises(UserError): putaway_form.save()
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 test_orderpoint_1(self): """As a user of company A, create an orderpoint for company B. Check itsn't possible to use a warehouse of companny A""" product = self.env['product.product'].create({ 'type': 'product', 'name': 'shared product', }) orderpoint = Form(self.env['stock.warehouse.orderpoint'].with_user( self.user_a)) orderpoint.company_id = self.company_b orderpoint.warehouse_id = self.warehouse_b orderpoint.location_id = self.stock_location_a orderpoint.product_id = product with self.assertRaises(UserError): orderpoint.save() orderpoint.location_id = self.stock_location_b orderpoint = orderpoint.save() self.assertEqual(orderpoint.company_id, self.company_b)
def test_generate_04_generate_in_multiple_time(self): """ Generates a Serial Number for each move lines (except the last one) but with multiple assignments, and checks the generated Serial Numbers are what we expect. """ nbre_of_lines = 10 move = self.get_new_move(nbre_of_lines) form_wizard = Form(self.env['stock.assign.serial'].with_context( default_move_id=move.id, )) # First assignment form_wizard.next_serial_count = 3 form_wizard.next_serial_number = '001' wiz = form_wizard.save() wiz.generate_serial_numbers() # Second assignment form_wizard.next_serial_count = 2 form_wizard.next_serial_number = 'bilou-64' wiz = form_wizard.save() wiz.generate_serial_numbers() # Third assignment form_wizard.next_serial_count = 4 form_wizard.next_serial_number = 'ro-1337-bot' wiz = form_wizard.save() wiz.generate_serial_numbers() # Checks all move lines have the right SN generated_numbers = [ # Correspond to the first assignment '001', '002', '003', # Correspond to the second assignment 'bilou-64', 'bilou-65', # Correspond to the third assignment 'ro-1337-bot', 'ro-1338-bot', 'ro-1339-bot', 'ro-1340-bot', ] self.assertEqual(len(move.move_line_ids), nbre_of_lines + len(generated_numbers)) self.assertEqual(len(move.move_line_nosuggest_ids), len(generated_numbers)) for move_line in move.move_line_nosuggest_ids: self.assertEqual(move_line.qty_done, 1) self.assertEqual(move_line.lot_name, generated_numbers.pop(0)) for move_line in (move.move_line_ids - move.move_line_nosuggest_ids): self.assertEqual(move_line.qty_done, 0) self.assertEqual(move_line.lot_name, False)
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)
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()
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()
def test_partial_payment(self): """ Create test to pay invoices (cust. inv + vendor bill) with partial payment """ # Test Customer Invoice inv_1 = self.create_invoice(amount=600) payment_register = Form(self.env['account.payment'].with_context( active_model='account.move', active_ids=inv_1.ids)) payment_register.payment_date = time.strftime('%Y') + '-07-15' payment_register.journal_id = self.bank_journal_euro payment_register.payment_method_id = self.payment_method_manual_in # Perform the partial payment by setting the amount at 550 instead of 600 payment_register.amount = 550 payment = payment_register.save() self.assertEqual(len(payment), 1) self.assertEqual(payment.invoice_ids[0].id, inv_1.id) self.assertAlmostEquals(payment.amount, 550) self.assertEqual(payment.payment_type, 'inbound') self.assertEqual(payment.partner_id, self.partner_agrolait) self.assertEqual(payment.partner_type, 'customer') # Test Vendor Bill inv_2 = self.create_invoice(amount=500, type='in_invoice', partner=self.partner_china_exp.id) payment_register = Form(self.env['account.payment'].with_context( active_model='account.move', active_ids=inv_2.ids)) payment_register.payment_date = time.strftime('%Y') + '-07-15' payment_register.journal_id = self.bank_journal_euro payment_register.payment_method_id = self.payment_method_manual_in # Perform the partial payment by setting the amount at 300 instead of 500 payment_register.amount = 300 payment = payment_register.save() self.assertEqual(len(payment), 1) self.assertEqual(payment.invoice_ids[0].id, inv_2.id) self.assertAlmostEquals(payment.amount, 300) self.assertEqual(payment.payment_type, 'outbound') self.assertEqual(payment.partner_id, self.partner_china_exp) self.assertEqual(payment.partner_type, 'supplier')
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 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'])
def test_product_1(self): """ As an user of Company A, checks we can or cannot create new product depending of its `company_id`.""" # Creates a new product with no company_id and set a responsible. # The product must be created as there is no company on the product. product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Paramite Pie' product_form.responsible_id = self.user_b product = product_form.save() self.assertEqual(product.company_id.id, False) self.assertEqual(product.responsible_id.id, self.user_b.id) # Creates a new product belong to Company A and set a responsible belong # to Company B. The product mustn't be created as the product and the # user don't belong of the same company. self.user_b.company_ids = [(6, 0, [self.company_b.id])] product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Meech Munchy' product_form.company_id = self.company_a product_form.responsible_id = self.user_b with self.assertRaises(UserError): # Raises an UserError for company incompatibility. product = product_form.save() # Creates a new product belong to Company A and set a responsible belong # to Company A & B (default B). The product must be created as the user # belongs to product's company. self.user_b.company_ids = [(6, 0, [self.company_a.id, self.company_b.id])] product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Scrab Cake' product_form.company_id = self.company_a product_form.responsible_id = self.user_b product = product_form.save() self.assertEqual(product.company_id.id, self.company_a.id) self.assertEqual(product.responsible_id.id, self.user_b.id)
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()
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)
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)])