Skip to content

Commit

Permalink
Merge pull request frappe#45144 from rohitwaghchaure/fixed-support-28796
Browse files Browse the repository at this point in the history
fix: issue in returning components against the SCO
  • Loading branch information
rohitwaghchaure authored Jan 7, 2025
2 parents 31dd32d + 729ce1d commit a24d7e8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
6 changes: 5 additions & 1 deletion erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ def add_items_in_ste(ste_doc, row, qty, rm_details, rm_detail_field="sco_rm_deta
"item_code": row.item_details["rm_item_code"],
"subcontracted_item": row.item_details["main_item_code"],
"serial_no": "\n".join(row.serial_no) if row.serial_no else "",
"use_serial_batch_fields": 1,
}
)

Expand Down Expand Up @@ -1303,10 +1304,13 @@ def post_process(source_doc, target_doc):
if not value.qty:
continue

if item_details := value.get("item_details"):
item_details["serial_and_batch_bundle"] = None

if value.batch_no:
for batch_no, qty in value.batch_no.items():
if qty > 0:
add_items_in_ste(ste_doc, value, value.qty, rm_details, rm_detail_field, batch_no)
add_items_in_ste(ste_doc, value, qty, rm_details, rm_detail_field, batch_no)
else:
add_items_in_ste(ste_doc, value, value.qty, rm_details, rm_detail_field)

Expand Down
73 changes: 73 additions & 0 deletions erpnext/controllers/tests/test_subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,79 @@ def test_subcontracting_with_same_components_different_fg(self):

frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)

def test_return_non_consumed_batch_materials(self):
"""
- Set backflush based on Material Transfer.
- Create SCO for item Subcontracted Item SA2.
- Transfer the batched components from Stores to Supplier warehouse with serial nos.
- Transfer extra qty of component for the subcontracted item Subcontracted Item SA2.
- Create SCR for full qty against the SCO and change the qty of raw material.
- After that return the non consumed material back to the store from supplier's warehouse.
"""

frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 0)
set_backflush_based_on("Material Transferred for Subcontract")
service_item = make_item("Subcontracted Service FG Item A", properties={"is_stock_item": 0}).name
fg_item = make_item(
"Subcontracted FG Item SA2", properties={"is_stock_item": 1, "is_sub_contracted_item": 1}
).name
rm_item = make_item(
"Subcontracted Batch RM Item SA2",
properties={
"is_stock_item": 1,
"create_new_batch": 1,
"has_batch_no": 1,
"batch_number_series": "BATCH-RM-IRM-.####",
},
).name

make_bom(item=fg_item, raw_materials=[rm_item], rate=100, currency="INR")

service_items = [
{
"warehouse": "_Test Warehouse - _TC",
"item_code": service_item,
"qty": 5,
"rate": 100,
"fg_item": fg_item,
"fg_item_qty": 5,
},
]
sco = get_subcontracting_order(service_items=service_items)
rm_items = get_rm_items(sco.supplied_items)
rm_items[0]["qty"] += 1
itemwise_details = make_stock_in_entry(rm_items=rm_items)

for item in rm_items:
item["sco_rm_detail"] = sco.items[0].name

make_stock_transfer_entry(
sco_no=sco.name,
rm_items=rm_items,
itemwise_details=copy.deepcopy(itemwise_details),
)

scr1 = make_subcontracting_receipt(sco.name)
scr1.save()
scr1.supplied_items[0].consumed_qty = 5
scr1.submit()

for key, value in get_supplied_items(scr1).items():
transferred_detais = itemwise_details.get(key)
self.assertEqual(value.qty, 5)
self.assertEqual(sorted(value.serial_no), sorted(transferred_detais.get("serial_no")[0:5]))

sco.load_from_db()
self.assertEqual(sco.supplied_items[0].consumed_qty, 5)
doc = get_materials_from_supplier(sco.name, [d.name for d in sco.supplied_items])
doc.save()
self.assertEqual(doc.items[0].qty, 1)
self.assertEqual(doc.items[0].s_warehouse, "_Test Warehouse 1 - _TC")
self.assertEqual(doc.items[0].t_warehouse, "_Test Warehouse - _TC")
self.assertTrue(doc.items[0].batch_no)
self.assertTrue(doc.items[0].use_serial_batch_fields)
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)

def test_return_non_consumed_materials(self):
"""
- Set backflush based on Material Transfer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def get_type_of_transaction(parent_doc, child_row):
elif parent_doc.get("doctype") == "Stock Reconciliation":
type_of_transaction = "Inward"

if parent_doc.get("is_return"):
if parent_doc.get("is_return") and parent_doc.get("doctype") != "Stock Entry":
type_of_transaction = "Inward"
if (
parent_doc.get("doctype") in ["Purchase Receipt", "Purchase Invoice"]
Expand Down
1 change: 0 additions & 1 deletion erpnext/stock/report/stock_balance/stock_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def prepare_sle_query(self):
.where((sle.docstatus < 2) & (sle.is_cancelled == 0))
.orderby(sle.posting_datetime)
.orderby(sle.creation)
.orderby(sle.actual_qty)
)

query = self.apply_inventory_dimensions_filters(query, sle)
Expand Down

0 comments on commit a24d7e8

Please sign in to comment.