Skip to content

Commit

Permalink
feat: inventory dimension for rejected materials (#44156)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9bf16df)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Nov 15, 2024
1 parent 725d107 commit 2201856
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
9 changes: 9 additions & 0 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,15 @@ def update_inventory_dimensions(self, row, sl_dict) -> None:
if not dimension:
continue

if (
self.doctype in ["Purchase Invoice", "Purchase Receipt"]
and row.get("rejected_warehouse")
and sl_dict.get("warehouse") == row.get("rejected_warehouse")
):
fieldname = f"rejected_{dimension.source_fieldname}"
sl_dict[dimension.target_fieldname] = row.get(fieldname)
continue

if self.doctype in [
"Purchase Invoice",
"Purchase Receipt",
Expand Down
23 changes: 20 additions & 3 deletions erpnext/stock/doctype/inventory_dimension/inventory_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def delete_custom_fields(self):
self.source_fieldname,
f"to_{self.source_fieldname}",
f"from_{self.source_fieldname}",
f"rejected_{self.source_fieldname}",
],
)
}
Expand Down Expand Up @@ -171,26 +172,42 @@ def get_dimension_fields(self, doctype=None):
if label_start_with:
label = f"{label_start_with} {self.dimension_name}"

return [
dimension_fields = [
dict(
fieldname="inventory_dimension",
fieldtype="Section Break",
insert_after=self.get_insert_after_fieldname(doctype),
label="Inventory Dimension",
label=_("Inventory Dimension"),
collapsible=1,
),
dict(
fieldname=self.source_fieldname,
fieldtype="Link",
insert_after="inventory_dimension",
options=self.reference_document,
label=label,
label=_(label),
search_index=1,
reqd=self.reqd,
mandatory_depends_on=self.mandatory_depends_on,
),
]

if doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]:
dimension_fields.append(
dict(
fieldname="rejected_" + self.source_fieldname,
fieldtype="Link",
insert_after=self.source_fieldname,
options=self.reference_document,
label=_("Rejected " + self.dimension_name),
search_index=1,
reqd=self.reqd,
mandatory_depends_on=self.mandatory_depends_on,
)
)

return dimension_fields

def add_custom_fields(self):
custom_fields = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,47 @@ def test_for_purchase_sales_and_stock_transaction(self):
item_code = "Test Inventory Dimension Item"
create_item(item_code)
warehouse = create_warehouse("Store Warehouse")
rj_warehouse = create_warehouse("RJ Warehouse")

if not frappe.db.exists("Store", "Rejected Store"):
frappe.get_doc({"doctype": "Store", "store_name": "Rejected Store"}).insert(
ignore_permissions=True
)

# Purchase Receipt -> Inward in Store 1
pr_doc = make_purchase_receipt(
item_code=item_code, warehouse=warehouse, qty=10, rate=100, do_not_submit=True
item_code=item_code,
warehouse=warehouse,
qty=10,
rejected_qty=5,
rate=100,
rejected_warehouse=rj_warehouse,
do_not_submit=True,
)

pr_doc.items[0].store = "Store 1"
pr_doc.items[0].rejected_store = "Rejected Store"
pr_doc.save()
pr_doc.submit()

entries = get_voucher_sl_entries(pr_doc.name, ["warehouse", "store", "incoming_rate"])
entries = frappe.get_all(
"Stock Ledger Entry",
filters={"voucher_no": pr_doc.name, "warehouse": warehouse},
fields=["store"],
order_by="creation",
)

self.assertEqual(entries[0].warehouse, warehouse)
self.assertEqual(entries[0].store, "Store 1")

entries = frappe.get_all(
"Stock Ledger Entry",
filters={"voucher_no": pr_doc.name, "warehouse": rj_warehouse},
fields=["store"],
order_by="creation",
)

self.assertEqual(entries[0].store, "Rejected Store")

# Stock Entry -> Transfer from Store 1 to Store 2
se_doc = make_stock_entry(
item_code=item_code, qty=10, from_warehouse=warehouse, to_warehouse=warehouse, do_not_save=True
Expand Down

0 comments on commit 2201856

Please sign in to comment.