Skip to content

Commit

Permalink
fix: stock qty validation in SCR (#42124)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Jul 1, 2024
1 parent cbd25ae commit 99f2735
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ def validate_accepted_warehouse(self):
)

def validate_available_qty_for_consumption(self):
if (
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
== "BOM"
):
return

for item in self.get("supplied_items"):
precision = item.precision("consumed_qty")
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_subcontracting(self):
self.assertEqual(scr.get("items")[0].rm_supp_cost, flt(rm_supp_cost))

def test_available_qty_for_consumption(self):
set_backflush_based_on("BOM")
make_stock_entry(item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100)
make_stock_entry(
item_code="_Test Item Home Desktop 100",
Expand Down Expand Up @@ -125,7 +126,7 @@ def test_available_qty_for_consumption(self):
)
scr = make_subcontracting_receipt(sco.name)
scr.save()
self.assertRaises(frappe.ValidationError, scr.submit)
scr.submit()

def test_subcontracting_gle_fg_item_rate_zero(self):
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries
Expand Down Expand Up @@ -476,6 +477,21 @@ def test_supplied_items_consumed_qty(self):
# consumed_qty should be (accepted_qty * qty_consumed_per_unit) = (6 * 1) = 6
self.assertEqual(scr.supplied_items[0].consumed_qty, 6)

# Do not transfer materials to the supplier warehouse and check whether system allows to consumed directly from the supplier's warehouse
sco = get_subcontracting_order(service_items=service_items)

# Transfer RM's
rm_items = get_rm_items(sco.supplied_items)
itemwise_details = make_stock_in_entry(rm_items=rm_items, warehouse="_Test Warehouse 1 - _TC")

# Create Subcontracting Receipt
scr = make_subcontracting_receipt(sco.name)
scr.submit()
self.assertEqual(scr.docstatus, 1)

for item in scr.supplied_items:
self.assertFalse(item.available_qty_for_consumption)

def test_supplied_items_cost_after_reposting(self):
# Set Backflush Based On as "BOM"
set_backflush_based_on("BOM")
Expand Down

0 comments on commit 99f2735

Please sign in to comment.