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 test_product_produce_2(self): """ Check that line are created when the consumed products are tracked by serial and the lot proposed are correct. """ self.stock_location = self.env.ref('stock.stock_location_stock') mo, bom, p_final, p1, p2 = self.generate_mo(tracking_base_1='serial', qty_base_1=1, qty_final=2) self.assertEqual(len(mo), 1, 'MO should have been created') lot_p1_1 = self.env['stock.production.lot'].create({ 'name': 'lot1', 'product_id': p1.id, }) lot_p1_2 = self.env['stock.production.lot'].create({ 'name': 'lot2', 'product_id': p1.id, }) self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1, lot_id=lot_p1_1) self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1, lot_id=lot_p1_2) self.env['stock.quant']._update_available_quantity( p2, self.stock_location, 5) mo.action_assign() produce_form = Form(self.env['mrp.product.produce'].with_context({ 'active_id': mo.id, 'active_ids': [mo.id], })) product_produce = produce_form.save() self.assertEqual( len(product_produce.produce_line_ids), 3, 'You should have 3 produce lines. One for each serial to consume') product_produce.product_qty = 1 produce_line_1 = product_produce.produce_line_ids[0] produce_line_1.qty_done = 1 remaining_lot = (lot_p1_1 | lot_p1_2) - produce_line_1.lot_id product_produce.do_produce() produce_form = Form(self.env['mrp.product.produce'].with_context({ 'active_id': mo.id, 'active_ids': [mo.id], })) product_produce = produce_form.save() self.assertEqual( len(product_produce.produce_line_ids), 2, 'You should have 2 produce lines since one has already be consumed.' ) for line in product_produce.produce_line_ids.filtered( lambda x: x.lot_id): self.assertEqual(line.lot_id, remaining_lot, 'Wrong lot proposed.')
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_00_crossdock(self): # Create a supplier supplier_crossdock = self.env['res.partner'].create( {'name': "Crossdocking supplier"}) # I first create a warehouse with pick-pack-ship and reception in 2 steps wh_f = Form(self.env['stock.warehouse']) wh_f.name = 'WareHouse PickPackShip' wh_f.code = 'whpps' wh_f.reception_steps = 'two_steps' wh_f.delivery_steps = 'pick_pack_ship' wh_pps = wh_f.save() # Check that cross-dock route is active self.assertTrue( wh_pps.crossdock_route_id.active, "Crossdock route should be active when reception_steps is not in 'single_step'" ) p_f = Form(self.env['product.template']) p_f.name = 'PCE' p_f.type = 'product' p_f.categ_id = self.env.ref('product.product_category_1') p_f.list_price = 100.0 p_f.standard_price = 70.0 with p_f.seller_ids.new() as seller: seller.name = supplier_crossdock p_f.route_ids.add(wh_pps.crossdock_route_id) cross_shop_product = p_f.save() # Create a sales order with a line of 100 PCE incoming shipment with route_id crossdock shipping so_form = Form(self.env['sale.order']) so_form.partner_id = self.env.ref('base.res_partner_4') so_form.warehouse_id = wh_pps with mute_logger('eagle.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 = cross_shop_product.product_variant_ids line.product_uom_qty = 100.0 sale_order_crossdock = so_form.save() # Confirm sales order sale_order_crossdock.action_confirm() # Run the scheduler self.env['procurement.group'].run_scheduler() # Check a quotation was created for the created supplier and confirm it po = self.env['purchase.order'].search([('partner_id', '=', supplier_crossdock.id), ('state', '=', 'draft')]) self.assertTrue(po, "an RFQ should have been created by the scheduler") po.button_confirm()
def test_shipping_cost(self): # Free delivery should not be taken into account when checking for minimum required threshold p_minimum_threshold_free_delivery = self.env['sale.coupon.program'].create({ 'name': 'free shipping if > 872 tax exl', 'promo_code_usage': 'no_code_needed', 'reward_type': 'free_shipping', 'program_type': 'promotion_program', 'rule_minimum_amount': 872, }) p_minimum_threshold_discount = self.env['sale.coupon.program'].create({ 'name': '10% reduction if > 872 tax exl', 'promo_code_usage': 'no_code_needed', 'reward_type': 'discount', 'program_type': 'promotion_program', 'discount_type': 'percentage', 'discount_percentage': 10.0, 'rule_minimum_amount': 872, }) order = self.empty_order self.iPadMini.taxes_id = self.tax_10pc_incl sol1 = self.env['sale.order.line'].create({ 'product_id': self.iPadMini.id, 'name': 'Large Cabinet', 'product_uom_qty': 3.0, 'order_id': order.id, }) order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 2, "We should get the 10% discount line since we bought 872.73$") order.carrier_id = self.env['delivery.carrier'].search([])[1] # I add delivery cost in Sales order delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({ 'default_order_id': order.id, 'default_carrier_id': self.env['delivery.carrier'].search([])[1] })) choose_delivery_carrier = delivery_wizard.save() choose_delivery_carrier.button_confirm() order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 3, "We should get the delivery line but not the free delivery since we are below 872.73$ with the 10% discount") p_minimum_threshold_free_delivery.sequence = 10 (order.order_line - sol1).unlink() # I add delivery cost in Sales order delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({ 'default_order_id': order.id, 'default_carrier_id': self.env['delivery.carrier'].search([])[1] })) choose_delivery_carrier = delivery_wizard.save() choose_delivery_carrier.button_confirm() order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 4, "We should get both promotion line since the free delivery will be applied first and won't change the SO total")
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 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_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 test_survey_invite_token(self): Answer = self.env['survey.user_input'] 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.partner_ids.add(self.customer) invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>' invite = invite_form.save() invite.action_invite() answers = Answer.search([('survey_id', '=', self.survey.id)]) self.assertEqual(len(answers), 3) self.assertEqual( set(answers.mapped('email')), set([ '*****@*****.**', '"Raoulette Vignolette" <*****@*****.**>', self.customer.email ])) self.assertEqual(answers.mapped('partner_id'), self.customer)
def test_survey_invite_authentication_signup(self): self.env["ir.config_parameter"].sudo().set_param( 'auth_signup.invitation_scope', 'b2c') self.survey.invalidate_cache() 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'])) invite_form.partner_ids.add(self.customer) invite_form.partner_ids.add(self.user_portal.partner_id) invite_form.partner_ids.add(self.user_emp.partner_id) # TDE FIXME: not sure for emails in authentication + signup # invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>' invite = invite_form.save() invite.action_invite() answers = Answer.search([('survey_id', '=', self.survey.id)]) self.assertEqual(len(answers), 3) self.assertEqual( set(answers.mapped('email')), set([ self.customer.email, self.user_emp.email, self.user_portal.email ])) self.assertEqual( answers.mapped('partner_id'), self.customer | self.user_emp.partner_id | self.user_portal.partner_id)
def test_unlink_mo(self): """ Try to unlink a Manufacturing Order, and check it's possible or not depending of the MO state (must be in cancel state to be unlinked, but the unlink method will try to cancel MO before unlink them). """ # Case #1: Create MO, do nothing and try to unlink it (can be deleted) manufacturing_order = self.generate_mo()[0] self.assertEqual(manufacturing_order.exists().state, 'confirmed') manufacturing_order.unlink() # Check the MO is deleted. self.assertEqual(manufacturing_order.exists().state, False) # Case #2: Create MO, make and post some production, then try to unlink # it (cannot be deleted) manufacturing_order = self.generate_mo()[0] # Produce some quantity (not all to avoid to done the MO when post inventory) produce_form = Form(self.env['mrp.product.produce'].with_context( active_id=manufacturing_order.id)) produce_form.qty_producing = 2 produce = produce_form.save() produce.do_produce() # Post Inventory manufacturing_order.post_inventory() # Unlink the MO must raises an UserError since it cannot be really cancelled self.assertEqual(manufacturing_order.exists().state, 'progress') with self.assertRaises(UserError): manufacturing_order.unlink()
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_company_no_color_change_logo(self): """When neither a logo nor the colors are set The wizard displays the colors of the report layout Changing logo means the colors on the wizard change too Emptying the logo works and doesn't change the colors""" self.company.write({ 'primary_color': False, 'secondary_color': False, 'logo': False, 'external_report_layout_id': self.env.ref('base.layout_template1').id, }) default_colors = self.default_colors with Form(self.env['base.document.layout']) as doc_layout: self.assertColors(doc_layout, default_colors) self.assertEqual(doc_layout.company_id, self.company) doc_layout.logo = self.company_imgs['overwatch']['img'] self.assertColors(doc_layout, self.company_imgs['overwatch']['colors']) doc_layout.logo = '' self.assertColors(doc_layout, self.company_imgs['overwatch']['colors']) self.assertEqual(doc_layout.logo, '')
def test_cancel_mo_without_routing_3(self): """ Cancel a Manufacturing Order with no routing but some productions after post inventory. """ # Create MO manufacturing_order = self.generate_mo()[0] # Produce some quantity (not all to avoid to done the MO when post inventory) produce_form = Form(self.env['mrp.product.produce'].with_context( active_id=manufacturing_order.id)) produce_form.qty_producing = 2 produce = produce_form.save() produce.do_produce() # Post Inventory manufacturing_order.post_inventory() # Cancel the MO manufacturing_order.action_cancel() # Check MO is marked as done and its SML are done or cancelled self.assertEqual(manufacturing_order.state, 'done', "MO should be in done state.") self.assertEqual( manufacturing_order.move_raw_ids[0].state, 'done', "Due to 'post_inventory', some move raw must stay in done state") self.assertEqual( manufacturing_order.move_raw_ids[1].state, 'done', "Due to 'post_inventory', some move raw must stay in done state") self.assertEqual(manufacturing_order.move_raw_ids[2].state, 'cancel', "The other move raw are cancelled like their MO.") self.assertEqual(manufacturing_order.move_raw_ids[3].state, 'cancel', "The other move raw are cancelled like their MO.") self.assertEqual( manufacturing_order.move_finished_ids[0].state, 'done', "Due to 'post_inventory', a move finished must stay in done state") self.assertEqual(manufacturing_order.move_finished_ids[1].state, 'cancel', "The other move finished is cancelled like its MO.")
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_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_product_produce_1(self): """ Check that no produce line are created when the consumed products are not tracked """ self.stock_location = self.env.ref('stock.stock_location_stock') mo, bom, p_final, p1, p2 = self.generate_mo() self.assertEqual(len(mo), 1, 'MO should have been created') self.env['stock.quant']._update_available_quantity( p1, self.stock_location, 100) self.env['stock.quant']._update_available_quantity( p2, self.stock_location, 5) mo.action_assign() produce_form = Form(self.env['mrp.product.produce'].with_context({ 'active_id': mo.id, 'active_ids': [mo.id], })) product_produce = produce_form.save() product_produce.do_produce() self.assertEqual( len(product_produce.produce_line_ids), 2, 'You should have produce lines even the consumed products are not tracked.' )
def test_pricelist_application(self): """ Test different prices are correctly applied based on dates """ support_product = self.env.ref('product.product_product_2') support_product.list_price = 100 partner = self.res_partner_model.create(dict(name="George")) christmas_pricelist = self.env['product.pricelist'].create({ 'name': 'Christmas pricelist', 'item_ids': [(0, 0, { 'date_start': "2017-12-01", 'date_end': "2017-12-24", 'compute_price': 'percentage', 'base': 'list_price', 'percent_price': 20, 'applied_on': '3_global', 'name': 'Pre-Christmas discount' }), (0, 0, { 'date_start': "2017-12-25", 'date_end': "2017-12-31", 'compute_price': 'percentage', 'base': 'list_price', 'percent_price': 50, 'applied_on': '3_global', 'name': 'Post-Christmas super-discount' })] }) # Create the SO with pricelist based on date order_form = Form(self.env['sale.order'].with_context(tracking_disable=True)) order_form.partner_id = partner order_form.date_order = '2017-12-20' order_form.pricelist_id = christmas_pricelist with order_form.order_line.new() as line: line.product_id = support_product so = order_form.save() # Check the unit price and subtotal of SO line self.assertEqual(so.order_line[0].price_unit, 80, "First date pricelist rule not applied") self.assertEquals(so.order_line[0].price_subtotal, so.order_line[0].price_unit * so.order_line[0].product_uom_qty, 'Total of SO line should be a multiplication of unit price and ordered quantity') # Change order date of the SO and check the unit price and subtotal of SO line with Form(so) as order: order.date_order = '2017-12-30' with order.order_line.edit(0) as line: line.product_id = support_product self.assertEqual(so.order_line[0].price_unit, 50, "Second date pricelist rule not applied") self.assertEquals(so.order_line[0].price_subtotal, so.order_line[0].price_unit * so.order_line[0].product_uom_qty, 'Total of SO line should be a multiplication of unit price and ordered quantity')
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_02_warehouse_twostep_manufacturing(self): """ Warehouse testing for picking ans store after manufacturing """ with Form(self.warehouse) as warehouse: warehouse.manufacture_steps = 'pbm_sam' self._check_location_and_routes() self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 3) self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.sam_loc_id.id)
def test_01_warehouse_twostep_manufacturing(self): """ Warehouse testing for picking before manufacturing """ with Form(self.warehouse) as warehouse: warehouse.manufacture_steps = 'pbm' self._check_location_and_routes() self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 2) self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.lot_stock_id.id)
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 setUp(self): super(TestSubcontractingTracking, self).setUp() # 1: Create a subcontracting partner main_company_1 = self.env['res.partner'].create( {'name': 'main_partner'}) self.subcontractor_partner1 = self.env['res.partner'].create({ 'name': 'Subcontractor 1', 'parent_id': main_company_1.id, 'company_id': self.env.ref('base.main_company').id }) # 2. Create a BOM of subcontracting type # 2.1. Comp1 has tracking by lot self.comp1_sn = self.env['product.product'].create({ 'name': 'Component1', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, 'tracking': 'serial' }) self.comp2 = self.env['product.product'].create({ 'name': 'Component2', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, }) # 2.2. Finished prodcut has tracking by serial number self.finished_lot = self.env['product.product'].create({ 'name': 'finished', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, 'tracking': 'lot' }) bom_form = Form(self.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.subcontractor_ids.add(self.subcontractor_partner1) bom_form.product_tmpl_id = self.finished_lot.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp1_sn bom_line.product_qty = 1 with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp2 bom_line.product_qty = 1 self.bom_tracked = bom_form.save()
def test_inventory_adjustment_and_negative_quants_1(self): """Make sure negative quants from returns get wiped out with an inventory adjustment""" productA = self.env['product.product'].create({ 'name': 'Product A', 'type': 'product' }) stock_location = self.env.ref('stock.stock_location_stock') customer_location = self.env.ref('stock.stock_location_customers') # Create a picking out and force availability picking_out = self.env['stock.picking'].create({ 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': stock_location.id, 'location_dest_id': customer_location.id, }) self.env['stock.move'].create({ 'name': productA.name, 'product_id': productA.id, 'product_uom_qty': 1, 'product_uom': productA.uom_id.id, 'picking_id': picking_out.id, 'location_id': stock_location.id, 'location_dest_id': customer_location.id, }) picking_out.action_confirm() picking_out.move_lines.quantity_done = 1 picking_out.action_done() quant = self.env['stock.quant'].search([ ('product_id', '=', productA.id), ('location_id', '=', stock_location.id) ]) self.assertEqual(len(quant), 1) stock_return_picking_form = Form( self.env['stock.return.picking'].with_context( active_ids=picking_out.ids, active_id=picking_out.ids[0], active_model='stock.picking')) stock_return_picking = stock_return_picking_form.save() stock_return_picking.product_return_moves.quantity = 1.0 stock_return_picking_action = stock_return_picking.create_returns() return_pick = self.env['stock.picking'].browse( stock_return_picking_action['res_id']) return_pick.action_assign() return_pick.move_lines.quantity_done = 1 return_pick.action_done() quant = self.env['stock.quant'].search([ ('product_id', '=', productA.id), ('location_id', '=', stock_location.id) ]) self.assertEqual(sum(quant.mapped('quantity')), 0)
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') with mute_logger('eagle.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 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 create_product(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 _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 _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