mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-23 12:06:43 +00:00
fix: repost read stale sibling SLE rate for moving average returns
During repost, a return line with recalculate_rate resolved its moving average rate through get_incoming_rate -> get_previous_sle, which matches posting_datetime <= and orders by creation desc. For a multi-line return of the same item, every line shares one posting_datetime, so the query landed on a sibling line of the same voucher whose stored valuation_rate was still the previous repost run's output, not the rate before the voucher. Each repost run therefore re-seeded the voucher from its own prior output. The error gain per run is (qty returned at the stale rate) / (qty remaining after the return), so whenever a return removes most of the stock the loop diverges instead of converging, alternating sign and growing until stock_value overflows decimal(21,9) and the repost dies with 'Out of range value for column stock_value'. Use the in-memory running valuation rate that update_entries_after already tracks for the warehouse at this point in the repost. It is the authoritative pre-entry state, is immune to sibling rows, and makes the repost idempotent. The database lookup is kept only as a fallback for a zero in-memory rate, preserving the existing zero-rate fallback chain.
This commit is contained in:
@@ -1301,6 +1301,8 @@ class update_entries_after:
|
|||||||
and not sle.get("batch_no")
|
and not sle.get("batch_no")
|
||||||
and not sle.get("serial_and_batch_bundle")
|
and not sle.get("serial_and_batch_bundle")
|
||||||
):
|
):
|
||||||
|
rate = flt(self.wh_data.valuation_rate)
|
||||||
|
if not rate:
|
||||||
rate = get_incoming_rate(
|
rate = get_incoming_rate(
|
||||||
{
|
{
|
||||||
"item_code": sle.item_code,
|
"item_code": sle.item_code,
|
||||||
|
|||||||
Reference in New Issue
Block a user