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 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()
def test_lifoprice(self): self._load('account', 'test', 'account_minimal_test.xml') self._load('stock_account', 'test', 'stock_valuation_account.xml') # Set product category removal strategy as LIFO product_category_001 = self.env['product.category'].create({ 'name': 'Lifo Category', 'removal_strategy_id': self.env.ref('stock.removal_lifo').id, 'property_valuation': 'real_time', 'property_cost_method': 'fifo', }) # Set a product as using lifo price product_form = Form(self.env['product.product']) product_form.default_code = 'LIFO' product_form.name = 'LIFO Ice Cream' product_form.type = 'product' product_form.categ_id = product_category_001 product_form.lst_price = 100.0 product_form.uom_id = self.env.ref('uom.product_uom_kgm') product_form.uom_po_id = self.env.ref('uom.product_uom_kgm') # these are not available (visible) in either product or variant # for views, apparently from the UI you can only set the product # category (or hand-assign the property_* version which seems...) # product_form.categ_id.valuation = 'real_time' # product_form.categ_id.property_cost_method = 'fifo' product_form.categ_id.property_stock_account_input_categ_id = self.env.ref( 'stock_dropshipping.o_expense') product_form.categ_id.property_stock_account_output_categ_id = self.env.ref( 'stock_dropshipping.o_income') product_lifo_icecream = product_form.save() std_price_wiz = Form( self.env['stock.change.standard.price'].with_context( active_id=product_lifo_icecream.id, active_model='product.product')) std_price_wiz.new_price = 70.0 std_price_wiz.save() # I create a draft Purchase Order for first in move for 10 pieces at 60 euro order_form = Form(self.env['purchase.order']) order_form.partner_id = self.env.ref('base.res_partner_3') with order_form.order_line.new() as line: line.product_id = product_lifo_icecream line.product_qty = 10.0 line.price_unit = 60.0 purchase_order_lifo1 = order_form.save() # I create a draft Purchase Order for second shipment for 30 pieces at 80 euro order2_form = Form(self.env['purchase.order']) order2_form.partner_id = self.env.ref('base.res_partner_3') with order2_form.order_line.new() as line: line.product_id = product_lifo_icecream line.product_qty = 30.0 line.price_unit = 80.0 purchase_order_lifo2 = order2_form.save() # I confirm the first purchase order purchase_order_lifo1.button_confirm() # I check the "Approved" status of purchase order 1 self.assertEqual(purchase_order_lifo1.state, 'purchase') # Process the receipt of purchase order 1 purchase_order_lifo1.picking_ids[ 0].move_lines.quantity_done = purchase_order_lifo1.picking_ids[ 0].move_lines.product_qty purchase_order_lifo1.picking_ids[0].button_validate() # I confirm the second purchase order purchase_order_lifo2.button_confirm() # Process the receipt of purchase order 2 purchase_order_lifo2.picking_ids[ 0].move_lines.quantity_done = purchase_order_lifo2.picking_ids[ 0].move_lines.product_qty purchase_order_lifo2.picking_ids[0].button_validate() # Let us send some goods out_form = Form(self.env['stock.picking']) out_form.picking_type_id = self.env.ref('stock.picking_type_out') out_form.immediate_transfer = True with out_form.move_ids_without_package.new() as move: move.product_id = product_lifo_icecream move.quantity_done = 20.0 move.date_expected = fields.Datetime.now() outgoing_lifo_shipment = out_form.save() # I assign this outgoing shipment outgoing_lifo_shipment.action_assign() # Process the delivery of the outgoing shipment outgoing_lifo_shipment.button_validate() # Check if the move value correctly reflects the fifo costing method self.assertEqual( outgoing_lifo_shipment.move_lines.stock_valuation_layer_ids.value, -1400.0, 'Stock move value should have been 1400 euro')