Skip to content

Commit

Permalink
fix: incorrect status of the returned purchase receipt (#37300)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Oct 6, 2023
1 parent 55a9a8f commit 63f4573
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def calculate_item_values(self):

item.net_rate = item.rate

if not item.qty and self.doc.get("is_return"):
if (
not item.qty and self.doc.get("is_return") and self.doc.get("doctype") != "Purchase Receipt"
):
item.amount = flt(-1 * item.rate, item.precision("amount"))
elif not item.qty and self.doc.get("is_debit_note"):
item.amount = flt(item.rate, item.precision("amount"))
Expand Down
10 changes: 9 additions & 1 deletion erpnext/public/js/controllers/taxes_and_totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
}
else {
// allow for '0' qty on Credit/Debit notes
let qty = item.qty || (me.frm.doc.is_debit_note ? 1 : -1);
let qty = flt(item.qty);
if (!qty) {
qty = (me.frm.doc.is_debit_note ? 1 : -1);
if (me.frm.doc.doctype !== "Purchase Receipt" && me.frm.doc.is_return === 1) {
// In case of Purchase Receipt, qty can be 0 if all items are rejected
qty = flt(item.qty);
}
}

item.net_amount = item.amount = flt(item.rate * qty, precision("amount", item));
}

Expand Down
4 changes: 4 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,10 @@ def update_billing_percentage(pr_doc, update_modified=True, adjust_incoming_rate

total_amount += total_billable_amount
total_billed_amount += flt(item.billed_amt)

if pr_doc.get("is_return") and not total_amount and total_billed_amount:
total_amount = total_billed_amount

if adjust_incoming_rate:
adjusted_amt = 0.0
if item.billed_amt and item.amount:
Expand Down
26 changes: 26 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,32 @@ def test_purchase_receipt_provisional_accounting(self):
company.enable_provisional_accounting_for_non_stock_items = 0
company.save()

def test_purchase_return_status_with_debit_note(self):
pr = make_purchase_receipt(rejected_qty=10, received_qty=10, rate=100, do_not_save=1)
pr.items[0].qty = 0
pr.items[0].stock_qty = 0
pr.submit()

return_pr = make_purchase_receipt(
is_return=1,
return_against=pr.name,
qty=0,
rejected_qty=10 * -1,
received_qty=10 * -1,
do_not_save=1,
)
return_pr.items[0].qty = 0.0
return_pr.items[0].stock_qty = 0.0
return_pr.submit()

self.assertEqual(return_pr.status, "To Bill")

pi = make_purchase_invoice(return_pr.name)
pi.submit()

return_pr.reload()
self.assertEqual(return_pr.status, "Completed")


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 63f4573

Please sign in to comment.