From 5bac652b5fc8d3196a4e238b8ca60daea34df96a Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 19 May 2025 22:53:03 +0530 Subject: [PATCH] fix: GL entries for rejected returned materials (#47612) (cherry picked from commit 3e098da01f2a4f585830fc683b2b2f2ee6f4159f) --- erpnext/controllers/buying_controller.py | 3 ++- .../stock/doctype/purchase_receipt/purchase_receipt.py | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 055b09c2d31..4e726333a7f 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -670,7 +670,8 @@ class BuyingController(SubcontractingController): "actual_qty": flt( flt(d.rejected_qty) * flt(d.conversion_factor), d.precision("stock_qty") ), - "incoming_rate": valuation_rate_for_rejected_item, + "incoming_rate": valuation_rate_for_rejected_item if not self.is_return else 0.0, + "outgoing_rate": valuation_rate_for_rejected_item if self.is_return else 0.0, "serial_and_batch_bundle": d.rejected_serial_and_batch_bundle, }, ) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 903a216d9db..c8c81c2a124 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -499,9 +499,7 @@ class PurchaseReceipt(BuyingController): if item.get("rejected_qty") and frappe.db.get_single_value( "Buying Settings", "set_valuation_rate_for_rejected_materials" ): - outgoing_amount += abs( - get_stock_value_difference(self.name, item.name, item.rejected_warehouse) - ) + outgoing_amount += get_stock_value_difference(self.name, item.name, item.rejected_warehouse) credit_amount = outgoing_amount if credit_amount: @@ -640,9 +638,7 @@ class PurchaseReceipt(BuyingController): if item.get("rejected_qty") and frappe.db.get_single_value( "Buying Settings", "set_valuation_rate_for_rejected_materials" ): - rejected_item_cost = abs( - get_stock_value_difference(self.name, item.name, item.rejected_warehouse) - ) + rejected_item_cost = get_stock_value_difference(self.name, item.name, item.rejected_warehouse) divisional_loss -= rejected_item_cost if divisional_loss: