def test_read_purchase_order(self): """ Check that a purchase user can read all purchase order and 'in' invoices""" purchase_user_2 = self.purchase_user.copy({ 'name': 'Purchase user 2', 'login': '******', 'email': '*****@*****.**', }) purchase_order_form = Form(self.env['purchase.order'].with_user(purchase_user_2)) purchase_order_form.partner_id = self.vendor with purchase_order_form.order_line.new() as line: line.name = self.product.name line.product_id = self.product line.product_qty = 4 line.price_unit = 5 purchase_order_user2 = purchase_order_form.save() action = purchase_order_user2.with_user(purchase_user_2).action_view_invoice() invoice_form = Form(self.env['account.move'].with_user(purchase_user_2).with_context(action['context'])) vendor_bill_user2 = invoice_form.save() # open purchase_order_user2 and vendor_bill_user2 with `self.purchase_user` purchase_order_user1 = Form(purchase_order_user2.with_user(self.purchase_user)) purchase_order_user1 = purchase_order_user1.save() vendor_bill_user1 = Form(vendor_bill_user2.with_user(self.purchase_user)) vendor_bill_user1 = vendor_bill_user1.save()
def test_flow_5(self): """ Check that the correct BoM is chosen accordingly to the partner """ # We create a second partner of type subcontractor main_partner_2 = self.env['res.partner'].create({'name': 'main_partner'}) subcontractor_partner2 = self.env['res.partner'].create({ 'name': 'subcontractor_partner', 'parent_id': main_partner_2.id, 'company_id': self.env.ref('base.main_company').id }) # We create a different BoM for the same product comp3 = self.env['product.product'].create({ 'name': 'Component1', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, }) bom_form = Form(self.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.product_tmpl_id = self.finished.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp1 bom_line.product_qty = 1 with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = comp3 bom_line.product_qty = 1 bom2 = bom_form.save() # We assign the second BoM to the new partner self.bom.write({'subcontractor_ids': [(4, self.subcontractor_partner1.id, None)]}) bom2.write({'subcontractor_ids': [(4, subcontractor_partner2.id, None)]}) # Create a receipt picking from the subcontractor1 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_receipt1 = picking_form.save() picking_receipt1.action_confirm() # Create a receipt picking from the subcontractor2 picking_form = Form(self.env['stock.picking']) picking_form.picking_type_id = self.env.ref('stock.picking_type_in') picking_form.partner_id = subcontractor_partner2 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished move.product_uom_qty = 1 picking_receipt2 = picking_form.save() picking_receipt2.action_confirm() mo_pick1 = picking_receipt1.move_lines.mapped('move_orig_ids.production_id') mo_pick2 = picking_receipt2.move_lines.mapped('move_orig_ids.production_id') self.assertEquals(len(mo_pick1), 1) self.assertEquals(len(mo_pick2), 1) self.assertEquals(mo_pick1.bom_id, self.bom) self.assertEquals(mo_pick2.bom_id, bom2)
def test_reordering_rule(self): """ - Receive products in 2 steps - The product has a reordering rule - On the po generated, the source document should be the name of the reordering rule """ warehouse_1 = self.env['stock.warehouse'].search( [('company_id', '=', self.env.user.id)], limit=1) warehouse_1.write({'reception_steps': 'two_steps'}) # Create a supplier partner = self.env['res.partner'].create({'name': 'Smith'}) # create product and set the vendor product_form = Form(self.env['product.product']) product_form.name = 'Product A' product_form.type = 'product' with product_form.seller_ids.new() as seller: seller.name = partner product_form.route_ids.add( self.env.ref('purchase_stock.route_warehouse0_buy')) product_01 = product_form.save() # create reordering rule orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) orderpoint_form.warehouse_id = warehouse_1 orderpoint_form.location_id = warehouse_1.lot_stock_id orderpoint_form.product_id = product_01 orderpoint_form.product_min_qty = 0.000 orderpoint_form.product_max_qty = 0.000 order_point = orderpoint_form.save() # Create Delivery Order of 10 product picking_form = Form(self.env['stock.picking']) picking_form.partner_id = partner picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = product_01 move.product_uom_qty = 10.0 customer_picking = picking_form.save() # picking confirm customer_picking.action_confirm() # Run scheduler self.env['procurement.group'].run_scheduler() # Check purchase order created or not purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)]) self.assertTrue(purchase_order, 'No purchase order created.') # On the po generated, the source document should be the name of the reordering rule self.assertEqual( order_point.name, purchase_order.origin, 'Source document on purchase order should be the name of the reordering rule.' )
def test_flow_6(self): """ Extra quantity on the move. """ # We create a second partner of type subcontractor main_partner_2 = self.env['res.partner'].create({'name': 'main_partner'}) subcontractor_partner2 = self.env['res.partner'].create({ 'name': 'subcontractor_partner', 'parent_id': main_partner_2.id, 'company_id': self.env.ref('base.main_company').id, }) self.env.cache.invalidate() # We create a different BoM for the same product comp3 = self.env['product.product'].create({ 'name': 'Component3', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, }) bom_form = Form(self.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.product_tmpl_id = self.finished.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp1 bom_line.product_qty = 1 with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = comp3 bom_line.product_qty = 2 bom2 = bom_form.save() # We assign the second BoM to the new partner self.bom.write({'subcontractor_ids': [(4, self.subcontractor_partner1.id, None)]}) bom2.write({'subcontractor_ids': [(4, subcontractor_partner2.id, None)]}) # Create a receipt picking from the subcontractor1 picking_form = Form(self.env['stock.picking']) picking_form.picking_type_id = self.env.ref('stock.picking_type_in') picking_form.partner_id = subcontractor_partner2 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.action_confirm() picking_receipt.move_lines.quantity_done = 3.0 picking_receipt.action_done() mo = picking_receipt._get_subcontracted_productions() move_comp1 = mo.move_raw_ids.filtered(lambda m: m.product_id == self.comp1) move_comp3 = mo.move_raw_ids.filtered(lambda m: m.product_id == comp3) self.assertEqual(sum(move_comp1.mapped('product_uom_qty')), 3.0) self.assertEqual(sum(move_comp3.mapped('product_uom_qty')), 6.0) self.assertEqual(sum(move_comp1.mapped('quantity_done')), 3.0) self.assertEqual(sum(move_comp3.mapped('quantity_done')), 6.0) move_finished = mo.move_finished_ids self.assertEqual(sum(move_finished.mapped('product_uom_qty')), 3.0) self.assertEqual(sum(move_finished.mapped('quantity_done')), 3.0)
def test_vendor_bill_flow_anglo_saxon_2(self): """In anglo saxon accounting, receive 10@10 and invoice with the addition of 1@50 as a landed costs and create a linked landed costs record. """ self.env.company.anglo_saxon_accounting = True # Create an RFQ for self.product1, 10@10 rfq = Form(self.env['purchase.order']) rfq.partner_id = self.vendor1 with rfq.order_line.new() as po_line: po_line.product_id = self.product1 po_line.price_unit = 10 po_line.product_qty = 10 po_line.taxes_id.clear() rfq = rfq.save() rfq.button_confirm() # Process the receipt receipt = rfq.picking_ids wiz = receipt.button_validate() wiz = self.env['stock.immediate.transfer'].browse( wiz['res_id']).process() self.assertEqual(rfq.order_line.qty_received, 10) input_aml = self._get_stock_input_move_lines()[-1] self.assertEqual(input_aml.debit, 0) self.assertEqual(input_aml.credit, 100) valuation_aml = self._get_stock_valuation_move_lines()[-1] self.assertEqual(valuation_aml.debit, 100) self.assertEqual(valuation_aml.credit, 0) # Create a vebdor bill for the RFQ and add to it the landed cost action = rfq.action_view_invoice() vb = Form(self.env['account.move'].with_context(action['context'])) with vb.invoice_line_ids.new() as inv_line: inv_line.product_id = self.productlc1 inv_line.price_unit = 50 inv_line.is_landed_costs_line = True vb = vb.save() vb.post() action = vb.button_create_landed_costs() lc = Form(self.env[action['res_model']].browse(action['res_id'])) lc.picking_ids.add(receipt) lc = lc.save() lc.button_validate() # Check reconciliation of input aml of lc lc_input_aml = lc.account_move_id.line_ids.filtered( lambda aml: aml.account_id == self.stock_input_account) self.assertTrue(len(lc_input_aml.full_reconcile_id), 1)
def setUp(self): super(TestMultistepManufacturing, self).setUp() self.MrpProduction = self.env['mrp.production'] # Create warehouse warehouse_form = Form(self.env['stock.warehouse']) warehouse_form.name = 'Test' warehouse_form.code = 'Test' self.warehouse = warehouse_form.save() self.uom_unit = self.env.ref('uom.product_uom_unit') # Create manufactured product product_form = Form(self.env['product.product']) product_form.name = 'Stick' product_form.uom_id = self.uom_unit product_form.uom_po_id = self.uom_unit product_form.route_ids.clear() product_form.route_ids.add(self.warehouse.manufacture_pull_id.route_id) product_form.route_ids.add(self.warehouse.mto_pull_id.route_id) self.product_manu = product_form.save() # Create raw product for manufactured product product_form = Form(self.env['product.product']) product_form.name = 'Raw Stick' product_form.uom_id = self.uom_unit product_form.uom_po_id = self.uom_unit self.product_raw = product_form.save() # Create bom for manufactured product bom_product_form = Form(self.env['mrp.bom']) bom_product_form.product_id = self.product_manu bom_product_form.product_tmpl_id = self.product_manu.product_tmpl_id bom_product_form.product_qty = 1.0 bom_product_form.type = 'normal' with bom_product_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.product_raw bom_line.product_qty = 2.0 self.bom_prod_manu = bom_product_form.save() # Create sale order sale_form = Form(self.env['sale.order']) sale_form.partner_id = self.env.ref('base.res_partner_1') sale_form.picking_policy = 'direct' sale_form.warehouse_id = self.warehouse with sale_form.order_line.new() as line: line.name = self.product_manu.name line.product_id = self.product_manu line.product_uom_qty = 1.0 line.product_uom = self.uom_unit line.price_unit = 10.0 self.sale_order = sale_form.save()
def test_00_procurement_exception(self): # I create a product with no supplier define for it. product_form = Form(self.env['product.product']) product_form.name = 'product with no seller' product_form.lst_price = 20.00 product_form.categ_id = self.env.ref('product.product_category_1') product_with_no_seller = product_form.save() std_price_wiz = Form( self.env['stock.change.standard.price'].with_context( active_id=product_with_no_seller.id, active_model='product.product')) std_price_wiz.new_price = 70.0 std_price_wiz.save() # I create a sales order with this product with route dropship. so_form = Form(self.env['sale.order']) so_form.partner_id = self.env.ref('base.res_partner_2') so_form.partner_invoice_id = self.env.ref('base.res_partner_address_3') so_form.partner_shipping_id = self.env.ref( 'base.res_partner_address_3') so_form.payment_term_id = self.env.ref( 'account.account_payment_term_end_following_month') with so_form.order_line.new() as line: line.product_id = product_with_no_seller line.product_uom_qty = 3 line.route_id = self.env.ref( 'stock_dropshipping.route_drop_shipping') sale_order_route_dropship01 = so_form.save() # I confirm the sales order, but it will raise an error with self.assertRaises(Exception): sale_order_route_dropship01.action_confirm() # I set the at least one supplier on the product. with Form(product_with_no_seller) as f: with f.seller_ids.new() as seller: seller.delay = 1 seller.name = self.env.ref('base.res_partner_2') seller.min_qty = 2.0 # I confirm the sales order, no error this time sale_order_route_dropship01.action_confirm() # I check a purchase quotation was created. purchase = self.env['purchase.order.line'].search([ ('sale_line_id', '=', sale_order_route_dropship01.order_line.ids[0]) ]).order_id self.assertTrue(purchase, 'No Purchase Quotation is created')
def test_fifo_delivered_invoice_post_partial_delivery(self): """Receive 1@8, 1@10, so 2@12, standard price 12, deliver 1, invoice 2: the price used should be 10: one at 8 and one at 10.""" self.product.categ_id.property_cost_method = 'fifo' self.product.invoice_policy = 'delivery' self._fifo_in_one_eight_one_ten() # Create and confirm a sale order for 2@12 sale_order = self._so_and_confirm_two_units() # Deliver one. sale_order.picking_ids.move_lines.quantity_done = 1 wiz = sale_order.picking_ids.button_validate() wiz = self.env[wiz['res_model']].browse(wiz['res_id']) wiz.process() # upate the standard price to 12 self.product.standard_price = 12 # Invoice 2 invoice = sale_order.with_context( default_journal_id=self.journal_sale.id)._create_invoices() invoice_form = Form(invoice) with invoice_form.invoice_line_ids.edit(0) as invoice_line: invoice_line.quantity = 2 invoice_form.save() invoice.post() # Check the resulting accounting entries amls = invoice.line_ids self.assertEqual(len(amls), 4) stock_out_aml = amls.filtered( lambda aml: aml.account_id == self.stock_output_account) self.assertEqual(stock_out_aml.debit, 0) self.assertEqual(stock_out_aml.credit, 20) cogs_aml = amls.filtered( lambda aml: aml.account_id == self.expense_account) self.assertEqual(cogs_aml.debit, 20) self.assertEqual(cogs_aml.credit, 0) receivable_aml = amls.filtered( lambda aml: aml.account_id == self.recv_account) self.assertEqual(receivable_aml.debit, 24) self.assertEqual(receivable_aml.credit, 0) income_aml = amls.filtered( lambda aml: aml.account_id == self.income_account) self.assertEqual(income_aml.debit, 0) self.assertEqual(income_aml.credit, 24)
def test_flow_9(self): """Ensure that cancel the subcontract moves will also delete the components need for the subcontractor. """ resupply_sub_on_order_route = self.env['stock.location.route'].search([ ('name', '=', 'Resupply Subcontractor on Order') ]) (self.comp1 + self.comp2).write({ 'route_ids': [(4, resupply_sub_on_order_route.id)] }) 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 = 5 picking_receipt = picking_form.save() picking_receipt.action_confirm() picking_delivery = self.env['stock.move'].search([ ('product_id', 'in', (self.comp1 | self.comp2).ids) ]).picking_id self.assertTrue(picking_delivery) self.assertEqual(picking_delivery.state, 'confirmed') self.assertEqual(self.comp1.virtual_available, -5) self.assertEqual(self.comp2.virtual_available, -5) # action_cancel is not call on the picking in order # to test behavior from other source than picking (e.g. puchase). picking_receipt.move_lines._action_cancel() self.assertEqual(picking_delivery.state, 'cancel') self.assertEqual(self.comp1.virtual_available, 0.0) self.assertEqual(self.comp1.virtual_available, 0.0)
def test_flow_8(self): resupply_sub_on_order_route = self.env['stock.location.route'].search([('name', '=', 'Resupply Subcontractor on Order')]) (self.comp1 + self.comp2).write({'route_ids': [(4, resupply_sub_on_order_route.id, None)]}) # 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 move.product_uom_qty = 5 picking_receipt = picking_form.save() picking_receipt.action_confirm() picking_receipt.move_lines.quantity_done = 3 backorder_wiz = picking_receipt.button_validate() backorder_wiz = self.env['stock.backorder.confirmation'].browse(backorder_wiz['res_id']) backorder_wiz.process() backorder = self.env['stock.picking'].search([('backorder_id', '=', picking_receipt.id)]) self.assertTrue(backorder) self.assertEqual(backorder.move_lines.product_uom_qty, 2) subcontract_order = backorder.move_lines.move_orig_ids.production_id.filtered(lambda p: p.state != 'done') self.assertTrue(subcontract_order) self.assertEqual(subcontract_order.product_uom_qty, 5) self.assertEqual(subcontract_order.qty_produced, 3) backorder.move_lines.quantity_done = 2 backorder.action_done() self.assertTrue(picking_receipt.move_lines.move_orig_ids.production_id.state == 'done')
def test_production_2(self): """Check that confirming a production in company b with user_a will create stock moves on company b. """ product_a = self.env['product.product'].create({ 'name': 'p1', 'company_id': self.company_a.id, }) component_a = self.env['product.product'].create({ 'name': 'p2', 'company_id': self.company_a.id, }) self.env['mrp.bom'].create({ 'product_id': product_a.id, 'product_tmpl_id': product_a.product_tmpl_id.id, 'company_id': self.company_a.id, 'bom_line_ids': [(0, 0, { 'product_id': component_a.id })] }) mo_form = Form(self.env['mrp.production'].with_user(self.user_a)) mo_form.product_id = product_a mo = mo_form.save() mo.with_user(self.user_b).action_confirm() self.assertEqual(mo.move_raw_ids.company_id, self.company_a) self.assertEqual(mo.move_finished_ids.company_id, self.company_a)
def test_11_return_with_refund(self): """ Creates a sale order, valids it and its delivery, then creates a return. The return must refund by default and the sale order delivered quantity must be updated. """ # Creates a sale order for 10 products. sale_order = self._get_new_sale_order() # Valids the sale order, then valids the delivery. sale_order.action_confirm() self.assertTrue(sale_order.picking_ids) self.assertEqual(sale_order.order_line.qty_delivered, 0) picking = sale_order.picking_ids picking.move_lines.write({'quantity_done': 10}) picking.button_validate() # Checks the delivery amount (must be 10). self.assertEqual(sale_order.order_line.qty_delivered, 10) # Creates a return from the delivery picking. return_picking_form = Form( self.env['stock.return.picking'].with_context( active_ids=picking.ids, active_id=picking.id, active_model='stock.picking')) return_wizard = return_picking_form.save() # Checks the field `to_refund` is checked (must be checked by default). self.assertEqual(return_wizard.product_return_moves.to_refund, True) self.assertEqual(return_wizard.product_return_moves.quantity, 10) # Valids the return picking. res = return_wizard.create_returns() return_picking = self.env['stock.picking'].browse(res['res_id']) return_picking.move_lines.write({'quantity_done': 10}) return_picking.button_validate() # Checks the delivery amount (must be 0). self.assertEqual(sale_order.order_line.qty_delivered, 0)
def test_12_return_without_refund(self): """ Do the exact thing than in `test_11_return_with_refund` except we set on False the refund and checks the sale order delivered quantity isn't changed. """ # Creates a sale order for 10 products. sale_order = self._get_new_sale_order() # Valids the sale order, then valids the delivery. sale_order.action_confirm() self.assertTrue(sale_order.picking_ids) self.assertEqual(sale_order.order_line.qty_delivered, 0) picking = sale_order.picking_ids picking.move_lines.write({'quantity_done': 10}) picking.button_validate() # Checks the delivery amount (must be 10). self.assertEqual(sale_order.order_line.qty_delivered, 10) # Creates a return from the delivery picking. return_picking_form = Form( self.env['stock.return.picking'].with_context( active_ids=picking.ids, active_id=picking.id, active_model='stock.picking')) return_wizard = return_picking_form.save() # Checks the field `to_refund` is checked, then unchecks it. self.assertEqual(return_wizard.product_return_moves.to_refund, True) self.assertEqual(return_wizard.product_return_moves.quantity, 10) return_wizard.product_return_moves.to_refund = False # Valids the return picking. res = return_wizard.create_returns() return_picking = self.env['stock.picking'].browse(res['res_id']) return_picking.move_lines.write({'quantity_done': 10}) return_picking.button_validate() # Checks the delivery amount (must still be 10). self.assertEqual(sale_order.order_line.qty_delivered, 10)
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_manufacturing_3_steps(self): """ Test MO/picking before manufacturing/picking after manufacturing components and move_orig/move_dest. Ensure that everything is created correctly. """ with Form(self.warehouse) as warehouse: warehouse.manufacture_steps = 'pbm_sam' production_form = Form(self.env['mrp.production']) production_form.product_id = self.finished_product production_form.picking_type_id = self.warehouse.manu_type_id production = production_form.save() production.action_confirm() move_raw_ids = production.move_raw_ids self.assertEqual(len(move_raw_ids), 1) self.assertEqual(move_raw_ids.product_id, self.raw_product) self.assertEqual(move_raw_ids.picking_type_id, self.warehouse.manu_type_id) pbm_move = move_raw_ids.move_orig_ids self.assertEqual(len(pbm_move), 1) self.assertEqual(pbm_move.location_id, self.warehouse.lot_stock_id) self.assertEqual(pbm_move.location_dest_id, self.warehouse.pbm_loc_id) self.assertEqual(pbm_move.picking_type_id, self.warehouse.pbm_type_id) self.assertFalse(pbm_move.move_orig_ids) move_finished_ids = production.move_finished_ids self.assertEqual(len(move_finished_ids), 1) self.assertEqual(move_finished_ids.product_id, self.finished_product) self.assertEqual(move_finished_ids.picking_type_id, self.warehouse.manu_type_id) sam_move = move_finished_ids.move_dest_ids self.assertEqual(len(sam_move), 1) self.assertEqual(sam_move.location_id, self.warehouse.sam_loc_id) self.assertEqual(sam_move.location_dest_id, self.warehouse.lot_stock_id) self.assertEqual(sam_move.picking_type_id, self.warehouse.sam_type_id) self.assertFalse(sam_move.move_dest_ids)
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.acc_stock_in: (10.0, 0.0), self.acc_stock_out: (0.0, 10.0), } self._check_results(expected_aml, 4, all_amls_return - all_amls)
def test_procurement_2(self): """Check that a manufacturing order create the right procurements when the route are set on a parent category of a product""" # find a child category id all_categ_id = self.env['product.category'].search([('parent_id', '=', None)], limit=1) child_categ_id = self.env['product.category'].search([('parent_id', '=', all_categ_id.id)], limit=1) # set the product of `self.bom_1` to this child category for bom_line_id in self.bom_1.bom_line_ids: # check that no routes are defined on the product self.assertEquals(len(bom_line_id.product_id.route_ids), 0) # set the category of the product to a child category bom_line_id.product_id.categ_id = child_categ_id # set the MTO route to the parent category (all) self.warehouse = self.env.ref('stock.warehouse0') mto_route = self.warehouse.mto_pull_id.route_id mto_route.product_categ_selectable = True all_categ_id.write({'route_ids': [(6, 0, [mto_route.id])]}) # create MO, but check it raises error as components are in make to order and not everyone has with self.assertRaises(UserError): production_form = Form(self.env['mrp.production']) production_form.product_id = self.product_4 production_form.product_uom_id = self.product_4.uom_id production_form.product_qty = 1 production_product_4 = production_form.save() production_product_4.action_confirm()
def test_flow_3(self): """ Tick "Resupply Subcontractor on Order" and "MTO" on the components and trigger the creation of the subcontracting manufacturing order through a receipt picking. Checks if the resupplying actually works. One of the component has also "manufacture" set and a BOM linked. Checks that an MO is created for this one. """ # Tick "resupply subconractor on order" resupply_sub_on_order_route = self.env['stock.location.route'].search([('name', '=', 'Resupply Subcontractor on Order')]) (self.comp1 + self.comp2).write({'route_ids': [(4, resupply_sub_on_order_route.id, None)]}) # Tick "manufacture" and MTO on self.comp2 mto_route = self.env['stock.location.route'].search([('name', '=', 'Replenish on Order (MTO)')]) manufacture_route = self.env['stock.location.route'].search([('name', '=', 'Manufacture')]) self.comp2.write({'route_ids': [(4, manufacture_route.id, None)]}) self.comp2.write({'route_ids': [(4, mto_route.id, None)]}) # 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 move.product_uom_qty = 1 picking_receipt = picking_form.save() picking_receipt.action_confirm() # Nothing should be tracked self.assertFalse(picking_receipt.display_action_record_components) # Pickings should directly be created mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)]) self.assertEquals(mo.state, 'confirmed') picking_delivery = mo.picking_ids self.assertEqual(len(picking_delivery), 1) self.assertEqual(len(picking_delivery.move_lines), 2) self.assertEquals(picking_delivery.origin, picking_receipt.name) self.assertEquals(picking_delivery.partner_id, picking_receipt.partner_id) # The picking should be a delivery order wh = picking_receipt.picking_type_id.warehouse_id self.assertEquals(mo.picking_ids.picking_type_id, wh.out_type_id) self.assertEquals(mo.picking_type_id, wh.subcontracting_type_id) self.assertFalse(mo.picking_type_id.active) # As well as a manufacturing order for `self.comp2` comp2mo = self.env['mrp.production'].search([('bom_id', '=', self.comp2_bom.id)]) self.assertEqual(len(comp2mo), 1) picking_receipt.move_lines.quantity_done = 1 picking_receipt.button_validate() self.assertEquals(mo.state, 'done') # Available quantities should be negative at the subcontracting location for each components avail_qty_comp1 = self.env['stock.quant']._get_available_quantity(self.comp1, 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, wh.lot_stock_id) self.assertEquals(avail_qty_comp1, -1) self.assertEquals(avail_qty_comp2, -1) self.assertEquals(avail_qty_finished, 1)
def test_survey_invite_authentication_nosignup(self): Answer = self.env['survey.user_input'] self.survey.write({'access_mode': 'public', 'users_login_required': True}) action = self.survey.action_send_survey() invite_form = Form(self.env[action['res_model']].with_context(action['context'])) with self.assertRaises(UserError): # do not allow to add customer (partner without user) invite_form.partner_ids.add(self.customer) invite_form.partner_ids.clear() invite_form.partner_ids.add(self.user_portal.partner_id) invite_form.partner_ids.add(self.user_emp.partner_id) with self.assertRaises(UserError): invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>' invite_form.emails = False invite = invite_form.save() invite.action_invite() answers = Answer.search([('survey_id', '=', self.survey.id)]) self.assertEqual(len(answers), 2) self.assertEqual( set(answers.mapped('email')), set([self.user_emp.email, self.user_portal.email])) self.assertEqual(answers.mapped('partner_id'), self.user_emp.partner_id | self.user_portal.partner_id)
def test_survey_invite(self): Answer = self.env['survey.user_input'] deadline = fields.Datetime.now() + relativedelta(months=1) self.survey.write({'access_mode': 'public', 'users_login_required': False}) action = self.survey.action_send_survey() invite_form = Form(self.env[action['res_model']].with_context(action['context'])) # some lowlevel checks that action is correctly configured self.assertEqual(Answer.search([('survey_id', '=', self.survey.id)]), self.env['survey.user_input']) self.assertEqual(invite_form.survey_id, self.survey) invite_form.partner_ids.add(self.customer) invite_form.deadline = fields.Datetime.to_string(deadline) invite = invite_form.save() invite.action_invite() answers = Answer.search([('survey_id', '=', self.survey.id)]) self.assertEqual(len(answers), 1) self.assertEqual( set(answers.mapped('email')), set([self.customer.email])) self.assertEqual(answers.mapped('partner_id'), self.customer) self.assertEqual(set(answers.mapped('deadline')), set([deadline]))
def _dropship_product1(self): # enable the dropship and MTO route on the product dropshipping_route = self.env.ref('stock_dropshipping.route_drop_shipping') mto_route = self.env.ref('stock.route_warehouse0_mto') self.product1.write({'route_ids': [(6, 0, [dropshipping_route.id, mto_route.id])]}) # add a vendor vendor1 = self.env['res.partner'].create({'name': 'vendor1'}) seller1 = self.env['product.supplierinfo'].create({ 'name': vendor1.id, 'price': 8, }) self.product1.write({'seller_ids': [(6, 0, [seller1.id])]}) # sell one unit of this product customer1 = self.env['res.partner'].create({'name': 'customer1'}) self.sale_order1 = self.env['sale.order'].create({ 'partner_id': customer1.id, 'partner_invoice_id': customer1.id, 'partner_shipping_id': customer1.id, 'order_line': [(0, 0, { 'name': self.product1.name, 'product_id': self.product1.id, 'product_uom_qty': 1, 'product_uom': self.product1.uom_id.id, 'price_unit': 12, })], 'pricelist_id': self.env.ref('product.list0').id, 'picking_policy': 'direct', }) self.sale_order1.action_confirm() # confirm the purchase order self.purchase_order1 = self.env['purchase.order'].search([('group_id', '=', self.sale_order1.procurement_group_id.id)]) self.purchase_order1.button_confirm() # validate the dropshipping picking self.assertEqual(len(self.sale_order1.picking_ids), 1) #self.assertEqual(self.sale_order1.picking_ids.move_lines._is_dropshipped(), True) wizard = self.sale_order1.picking_ids.button_validate() immediate_transfer = self.env[wizard['res_model']].browse(wizard['res_id']) immediate_transfer.process() self.assertEqual(self.sale_order1.picking_ids.state, 'done') # create the vendor bill move_form = Form(self.env['account.move'].with_context(default_type='in_invoice')) move_form.partner_id = vendor1 move_form.purchase_id = self.purchase_order1 self.vendor_bill1 = move_form.save() self.vendor_bill1.post() # create the customer invoice self.customer_invoice1 = self.sale_order1._create_invoices() self.customer_invoice1.post() all_amls = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids if self.sale_order1.picking_ids.move_lines.account_move_ids: all_amls |= self.sale_order1.picking_ids.move_lines.account_move_ids.line_ids return all_amls
def _make_mo(self, bom, quantity=1): mo_form = Form(self.env['mrp.production']) mo_form.product_id = bom.product_id mo_form.bom_id = bom mo_form.product_qty = quantity mo = mo_form.save() mo.action_confirm() return mo
def test_00_dropship(self): # Create a vendor supplier_dropship = self.env['res.partner'].create({'name': 'Vendor of Dropshipping test'}) # Create new product without any routes drop_shop_product = self.env['product.product'].create({ 'name': "Pen drive", 'type': "product", 'categ_id': self.env.ref('product.product_category_1').id, 'lst_price': 100.0, 'standard_price': 0.0, 'uom_id': self.env.ref('uom.product_uom_unit').id, 'uom_po_id': self.env.ref('uom.product_uom_unit').id, 'seller_ids': [(0, 0, { 'delay': 1, 'name': supplier_dropship.id, 'min_qty': 2.0 })] }) # Create a sales order with a line of 200 PCE incoming shipment, with route_id drop shipping so_form = Form(self.env['sale.order']) so_form.partner_id = self.env.ref('base.res_partner_2') so_form.payment_term_id = self.env.ref('account.account_payment_term_end_following_month') with mute_logger('harpiya.tests.common.onchange'): # otherwise complains that there's not enough inventory and # apparently that's normal according to @jco and @sle with so_form.order_line.new() as line: line.product_id = drop_shop_product line.product_uom_qty = 200 line.price_unit = 1.00 line.route_id = self.env.ref('stock_dropshipping.route_drop_shipping') sale_order_drp_shpng = so_form.save() # Confirm sales order sale_order_drp_shpng.action_confirm() # Check the sales order created a procurement group which has a procurement of 200 pieces self.assertTrue(sale_order_drp_shpng.procurement_group_id, 'SO should have procurement group') # Check a quotation was created to a certain vendor and confirm so it becomes a confirmed purchase order purchase = self.env['purchase.order'].search([('partner_id', '=', supplier_dropship.id)]) self.assertTrue(purchase, "an RFQ should have been created by the scheduler") purchase.button_confirm() self.assertEquals(purchase.state, 'purchase', 'Purchase order should be in the approved state') self.assertEquals(len(purchase.ids), 1, 'There should be one picking') # Send the 200 pieces purchase.picking_ids.move_lines.quantity_done = purchase.picking_ids.move_lines.product_qty purchase.picking_ids.button_validate() # Check one move line was created in Customers location with 200 pieces move_line = self.env['stock.move.line'].search([ ('location_dest_id', '=', self.env.ref('stock.stock_location_customers').id), ('product_id', '=', drop_shop_product.id)]) self.assertEquals(len(move_line.ids), 1, 'There should be exactly one move line')
def _produce(self, mo, quantity=0): produce_form = Form(self.env['mrp.product.produce'].with_context({ 'active_id': mo.id, 'active_ids': [mo.id], })) if quantity: produce_form.qty_producing = quantity product_produce = produce_form.save() product_produce.do_produce()
def test_employee_resource(self): _tz = 'Pacific/Apia' self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz 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 = employee_form.save() self.assertEqual(employee.tz, _tz)
def _make_return(self, move, quantity_to_return): stock_return_picking = Form(self.env['stock.return.picking']\ .with_context(active_ids=[move.picking_id.id], active_id=move.picking_id.id, active_model='stock.picking')) stock_return_picking = stock_return_picking.save() stock_return_picking.product_return_moves.quantity = quantity_to_return 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 = quantity_to_return return_pick.action_done() return return_pick.move_lines
def test_00_product_company_level_delays(self): """ In order to check schedule date, set product's Manufacturing Lead Time and Customer Lead Time and also set company's Manufacturing Lead Time and Sales Safety Days.""" company = self.env.ref('base.main_company') # Update company with Manufacturing Lead Time and Sales Safety Days company.write({'manufacturing_lead': 3.0, 'security_lead': 3.0}) # Create sale order of product_1 order_form = Form(self.env['sale.order']) order_form.partner_id = self.partner_1 with order_form.order_line.new() as line: line.product_id = self.product_1 line.product_uom_qty = 10 order = order_form.save() # Confirm sale order order.action_confirm() # Check manufacturing order created or not manufacturing_order = self.env['mrp.production'].search([ ('product_id', '=', self.product_1.id), ('move_dest_ids', 'in', order.picking_ids[0].move_lines.ids) ]) self.assertTrue(manufacturing_order, 'Manufacturing order should be created.') # Check schedule date of picking out_date = fields.Datetime.from_string(order.date_order) + timedelta( days=self.product_1.sale_delay) - timedelta( days=company.security_lead) min_date = fields.Datetime.from_string( order.picking_ids[0].scheduled_date) self.assertAlmostEqual( min_date, out_date, delta=timedelta(seconds=1), msg= 'Schedule date of picking should be equal to: Order date + Customer Lead Time - Sales Safety Days.' ) # Check schedule date of manufacturing order mo_date = out_date - timedelta( days=self.product_1.produce_delay) - timedelta( days=company.manufacturing_lead) date_deadline = fields.Datetime.from_string( manufacturing_order.date_deadline) self.assertAlmostEqual( date_deadline, mo_date, delta=timedelta(seconds=1), msg= "Schedule date of manufacturing order should be equal to: Schedule date of picking - product's Manufacturing Lead Time - company's Manufacturing Lead Time." )
def test_create_purchase_order(self): """Check a purchase user can create a vendor bill from a purchase order but not post it""" purchase_order_form = Form(self.env['purchase.order'].with_user(self.purchase_user)) purchase_order_form.partner_id = self.vendor with purchase_order_form.order_line.new() as line: line.name = self.product.name line.product_id = self.product line.product_qty = 4 line.price_unit = 5 purchase_order = purchase_order_form.save() purchase_order.button_confirm() action = purchase_order.with_user(self.purchase_user).action_view_invoice() invoice_form = Form(self.env['account.move'].with_user(self.purchase_user).with_context( action['context'] )) invoice = invoice_form.save() with self.assertRaises(AccessError): invoice.post()
def test_product_produce_2(self): """Check that using a component lot of company b in the produce wizard of a production of company a is not allowed """ product = self.env['product.product'].create({ 'name': 'p1', }) component = self.env['product.product'].create({ 'name': 'p2', 'tracking': 'lot', }) lot_b = self.env['stock.production.lot'].create({ 'product_id': component.id, 'company_id': self.company_b.id, }) self.env['mrp.bom'].create({ 'product_id': product.id, 'product_tmpl_id': product.product_tmpl_id.id, 'company_id': self.company_a.id, 'bom_line_ids': [(0, 0, { 'product_id': component.id })] }) mo_form = Form(self.env['mrp.production'].with_user(self.user_a)) mo_form.product_id = product mo = mo_form.save() mo.with_user(self.user_b).action_confirm() produce_form = Form(self.env['mrp.product.produce'].with_user( self.user_b).with_context({ 'active_id': mo.id, 'active_ids': [mo.id], })) with produce_form.raw_workorder_line_ids.edit(0) as line: line.lot_id = lot_b with self.assertRaises(UserError): produce_form.save()
def setUp(self): super(TestMultistepManufacturingWarehouse, self).setUp() # Create warehouse self.customer_location = self.env['ir.model.data'].xmlid_to_res_id('stock.stock_location_customers') warehouse_form = Form(self.env['stock.warehouse']) warehouse_form.name = 'Test Warehouse' warehouse_form.code = 'TWH' self.warehouse = warehouse_form.save() self.uom_unit = self.env.ref('uom.product_uom_unit') # Create manufactured product product_form = Form(self.env['product.product']) product_form.name = 'Stick' product_form.uom_id = self.uom_unit product_form.uom_po_id = self.uom_unit product_form.type = 'product' product_form.route_ids.clear() product_form.route_ids.add(self.warehouse.manufacture_pull_id.route_id) product_form.route_ids.add(self.warehouse.mto_pull_id.route_id) self.finished_product = product_form.save() # Create raw product for manufactured product product_form = Form(self.env['product.product']) product_form.name = 'Raw Stick' product_form.type = 'product' product_form.uom_id = self.uom_unit product_form.uom_po_id = self.uom_unit self.raw_product = product_form.save() # Create bom for manufactured product bom_product_form = Form(self.env['mrp.bom']) bom_product_form.product_id = self.finished_product bom_product_form.product_tmpl_id = self.finished_product.product_tmpl_id bom_product_form.product_qty = 1.0 bom_product_form.type = 'normal' with bom_product_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.raw_product bom_line.product_qty = 2.0 self.bom = bom_product_form.save()