Merge pull request #52416 from aerele/fix/inventory-dimension-attribute

fix(stock): update target field attribute
This commit is contained in:
Mihir Kandoi
2026-02-05 10:23:31 +05:30
committed by GitHub
3 changed files with 98 additions and 3 deletions

View File

@@ -139,7 +139,7 @@ class InventoryDimension(Document):
self.source_fieldname = scrub(self.dimension_name)
if not self.target_fieldname:
self.target_fieldname = scrub(self.reference_document)
self.target_fieldname = scrub(self.dimension_name)
def on_update(self):
self.add_custom_fields()

View File

@@ -116,12 +116,12 @@ class TestInventoryDimension(IntegrationTestCase):
inward.load_from_db()
sle_data = frappe.db.get_value(
"Stock Ledger Entry", {"voucher_no": inward.name}, ["shelf", "warehouse"], as_dict=1
"Stock Ledger Entry", {"voucher_no": inward.name}, ["to_shelf", "warehouse"], as_dict=1
)
self.assertEqual(inward.items[0].to_shelf, "Shelf 1")
self.assertEqual(sle_data.warehouse, warehouse)
self.assertEqual(sle_data.shelf, "Shelf 1")
self.assertEqual(sle_data.to_shelf, "Shelf 1")
outward = make_stock_entry(
item_code=item_code,

View File

@@ -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)