def test_avco_and_credit_note(self): """ When reversing an invoice that contains some anglo-saxo AML, the new anglo-saxo AML should have the same value """ self.product1.categ_id.property_cost_method = 'average' self._make_in_move(self.product1, 2, unit_cost=10) invoice_form = Form(self.env['account.move'].with_context( default_move_type='out_invoice')) invoice_form.partner_id = self.env['res.partner'].create( {'name': 'Super Client'}) with invoice_form.invoice_line_ids.new() as invoice_line_form: invoice_line_form.product_id = self.product1 invoice_line_form.quantity = 2 invoice_line_form.price_unit = 25 invoice_line_form.account_id = self.default_journal_purchase.default_account_id invoice = invoice_form.save() invoice.action_post() self._make_in_move(self.product1, 2, unit_cost=20) self.assertEqual(self.product1.standard_price, 15) refund_wizard = self.env['account.move.reversal'].with_context( active_model="account.move", active_ids=invoice.ids).create({ 'refund_method': 'refund', }) action = refund_wizard.reverse_moves() reverse_invoice = self.env['account.move'].browse(action['res_id']) with Form(reverse_invoice) as reverse_invoice_form: with reverse_invoice_form.invoice_line_ids.edit(0) as line: line.quantity = 1 reverse_invoice.action_post() anglo_lines = reverse_invoice.line_ids.filtered( lambda l: l.is_anglo_saxon_line) self.assertEqual(len(anglo_lines), 2) self.assertEqual(abs(anglo_lines[0].balance), 10) self.assertEqual(abs(anglo_lines[1].balance), 10)
def test_fiscalposition_application(self): """Test application of a fiscal position mapping price included to price included tax """ uom = self.product_uom_model.search([('name', '=', 'Units')]) pricelist = self.pricelist_model.search([('name', '=', 'Public Pricelist')]) partner = self.res_partner_model.create({'name': "George"}) tax_include_src = self.tax_model.create({ 'name': "Include tax", 'amount': 21.00, 'price_include': True, }) tax_include_dst = self.tax_model.create({ 'name': "Exclude tax", 'amount': 6.00, 'price_include': True, }) product_tmpl = self.product_tmpl_model.create({ 'name': "Voiture", 'list_price': 121, 'taxes_id': [(6, 0, [tax_include_src.id])] }) product_product = product_tmpl.product_variant_id fpos = self.fiscal_position_model.create({ 'name': "fiscal position", 'sequence': 1 }) fpos_tax = self.fiscal_position_tax_model.create({ 'position_id': fpos.id, 'tax_src_id': tax_include_src.id, 'tax_dest_id': tax_include_dst.id }) # Create the SO with one SO line and apply a pricelist and fiscal position on it order_form = Form( self.env['sale.order'].with_context(tracking_disable=True)) order_form.partner_id = partner order_form.pricelist_id = pricelist order_form.fiscal_position_id = fpos with order_form.order_line.new() as line: line.name = product_product.name line.product_id = product_product line.product_uom_qty = 1.0 line.product_uom = uom sale_order = order_form.save() # Check the unit price of SO line self.assertRecordValues(sale_order.order_line, [{'price_unit': 106}])
def test_flow_tracked_only_finished(self): """ Test when only the finished product is tracked """ self.finished_product.tracking = "serial" self.comp1_sn.tracking = "none" nb_finished_product = 3 # Create a receipt picking from the subcontractor 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_product move.product_uom_qty = nb_finished_product picking_receipt = picking_form.save() picking_receipt.action_confirm() # We shouldn't be able to call the 'record_components' button self.assertFalse(picking_receipt.display_action_record_components) wh = picking_receipt.picking_type_id.warehouse_id lot_names_finished = [f"subtracked_{i}" for i in range(nb_finished_product)] move_details = Form(picking_receipt.move_lines, view='stock.view_stock_move_nosuggest_operations') for lot_name in lot_names_finished: with move_details.move_line_nosuggest_ids.new() as ml: ml.qty_done = 1 ml.lot_name = lot_name move_details.save() picking_receipt.button_validate() # Check the created manufacturing order # Should have one mo by serial number mos = picking_receipt.move_lines.move_orig_ids.production_id self.assertEqual(len(mos), nb_finished_product) self.assertEqual(mos.mapped("state"), ["done"] * nb_finished_product) self.assertEqual(mos.picking_type_id, wh.subcontracting_type_id) self.assertFalse(mos.picking_type_id.active) self.assertEqual(set(mos.lot_producing_id.mapped("name")), set(lot_names_finished)) # Available quantities should be negative at the subcontracting location for each components avail_qty_comp1 = self.env['stock.quant']._get_available_quantity(self.comp1_sn, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) avail_qty_comp2 = self.env['stock.quant']._get_available_quantity(self.comp2, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) avail_qty_finished = self.env['stock.quant']._get_available_quantity(self.finished_product, wh.lot_stock_id) self.assertEqual(avail_qty_comp1, -nb_finished_product) self.assertEqual(avail_qty_comp2, -nb_finished_product) self.assertEqual(avail_qty_finished, nb_finished_product)
def test_with_different_uom(self): """ This test ensures that the unit price is correctly computed""" uom_units = self.env['ir.model.data'].xmlid_to_object( 'uom.product_uom_unit') uom_dozens = self.env['ir.model.data'].xmlid_to_object( 'uom.product_uom_dozen') uom_pairs = self.env['uom.uom'].create({ 'name': 'Pairs', 'category_id': uom_units.category_id.id, 'uom_type': 'bigger', 'factor_inv': 2, 'rounding': 1, }) product_data = { 'name': 'SuperProduct', 'type': 'consu', 'uom_id': uom_units.id, 'uom_po_id': uom_pairs.id, 'standard_price': 100 } product_01 = self.env['product.product'].create(product_data) product_02 = self.env['product.product'].create(product_data) po_form = Form(self.env['purchase.order']) po_form.partner_id = self.partner_a with po_form.order_line.new() as po_line: po_line.product_id = product_01 with po_form.order_line.new() as po_line: po_line.product_id = product_02 po_line.product_uom = uom_dozens po = po_form.save() self.assertEqual(po.order_line[0].price_unit, 200) self.assertEqual(po.order_line[1].price_unit, 1200)
def test_03_repair_multicompany(self): """ This test ensures that the correct taxes are selected when the user fills in the RO form """ company01 = self.env.company company02 = self.env['res.company'].create({ 'name': 'SuperCompany', }) tax01 = self.env["account.tax"].create({ "name": "C01 Tax", "amount": "0.00", "company_id": company01.id }) tax02 = self.env["account.tax"].create({ "name": "C02 Tax", "amount": "0.00", "company_id": company02.id }) super_product = self.env['product.template'].create({ "name": "SuperProduct", "taxes_id": [(4, tax01.id), (4, tax02.id)], }) super_variant = super_product.product_variant_id self.assertEqual(super_variant.taxes_id, tax01 | tax02) ro_form = Form(self.env['repair.order']) ro_form.product_id = super_variant ro_form.partner_id = company01.partner_id with ro_form.operations.new() as ro_line: ro_line.product_id = super_variant with ro_form.fees_lines.new() as fee_line: fee_line.product_id = super_variant repair_order = ro_form.save() # tax02 should not be present since it belongs to the second company. self.assertEqual(repair_order.operations.tax_id, tax01) self.assertEqual(repair_order.fees_lines.tax_id, tax01)
def test_no_tracking_pbm_1(self): """Create a MO for 4 product. Produce 1. The backorder button should appear and hitting mark as done should open the backorder wizard. In the backorder wizard, choose to do the backorder. A new MO for 3 self.untracked_bom should be created. The sequence of the first MO should be MO/001-01, the sequence of the second MO should be MO/001-02. Check that all MO are reachable through the procurement group. """ with Form(self.warehouse) as warehouse: warehouse.manufacture_steps = 'pbm' production, _, product_to_build, product_to_use_1, product_to_use_2 = self.generate_mo(qty_base_1=4, qty_final=4, picking_type_id=self.warehouse.manu_type_id) move_raw_ids = production.move_raw_ids self.assertEqual(len(move_raw_ids), 2) self.assertEqual(set(move_raw_ids.mapped("product_id")), {product_to_use_1, product_to_use_2}) pbm_move = move_raw_ids.move_orig_ids self.assertEqual(len(pbm_move), 2) self.assertEqual(set(pbm_move.mapped("product_id")), {product_to_use_1, product_to_use_2}) self.assertFalse(pbm_move.move_orig_ids) mo_form = Form(production) mo_form.qty_producing = 1 production = mo_form.save() self.assertEqual(sum(pbm_move.filtered(lambda m: m.product_id.id == product_to_use_1.id).mapped("product_qty")), 16) self.assertEqual(sum(pbm_move.filtered(lambda m: m.product_id.id == product_to_use_2.id).mapped("product_qty")), 4) action = production.button_mark_done() backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context'])) backorder.save().action_backorder() mo_backorder = production.procurement_group_id.mrp_production_ids[-1] self.assertEqual(mo_backorder.delivery_count, 1) pbm_move |= mo_backorder.move_raw_ids.move_orig_ids # Check that quantity is correct self.assertEqual(sum(pbm_move.filtered(lambda m: m.product_id.id == product_to_use_1.id).mapped("product_qty")), 16) self.assertEqual(sum(pbm_move.filtered(lambda m: m.product_id.id == product_to_use_2.id).mapped("product_qty")), 4) self.assertFalse(pbm_move.move_orig_ids)
def new_mo_laptop(self): form = Form(self.env['mrp.production']) form.product_id = self.laptop form.product_qty = 1 form.bom_id = self.bom_laptop p = form.save() p.action_confirm() p.action_assign() return p
def test_employee_from_user_tz_no_reset(self): _tz = 'Pacific/Apia' self.res_users_hr_officer.tz = False Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer) employee_form = Form(Employee) employee_form.name = 'Raoul Grosbedon' employee_form.work_email = '*****@*****.**' employee_form.tz = _tz employee_form.user_id = self.res_users_hr_officer employee = employee_form.save() self.assertEqual(employee.name, 'Raoul Grosbedon') self.assertEqual(employee.work_email, self.res_users_hr_officer.email) self.assertEqual(employee.tz, _tz)
def test_backorder_name_without_procurement_group(self): production = self.generate_mo(qty_final=5)[0] mo_form = Form(production) mo_form.qty_producing = 1 mo = mo_form.save() # Remove pg to trigger fallback on backorder name mo.procurement_group_id = False action = mo.button_mark_done() backorder_form = Form(self.env['mrp.production.backorder'].with_context(**action['context'])) backorder_form.save().action_backorder() # The pg is back self.assertTrue(production.procurement_group_id) backorder_ids = production.procurement_group_id.mrp_production_ids[1] self.assertEqual(production.name.split('-')[0], backorder_ids.name.split('-')[0]) self.assertEqual(int(production.name.split('-')[1]) + 1, int(backorder_ids.name.split('-')[1]))
def test_dropship_standard_perpetual_anglosaxon_ordered_return(self): self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' self.product1.product_tmpl_id.invoice_policy = 'order' all_amls = self._dropship_product1() # return what we've done stock_return_picking_form = Form( self.env['stock.return.picking'].with_context( active_ids=self.sale_order1.picking_ids.ids, active_id=self.sale_order1.picking_ids.ids[0], active_model='stock.picking')) stock_return_picking = stock_return_picking_form.save() stock_return_picking_action = stock_return_picking.create_returns() return_pick = self.env['stock.picking'].browse( stock_return_picking_action['res_id']) return_pick.move_lines[0].move_line_ids[0].qty_done = 1.0 return_pick._action_done() self.assertEqual(return_pick.move_lines._is_dropshipped_returned(), True) all_amls_return = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids if self.sale_order1.picking_ids.mapped('move_lines.account_move_ids'): all_amls_return |= self.sale_order1.picking_ids.mapped( 'move_lines.account_move_ids.line_ids') # Two extra AML should have been created for the return expected_aml = { self.company_data['default_account_stock_in'].id: (10.0, 0.0), self.company_data['default_account_stock_out'].id: (0.0, 10.0), } self._check_results(expected_aml, 4, all_amls_return - all_amls)
def test_survey_invite_token_by_email_nosignup(self): """ Case: have multiples partners with the same email address If I set one email address, I expect one email to be sent """ first_partner = self.env['res.partner'].create({ 'name': 'Test 1', 'email': '*****@*****.**', }) self.env['res.partner'].create({ 'name': 'Test 2', 'email': '"Raoul Poilvache" <*****@*****.**>', }) self.survey.write({ 'access_mode': 'token', 'users_login_required': False }) action = self.survey.action_send_survey() invite_form = Form(self.env[action['res_model']].with_context( action['context'])) invite_form.emails = '*****@*****.**' invite = invite_form.save() invite.action_invite() answers = self.env['survey.user_input'].search([('survey_id', '=', self.survey.id)]) self.assertEqual(len(answers), 1) self.assertEqual(answers.partner_id.display_name, first_partner.display_name)
def test_company_colors_change_logo(self): """changes of the logo implies displaying the new computed colors""" self.company.write({ 'primary_color': '#ff0080', 'secondary_color': '#00ff00', 'logo': False, 'paperformat_id': self.env.ref('base.paperformat_us').id, }) with Form(self.env['base.document.layout']) as doc_layout: self.assertColors(doc_layout, self.company) doc_layout.logo = self.company_imgs['flectra']['img'] self.assertColors(doc_layout, self.company_imgs['flectra']['colors'])
def test_no_tracking_2(self): """Create a MO for 4 product. Produce 1. The backorder button should appear and hitting mark as done should open the backorder wizard. In the backorder wizard, choose to do the backorder. A new MO for 3 self.untracked_bom should be created. The sequence of the first MO should be MO/001-01, the sequence of the second MO should be MO/001-02. Check that all MO are reachable through the procurement group. """ production, _, _, product_to_use_1, _ = self.generate_mo(qty_final=4, qty_base_1=3) self.assertEqual(production.state, 'confirmed') self.assertEqual(production.reserve_visible, True) # Make some stock and reserve for product in production.move_raw_ids.product_id: self.env['stock.quant'].with_context(inventory_mode=True).create({ 'product_id': product.id, 'inventory_quantity': 100, 'location_id': production.location_src_id.id, }) production.action_assign() self.assertEqual(production.state, 'confirmed') self.assertEqual(production.reserve_visible, False) mo_form = Form(production) mo_form.qty_producing = 1 production = mo_form.save() action = production.button_mark_done() backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context'])) backorder.save().action_backorder() # Two related MO to the procurement group self.assertEqual(len(production.procurement_group_id.mrp_production_ids), 2) # Check MO backorder mo_backorder = production.procurement_group_id.mrp_production_ids[-1] self.assertEqual(mo_backorder.product_id.id, production.product_id.id) self.assertEqual(mo_backorder.product_qty, 3) self.assertEqual(sum(mo_backorder.move_raw_ids.filtered(lambda m: m.product_id.id == product_to_use_1.id).mapped("product_uom_qty")), 9) self.assertEqual(mo_backorder.reserve_visible, False) # the reservation of the first MO should've been moved here
def test_company_no_color_but_logo_change_logo(self): """When company colors are not set, but a logo is, the wizard displays the computed colors from the logo""" self.company.write({ 'primary_color': '#ff0080', 'secondary_color': '#00ff00', 'logo': self.company_imgs['sweden']['img'], 'paperformat_id': self.env.ref('base.paperformat_us').id, }) with Form(self.env['base.document.layout']) as doc_layout: self.assertColors(doc_layout, self.company) doc_layout.logo = self.company_imgs['flectra']['img'] self.assertColors(doc_layout, self.company_imgs['flectra']['colors'])