Skip to content

Commit

Permalink
Merge pull request frappe#45087 from rohitwaghchaure/fixed-support-28646
Browse files Browse the repository at this point in the history
fix: invoice against purchase receipt with returned quantity
  • Loading branch information
rohitwaghchaure authored Jan 4, 2025
2 parents 9e86a02 + d5babf4 commit a76c3b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,34 @@ def test_last_purchase_rate(self):
item.reload()
self.assertEqual(item.last_purchase_rate, 0)

def test_invoice_against_returned_pr(self):
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_invoice as make_purchase_invoice_from_pr,
)
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_return_against_rejected_warehouse,
)

item = make_item("_Test Item For Invoice Against Returned PR", properties={"is_stock_item": 1}).name

original_value = frappe.db.get_single_value(
"Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice"
)
frappe.db.set_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", 0)

pr = make_purchase_receipt(item_code=item, qty=5, rejected_qty=5, rate=100)
pr_return = make_purchase_return_against_rejected_warehouse(pr.name)
pr_return.submit()

pi = make_purchase_invoice_from_pr(pr.name)
pi.save()
self.assertEqual(pi.items[0].qty, 5.0)

frappe.db.set_single_value(
"Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", original_value
)


def set_advance_flag(company, flag, default_account):
frappe.db.set_value(
Expand Down
3 changes: 3 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,9 @@ def get_pending_qty(item_row):
return pending_qty, 0

returned_qty = flt(returned_qty_map.get(item_row.name, 0))
if item_row.rejected_qty and returned_qty:
returned_qty -= item_row.rejected_qty

if returned_qty:
if returned_qty >= pending_qty:
pending_qty = 0
Expand Down

0 comments on commit a76c3b5

Please sign in to comment.