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: not able to make purchase return (backport #42053) (backport #42055) #42056

Merged
merged 1 commit into from
Jun 28, 2024
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
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
Loading