Skip to content

Commit

Permalink
test: add test case for so stock reservation with pick list 69
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-DT committed Jan 16, 2025
1 parent e95e0a7 commit ffa00b6
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4649,6 +4649,66 @@ def test_sales_order_for_stock_reservation_with_returns_and_note_TC_S_068(self):
self.assertEqual(frappe.db.get_value('GL Entry', {'voucher_no': si.name, 'account': 'Sales - _TC'}, 'credit'), 5000)
self.assertEqual(frappe.db.get_value('GL Entry', {'voucher_no': si.name, 'account': 'Debtors - _TC'}, 'debit'), 5000)

def test_sales_order_for_stock_reservation_with_pick_list_TC_S_069(self):
make_stock_entry(item_code="_Test Item", qty=10, rate=5000, target="_Test Warehouse - _TC")

stock_setting = frappe.get_doc('Stock Settings')
stock_setting.enable_stock_resrvation = 1
stock_setting.save()

so = self.create_and_submit_sales_order(qty=1, rate=5000)

pick_list = create_pick_list(so.name)
pick_list.save()
pick_list.submit()

self.assertEqual(pick_list.docstatus, 1, "Pick List not created")

# Creating Stock Reservation Entries for Sales Order Items against Pick List
so_items_details_map = {}
for location in pick_list.locations:
if location.warehouse and location.sales_order and location.sales_order_item:
item_details = {
"sales_order_item": location.sales_order_item,
"item_code": location.item_code,
"warehouse": location.warehouse,
"qty_to_reserve": (flt(location.picked_qty) - flt(location.stock_reserved_qty)),
"from_voucher_no": location.parent,
"from_voucher_detail_no": location.name,
"serial_and_batch_bundle": location.serial_and_batch_bundle,
}
so_items_details_map.setdefault(location.sales_order, []).append(item_details)

if so_items_details_map:
for so, items_details in so_items_details_map.items():
so_doc = frappe.get_doc("Sales Order", so)
so_doc.create_stock_reservation_entries(
items_details=items_details,
from_voucher_type="Pick List",
notify=None,
)

self.assertEqual(frappe.db.get_value("Stock Reservation Entry", {"voucher_no": so_doc.name}, "status"), "Reserved")

from erpnext.stock.doctype.pick_list.pick_list import create_delivery_note
dn = create_delivery_note(pick_list.name)
dn.submit()

self.assertEqual(dn.status, "To Bill", "Delivery Note not created")
self.assertEqual(frappe.db.get_value("Stock Reservation Entry", {"voucher_no": so_doc.name}, "status"), "Delivered")

qty_change = frappe.db.get_value('Stock Ledger Entry', {'item_code': '_Test Item', 'voucher_no': dn.name, 'warehouse': '_Test Warehouse - _TC'}, 'actual_qty')
self.assertEqual(qty_change, -1)

from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
si = make_sales_invoice(dn.name)
si.save()
si.submit()

self.assertEqual(si.status, 'Unpaid')
self.assertEqual(frappe.db.get_value('GL Entry', {'voucher_no': si.name, 'account': 'Sales - _TC'}, 'credit'), 5000)
self.assertEqual(frappe.db.get_value('GL Entry', {'voucher_no': si.name, 'account': 'Debtors - _TC'}, 'debit'), 5000)

def create_and_submit_sales_order(self, qty=None, rate=None):
sales_order = make_sales_order(cost_center='Main - _TC', selling_price_list='Standard Selling', do_not_save=True)
sales_order.delivery_date = nowdate()
Expand Down

0 comments on commit ffa00b6

Please sign in to comment.