mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-17 02:26:33 +00:00
fix(assets): discard stale set_finance_book responses
Rapid successive edits to Net Purchase Amount could fire overlapping
set_finance_book calls; if an older request's response arrived after a
newer one, it could overwrite Finance Books with values computed from
a stale amount. Now the callback only applies a response if the fields
it was based on still match the form's current values.
(cherry picked from commit 5a8126412a)
This commit is contained in:
@@ -546,15 +546,25 @@ frappe.ui.form.on("Asset", {
|
||||
},
|
||||
|
||||
set_finance_book: function (frm) {
|
||||
// Snapshot the fields this request is based on, so a stale response from an
|
||||
// earlier, still-in-flight call (e.g. from rapid successive amount edits)
|
||||
// can't overwrite Finance Books with values computed from an old amount.
|
||||
let item_code = frm.doc.item_code;
|
||||
let net_purchase_amount = frm.doc.net_purchase_amount;
|
||||
|
||||
frappe.call({
|
||||
method: "erpnext.assets.doctype.asset.asset.get_item_details",
|
||||
args: {
|
||||
item_code: frm.doc.item_code,
|
||||
item_code: item_code,
|
||||
asset_category: frm.doc.asset_category,
|
||||
net_purchase_amount: frm.doc.net_purchase_amount,
|
||||
net_purchase_amount: net_purchase_amount,
|
||||
},
|
||||
callback: function (r, rt) {
|
||||
if (r.message) {
|
||||
if (
|
||||
r.message &&
|
||||
frm.doc.item_code === item_code &&
|
||||
frm.doc.net_purchase_amount === net_purchase_amount
|
||||
) {
|
||||
frm.set_value("finance_books", r.message);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user