From 21d0ee8db15625799ed8c8dc95d80cff3eef7012 Mon Sep 17 00:00:00 2001 From: Pandiyan37 Date: Wed, 4 Feb 2026 22:10:22 +0530 Subject: [PATCH] test(stock): testcase for different inventory dimension --- .../test_stock_reconciliation.py | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index eb6f6ca1f2c..8825a680394 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -1712,6 +1712,101 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): self.assertEqual(docstatus, 2) + def test_stock_reco_with_opening_stock_with_diff_inventory(self): + from erpnext.stock.doctype.inventory_dimension.test_inventory_dimension import ( + create_inventory_dimension, + ) + + if frappe.db.exists("DocType", "Plant"): + return + + doctype = frappe.get_doc( + { + "doctype": "DocType", + "name": "Plant", + "module": "Stock", + "custom": 1, + "fields": [ + { + "fieldname": "plant_name", + "fieldtype": "Data", + "label": "Plant Name", + "reqd": 1, + } + ], + "autoname": "field:plant_name", + } + ) + doctype.insert(ignore_permissions=True) + create_inventory_dimension(dimension_name="ID-Plant", reference_document="Plant") + + plant_a = frappe.get_doc( + { + "doctype": "Plant", + "plant_name": "Plant A", + } + ).insert(ignore_permissions=True) + + plant_b = frappe.get_doc( + { + "doctype": "Plant", + "plant_name": "Plant B", + } + ).insert(ignore_permissions=True) + + warehouse = "_Test Warehouse - _TC" + + item_code = "Item-Test" + item = self.make_item(item_code, {"is_stock_item": 1}) + + sr = frappe.new_doc("Stock Reconciliation") + sr.purpose = "Opening Stock" + sr.posting_date = nowdate() + sr.posting_time = nowtime() + sr.company = "_Test Company" + + sr.append( + "items", + { + "item_code": item.name, + "warehouse": warehouse, + "qty": 5, + "valuation_rate": 100, + "id_plant": plant_a.name, + }, + ) + + sr.append( + "items", + { + "item_code": item.name, + "warehouse": warehouse, + "qty": 3, + "valuation_rate": 110, + "id_plant": plant_b.name, + }, + ) + + sr.insert() + sr.submit() + + self.assertEqual(len(sr.items), 2) + sle_count = frappe.db.count( + "Stock Ledger Entry", + {"voucher_type": "Stock Reconciliation", "voucher_no": sr.name, "is_cancelled": 0}, + ) + self.assertEqual(sle_count, 2) + sle = frappe.get_all( + "Stock Ledger Entry", + {"voucher_type": "Stock Reconciliation", "voucher_no": sr.name, "is_cancelled": 0}, + ["item_code", "id_plant", "actual_qty", "valuation_rate"], + ) + for s in sle: + if s.id_plant == plant_a.name: + self.assertEqual(s.actual_qty, 5) + elif s.id_plant == plant_b.name: + self.assertEqual(s.actual_qty, 3) + def create_batch_item_with_batch(item_name, batch_id): batch_item_doc = create_item(item_name, is_stock_item=1)