Test case for purchase return
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 141bcd4..9cdbc2c 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -119,6 +119,38 @@
for serial_no in rejected_serial_nos:
self.assertEquals(frappe.db.get_value("Serial No", serial_no, "warehouse"),
pr.get("items")[0].rejected_warehouse)
+
+ def test_purchase_return(self):
+ set_perpetual_inventory()
+
+ pr = make_purchase_receipt()
+
+ return_pr = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-2)
+
+
+ # check sle
+ outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
+ "voucher_no": return_pr.name}, "outgoing_rate")
+
+ self.assertEqual(outgoing_rate, 50)
+
+
+ # check gl entries for return
+ gl_entries = get_gl_entries("Purchase Receipt", return_pr.name)
+
+ self.assertTrue(gl_entries)
+
+ expected_values = {
+ "_Test Warehouse - _TC": [0.0, 100.0],
+ "Stock Received But Not Billed - _TC": [100.0, 0.0],
+ }
+
+ for gle in gl_entries:
+ self.assertEquals(expected_values[gle.account][0], gle.debit)
+ self.assertEquals(expected_values[gle.account][1], gle.credit)
+
+ set_perpetual_inventory(0)
+
def get_gl_entries(voucher_type, voucher_no):
return frappe.db.sql("""select account, debit, credit
@@ -142,6 +174,8 @@
pr.is_subcontracted = args.is_subcontracted or "No"
pr.supplier_warehouse = "_Test Warehouse 1 - _TC"
pr.currency = args.currency or "INR"
+ pr.is_return = args.is_return
+ pr.return_against = args.return_against
pr.append("items", {
"item_code": args.item or args.item_code or "_Test Item",