Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stock qty validation in SCR (backport #42124) #42224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def validate_rejected_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 @@ -75,6 +75,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 @@ -119,7 +120,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 @@ -556,6 +557,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
Loading