Skip to content

Commit

Permalink
fix: incorrect stock value for purchase returned with rejected qty (b…
Browse files Browse the repository at this point in the history
…ackport #35747) (#35752)

fix: incorrect stock value for purchase returned with rejected qty

(cherry picked from commit 28dd758)

Co-authored-by: Rohit Waghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure committed Jun 17, 2023
1 parent a0fc8e2 commit c11d950
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions erpnext/controllers/sales_and_purchase_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ def get_filters(
if reference_voucher_detail_no:
filters["voucher_detail_no"] = reference_voucher_detail_no

if item_row and item_row.get("warehouse"):
filters["warehouse"] = item_row.get("warehouse")

return filters


Expand Down
46 changes: 46 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,52 @@ def test_internal_pr_reference(self):
pr.items[0].delivery_note_item = delivery_note_item
pr.save()

def test_purchase_return_valuation_with_rejected_qty(self):
item_code = "_Test Item Return Valuation"
create_item(item_code)

warehouse = create_warehouse("_Test Warehouse Return Valuation")
rejected_warehouse = create_warehouse("_Test Rejected Warehouse Return Valuation")

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

# Step 2: Create One more Purchase Receipt with valuation rate 200
pr = make_purchase_receipt(
item_code=item_code,
warehouse=warehouse,
qty=10,
rate=200,
rejected_qty=2,
rejected_warehouse=rejected_warehouse,
)

# Step 3: Create Purchase Return for 2 qty
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_return

pr_return = make_purchase_return(pr.name)
pr_return.items[0].qty = 2 * -1
pr_return.items[0].received_qty = 2 * -1
pr_return.items[0].rejected_qty = 0
pr_return.items[0].rejected_warehouse = ""
pr_return.save()
pr_return.submit()

data = frappe.get_all(
"Stock Ledger Entry",
filters={"voucher_no": pr_return.name, "docstatus": 1},
fields=["SUM(stock_value_difference) as stock_value_difference"],
)[0]

self.assertEqual(abs(data["stock_value_difference"]), 400.00)


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 c11d950

Please sign in to comment.