mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-23 00:28:30 +00:00
fix: issue in returning components against the SCO
(cherry picked from commit 729ce1dc50)
This commit is contained in:
committed by
Mergify
parent
cac35246f1
commit
87405f0753
@@ -1257,6 +1257,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"],
|
"item_code": row.item_details["rm_item_code"],
|
||||||
"subcontracted_item": row.item_details["main_item_code"],
|
"subcontracted_item": row.item_details["main_item_code"],
|
||||||
"serial_no": "\n".join(row.serial_no) if row.serial_no else "",
|
"serial_no": "\n".join(row.serial_no) if row.serial_no else "",
|
||||||
|
"use_serial_batch_fields": 1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1297,10 +1298,13 @@ def make_return_stock_entry_for_subcontract(
|
|||||||
if not value.qty:
|
if not value.qty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if item_details := value.get("item_details"):
|
||||||
|
item_details["serial_and_batch_bundle"] = None
|
||||||
|
|
||||||
if value.batch_no:
|
if value.batch_no:
|
||||||
for batch_no, qty in value.batch_no.items():
|
for batch_no, qty in value.batch_no.items():
|
||||||
if qty > 0:
|
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:
|
else:
|
||||||
add_items_in_ste(ste_doc, value, value.qty, rm_details, rm_detail_field)
|
add_items_in_ste(ste_doc, value, value.qty, rm_details, rm_detail_field)
|
||||||
|
|
||||||
|
|||||||
@@ -282,6 +282,79 @@ class TestSubcontractingController(FrappeTestCase):
|
|||||||
|
|
||||||
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)
|
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):
|
def test_return_non_consumed_materials(self):
|
||||||
"""
|
"""
|
||||||
- Set backflush based on Material Transfer.
|
- Set backflush based on Material Transfer.
|
||||||
|
|||||||
@@ -1557,7 +1557,7 @@ def get_type_of_transaction(parent_doc, child_row):
|
|||||||
elif parent_doc.get("doctype") == "Stock Reconciliation":
|
elif parent_doc.get("doctype") == "Stock Reconciliation":
|
||||||
type_of_transaction = "Inward"
|
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"
|
type_of_transaction = "Inward"
|
||||||
if (
|
if (
|
||||||
parent_doc.get("doctype") in ["Purchase Receipt", "Purchase Invoice"]
|
parent_doc.get("doctype") in ["Purchase Receipt", "Purchase Invoice"]
|
||||||
|
|||||||
@@ -317,7 +317,6 @@ class StockBalanceReport:
|
|||||||
.where((sle.docstatus < 2) & (sle.is_cancelled == 0))
|
.where((sle.docstatus < 2) & (sle.is_cancelled == 0))
|
||||||
.orderby(sle.posting_datetime)
|
.orderby(sle.posting_datetime)
|
||||||
.orderby(sle.creation)
|
.orderby(sle.creation)
|
||||||
.orderby(sle.actual_qty)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
query = self.apply_inventory_dimensions_filters(query, sle)
|
query = self.apply_inventory_dimensions_filters(query, sle)
|
||||||
|
|||||||
Reference in New Issue
Block a user