Skip to content

Commit

Permalink
fix: not able to make purchase return (#42053)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9738c04)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Jun 27, 2024
1 parent 482832f commit 1668459
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions erpnext/controllers/sales_and_purchase_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def validate_returned_items(doc):
def validate_quantity(doc, args, ref, valid_items, already_returned_items):
fields = ["stock_qty"]
if doc.doctype in ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"]:
fields.extend(["received_qty", "rejected_qty"])
if not args.get("return_qty_from_rejected_warehouse"):
fields.extend(["received_qty", "rejected_qty"])
else:
fields.extend(["received_qty"])

already_returned_data = already_returned_items.get(args.item_code) or {}

Expand All @@ -158,9 +161,12 @@ def validate_quantity(doc, args, ref, valid_items, already_returned_items):
for column in fields:
returned_qty = flt(already_returned_data.get(column, 0)) if len(already_returned_data) > 0 else 0

if column == "stock_qty":
if column == "stock_qty" and not args.get("return_qty_from_rejected_warehouse"):
reference_qty = ref.get(column)
current_stock_qty = args.get(column)
elif args.get("return_qty_from_rejected_warehouse"):
reference_qty = ref.get("rejected_qty") * ref.get("conversion_factor", 1.0)
current_stock_qty = args.get(column) * args.get("conversion_factor", 1.0)
else:
reference_qty = ref.get(column) * ref.get("conversion_factor", 1.0)
current_stock_qty = args.get(column) * args.get("conversion_factor", 1.0)
Expand Down
30 changes: 30 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,36 @@ def test_manufacturing_and_expiry_date_for_batch(self):
self.assertEqual(batch.manufacturing_date, getdate(today()))
self.assertEqual(batch.expiry_date, getdate(add_days(today(), 5)))

def test_purchase_return_from_rejected_warehouse(self):
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_return_against_rejected_warehouse,
)

item_code = "_Test Item Return from Rejected Warehouse 11"
create_item(item_code)

warehouse = create_warehouse("_Test Warehouse Return Qty Warehouse 11")
rejected_warehouse = create_warehouse("_Test Rejected Warehouse Return Qty Warehouse 11")

# Step 1: Create Purchase Receipt with valuation rate 100
pr = make_purchase_receipt(
item_code=item_code,
warehouse=warehouse,
qty=24,
rate=100,
rejected_qty=31,
rejected_warehouse=rejected_warehouse,
)

pr_return = make_purchase_return_against_rejected_warehouse(pr.name)
pr_return.save()
pr_return.submit()

self.assertEqual(pr_return.items[0].warehouse, rejected_warehouse)
self.assertEqual(pr_return.items[0].qty, 31 * -1)
self.assertEqual(pr_return.items[0].rejected_qty, 0.0)
self.assertEqual(pr_return.items[0].rejected_warehouse, "")


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down

0 comments on commit 1668459

Please sign in to comment.