def test_putaway_rule_on_stock_entry_material_transfer_batch_serial_item(self): """Test if batch and serial items are split correctly.""" if not frappe.db.exists("Item", "Water Bottle"): make_item("Water Bottle", { "is_stock_item": 1, "has_batch_no" : 1, "create_new_batch": 1, "has_serial_no": 1, "serial_no_series": "BOTTL-.####", "stock_uom": "Nos" }) rule_1 = create_putaway_rule(item_code="Water Bottle", warehouse=self.warehouse_1, capacity=3, uom="Nos") rule_2 = create_putaway_rule(item_code="Water Bottle", warehouse=self.warehouse_2, capacity=2, uom="Nos") make_new_batch(batch_id="BOTTL-BATCH-1", item_code="Water Bottle") pr = make_purchase_receipt(item_code="Water Bottle", qty=5, do_not_submit=1) pr.items[0].batch_no = "BOTTL-BATCH-1" pr.save() pr.submit() serial_nos = frappe.get_list("Serial No", filters={"purchase_document_no": pr.name, "status": "Active"}) serial_nos = [d.name for d in serial_nos] stock_entry = make_stock_entry(item_code="Water Bottle", source="_Test Warehouse - _TC", qty=5, target="Finished Goods - _TC", purpose="Material Transfer", apply_putaway_rule=1, do_not_save=1) stock_entry.items[0].batch_no = "BOTTL-BATCH-1" stock_entry.items[0].serial_no = "\n".join(serial_nos) stock_entry.save() self.assertEqual(stock_entry.items[0].t_warehouse, self.warehouse_1) self.assertEqual(stock_entry.items[0].qty, 3) self.assertEqual(stock_entry.items[0].putaway_rule, rule_1.name) self.assertEqual(stock_entry.items[0].serial_no, "\n".join(serial_nos[:3])) self.assertEqual(stock_entry.items[0].batch_no, "BOTTL-BATCH-1") self.assertEqual(stock_entry.items[1].t_warehouse, self.warehouse_2) self.assertEqual(stock_entry.items[1].qty, 2) self.assertEqual(stock_entry.items[1].putaway_rule, rule_2.name) self.assertEqual(stock_entry.items[1].serial_no, "\n".join(serial_nos[3:])) self.assertEqual(stock_entry.items[1].batch_no, "BOTTL-BATCH-1") stock_entry.delete() pr.cancel() rule_1.delete() rule_2.delete()
def initialize_records_for_future_negative_sle_test( item_code, batch_no, warehouses, opening_qty, posting_date ): from erpnext.stock.doctype.batch.test_batch import TestBatch, make_new_batch from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( create_stock_reconciliation, ) from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse TestBatch.make_batch_item(item_code) make_new_batch(item_code=item_code, batch_id=batch_no) warehouse_names = [create_warehouse(w) for w in warehouses] create_stock_reconciliation( purpose="Opening Stock", posting_date=posting_date, posting_time="20:00:20", item_code=item_code, warehouse=warehouse_names[0], valuation_rate=100, qty=opening_qty, batch_no=batch_no, ) return warehouse_names
def test_backflushed_based_on_for_multiple_batches(self): item_code = "_Test Subcontracted FG Item 2" make_item('Sub Contracted Raw Material 2', { 'is_stock_item': 1, 'is_sub_contracted_item': 1 }) make_subcontracted_item( item_code=item_code, has_batch_no=1, create_new_batch=1, raw_materials=["Sub Contracted Raw Material 2"]) update_backflush_based_on("Material Transferred for Subcontract") order_qty = 500 po = create_purchase_order( item_code=item_code, qty=order_qty, is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC") make_stock_entry(target="_Test Warehouse - _TC", item_code="Sub Contracted Raw Material 2", qty=552, basic_rate=100) rm_items = [{ "item_code": item_code, "rm_item_code": "Sub Contracted Raw Material 2", "item_name": "_Test Item", "qty": 552, "warehouse": "_Test Warehouse - _TC", "stock_uom": "Nos" }] rm_item_string = json.dumps(rm_items) se = frappe.get_doc( make_subcontract_transfer_entry(po.name, rm_item_string)) se.submit() for batch in ["ABCD1", "ABCD2", "ABCD3", "ABCD4"]: make_new_batch(batch_id=batch, item_code=item_code) pr = make_purchase_receipt(po.name) # partial receipt pr.get('items')[0].qty = 30 pr.get('items')[0].batch_no = "ABCD1" purchase_order = po.name purchase_order_item = po.items[0].name for batch_no, qty in {"ABCD2": 60, "ABCD3": 70, "ABCD4": 40}.items(): pr.append( "items", { "item_code": pr.get('items')[0].item_code, "item_name": pr.get('items')[0].item_name, "uom": pr.get('items')[0].uom, "stock_uom": pr.get('items')[0].stock_uom, "warehouse": pr.get('items')[0].warehouse, "conversion_factor": pr.get('items')[0].conversion_factor, "cost_center": pr.get('items')[0].cost_center, "rate": pr.get('items')[0].rate, "qty": qty, "batch_no": batch_no, "purchase_order": purchase_order, "purchase_order_item": purchase_order_item }) pr.submit() pr1 = make_purchase_receipt(po.name) pr1.get('items')[0].qty = 300 pr1.get('items')[0].batch_no = "ABCD1" pr1.save() pr_key = ("Sub Contracted Raw Material 2", po.name) consumed_qty = get_backflushed_subcontracted_raw_materials( [po.name]).get(pr_key) self.assertTrue(pr1.supplied_items[0].consumed_qty > 0) self.assertTrue(pr1.supplied_items[0].consumed_qty, flt(552.0) - flt(consumed_qty)) update_backflush_based_on("BOM")