Skip to content

Commit

Permalink
test: test case for pick list without rejected materials
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Jan 24, 2024
1 parent 4b28c4c commit 2bd98e2
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
78 changes: 78 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
from erpnext.selling.doctype.sales_order.sales_order import (
WarehouseRequired,
create_pick_list,
make_delivery_note,
make_material_request,
make_raw_material_request,
Expand Down Expand Up @@ -2082,6 +2083,83 @@ def test_expired_rate_for_packed_item(self):
self.assertEqual(so.items[0].rate, scenario.get("expected_rate"))
self.assertEqual(so.packed_items[0].rate, scenario.get("expected_rate"))

def test_pick_list_without_rejected_materials(self):
serial_and_batch_item = make_item(
"_Test Serial and Batch Item for Rejected Materials",
properties={
"has_serial_no": 1,
"has_batch_no": 1,
"create_new_batch": 1,
"batch_number_series": "BAT-TSBIFRM-.#####",
"serial_no_series": "SN-TSBIFRM-.#####",
},
).name

serial_item = make_item(
"_Test Serial Item for Rejected Materials",
properties={
"has_serial_no": 1,
"serial_no_series": "SN-TSIFRM-.#####",
},
).name

batch_item = make_item(
"_Test Batch Item for Rejected Materials",
properties={
"has_batch_no": 1,
"create_new_batch": 1,
"batch_number_series": "BAT-TBIFRM-.#####",
},
).name

normal_item = make_item("_Test Normal Item for Rejected Materials").name

warehouse = "_Test Warehouse - _TC"
rejected_warehouse = "_Test Dummy Rejected Warehouse - _TC"

if not frappe.db.exists("Warehouse", rejected_warehouse):
frappe.get_doc(
{
"doctype": "Warehouse",
"warehouse_name": rejected_warehouse,
"company": "_Test Company",
"warehouse_group": "_Test Warehouse Group",
"is_rejected_warehouse": 1,
}
).insert()

se = make_stock_entry(item_code=normal_item, qty=1, to_warehouse=warehouse, do_not_submit=True)
for item in [serial_and_batch_item, serial_item, batch_item]:
se.append("items", {"item_code": item, "qty": 1, "t_warehouse": warehouse})

se.save()
se.submit()

se = make_stock_entry(
item_code=normal_item, qty=1, to_warehouse=rejected_warehouse, do_not_submit=True
)
for item in [serial_and_batch_item, serial_item, batch_item]:
se.append("items", {"item_code": item, "qty": 1, "t_warehouse": rejected_warehouse})

se.save()
se.submit()

so = make_sales_order(item_code=normal_item, qty=2, do_not_submit=True)

for item in [serial_and_batch_item, serial_item, batch_item]:
so.append("items", {"item_code": item, "qty": 2, "warehouse": warehouse})

so.save()
so.submit()

pick_list = create_pick_list(so.name)

pick_list.save()
for row in pick_list.locations:
self.assertEqual(row.qty, 1.0)
self.assertFalse(row.warehouse == rejected_warehouse)
self.assertTrue(row.warehouse == warehouse)


def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
Expand Down
10 changes: 6 additions & 4 deletions erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ def get_available_item_locations_for_serialized_item(
query = query.where(Coalesce(sn.warehouse, "") != "")

if not consider_rejected_warehouses:
query = query.where(sn.warehouse.notin(get_rejected_warehouses()))
if rejected_warehouses := get_rejected_warehouses():
query = query.where(sn.warehouse.notin(rejected_warehouses))

serial_nos = query.run(as_list=True)

Expand Down Expand Up @@ -689,7 +690,8 @@ def get_available_item_locations_for_batched_item(
query = query.where(sle.warehouse.isin(from_warehouses))

if not consider_rejected_warehouses:
query = query.where(sle.warehouse.notin(get_rejected_warehouses()))
if rejected_warehouses := get_rejected_warehouses():
query = query.where(sle.warehouse.notin(rejected_warehouses))

return query.run(as_dict=True)

Expand Down Expand Up @@ -761,7 +763,8 @@ def get_available_item_locations_for_other_item(
query = query.from_(wh).where((bin.warehouse == wh.name) & (wh.company == company))

if not consider_rejected_warehouses:
query = query.where(bin.warehouse.notin(get_rejected_warehouses()))
if rejected_warehouses := get_rejected_warehouses():
query = query.where(bin.warehouse.notin(rejected_warehouses))

item_locations = query.run(as_dict=True)

Expand Down Expand Up @@ -1093,6 +1096,5 @@ def get_rejected_warehouses():
frappe.local.rejected_warehouses = frappe.get_all(
"Warehouse", filters={"is_rejected_warehouse": 1}, pluck="name"
)
print("hiii")

return frappe.local.rejected_warehouses

0 comments on commit 2bd98e2

Please sign in to comment.