fix: 'Bill for Rejected Quantity in Purchase Invoice' feature not working (backport #41437) (#41445)
fix: 'Bill for Rejected Quantity in Purchase Invoice' feature not working (#41437)
(cherry picked from commit 3309359822)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -1163,7 +1163,12 @@ def make_purchase_invoice(source_name, target_doc=None, args=None):
|
||||
qty = item_row.qty
|
||||
if frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice"):
|
||||
qty = item_row.received_qty
|
||||
|
||||
pending_qty = qty - invoiced_qty_map.get(item_row.name, 0)
|
||||
|
||||
if frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice"):
|
||||
return pending_qty, 0
|
||||
|
||||
returned_qty = flt(returned_qty_map.get(item_row.name, 0))
|
||||
if returned_qty:
|
||||
if returned_qty >= pending_qty:
|
||||
@@ -1172,6 +1177,7 @@ def make_purchase_invoice(source_name, target_doc=None, args=None):
|
||||
else:
|
||||
pending_qty -= returned_qty
|
||||
returned_qty = 0
|
||||
|
||||
return pending_qty, returned_qty
|
||||
|
||||
doclist = get_mapped_doc(
|
||||
|
||||
@@ -895,6 +895,8 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
create_purchase_order,
|
||||
)
|
||||
|
||||
frappe.db.set_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", 0)
|
||||
|
||||
po = create_purchase_order()
|
||||
pr = create_pr_against_po(po.name)
|
||||
|
||||
@@ -914,6 +916,7 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
po.cancel()
|
||||
|
||||
def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self):
|
||||
frappe.db.set_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", 0)
|
||||
pr1 = make_purchase_receipt(qty=8, do_not_submit=True)
|
||||
pr1.append(
|
||||
"items",
|
||||
@@ -2783,6 +2786,40 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
|
||||
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)
|
||||
|
||||
def test_purchase_receipt_bill_for_rejected_quantity_in_purchase_invoice(self):
|
||||
item_code = make_item(
|
||||
"_Test Purchase Receipt Bill For Rejected Quantity",
|
||||
properties={"is_stock_item": 1},
|
||||
).name
|
||||
|
||||
pr = make_purchase_receipt(item_code=item_code, qty=5, rate=100)
|
||||
|
||||
return_pr = make_purchase_receipt(
|
||||
item_code=item_code,
|
||||
is_return=1,
|
||||
return_against=pr.name,
|
||||
qty=-2,
|
||||
do_not_submit=1,
|
||||
)
|
||||
return_pr.items[0].purchase_receipt_item = pr.items[0].name
|
||||
return_pr.submit()
|
||||
old_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)
|
||||
pi = make_purchase_invoice(pr.name)
|
||||
self.assertEqual(pi.items[0].qty, 3)
|
||||
|
||||
frappe.db.set_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", 1)
|
||||
pi = make_purchase_invoice(pr.name)
|
||||
pi.submit()
|
||||
self.assertEqual(pi.items[0].qty, 5)
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", old_value
|
||||
)
|
||||
|
||||
|
||||
def prepare_data_for_internal_transfer():
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||
|
||||
Reference in New Issue
Block a user