fix: purchase return from rejected warehouse (backport #42531) (#42535)

fix: purchase return from rejected warehouse (#42531)

(cherry picked from commit c5d68333c9)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-07-30 14:53:42 +05:30
committed by GitHub
parent 826577c88f
commit b7d70ac928
2 changed files with 17 additions and 0 deletions

View File

@@ -640,6 +640,12 @@ def make_return_doc(doctype: str, source_name: str, target_doc=None, return_agai
def update_terms(source_doc, target_doc, source_parent):
target_doc.payment_amount = -source_doc.payment_amount
def item_condition(doc):
if return_against_rejected_qty:
return doc.rejected_qty
return doc.qty
doclist = get_mapped_doc(
doctype,
source_name,
@@ -654,6 +660,7 @@ def make_return_doc(doctype: str, source_name: str, target_doc=None, return_agai
"doctype": doctype + " Item",
"field_map": {"serial_no": "serial_no", "batch_no": "batch_no", "bom": "bom"},
"postprocess": update_item,
"condition": item_condition,
},
"Payment Schedule": {"doctype": "Payment Schedule", "postprocess": update_terms},
},

View File

@@ -1886,9 +1886,19 @@ class TestPurchaseReceipt(FrappeTestCase):
rate=100,
rejected_qty=2,
rejected_warehouse=rejected_warehouse,
do_not_save=1,
)
pr.append(
"items",
{"item_code": item_code, "qty": 2, "rate": 100, "warehouse": warehouse, "rejected_qty": 0},
)
pr.save()
pr.submit()
self.assertEqual(len(pr.items), 2)
pr_return = make_purchase_return_against_rejected_warehouse(pr.name)
self.assertEqual(len(pr_return.items), 1)
self.assertEqual(pr_return.items[0].warehouse, rejected_warehouse)
self.assertEqual(pr_return.items[0].qty, 2.0 * -1)
self.assertEqual(pr_return.items[0].rejected_qty, 0.0)