mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 17:53:49 +00:00
fix(asset): properly reset purchase reference and item fields
(cherry picked from commit 671610db1e)
This commit is contained in:
@@ -235,28 +235,64 @@ frappe.ui.form.on("Asset", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggle_reference_doc: function (frm) {
|
toggle_reference_doc: function (frm) {
|
||||||
if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) {
|
const is_submitted = frm.doc.docstatus === 1;
|
||||||
frm.set_df_property("purchase_invoice", "read_only", 1);
|
const is_special_asset = frm.doc.is_existing_asset || frm.doc.is_composite_asset;
|
||||||
frm.set_df_property("purchase_receipt", "read_only", 1);
|
|
||||||
} else if (frm.doc.is_existing_asset || frm.doc.is_composite_asset) {
|
const clear_field = (field) => {
|
||||||
frm.toggle_reqd("purchase_receipt", 0);
|
if (frm.doc[field]) {
|
||||||
frm.toggle_reqd("purchase_invoice", 0);
|
frm.set_value(field, "");
|
||||||
frm.set_value("purchase_receipt", "");
|
}
|
||||||
frm.set_value("purchase_invoice", "");
|
};
|
||||||
} else if (frm.doc.purchase_receipt) {
|
|
||||||
// if purchase receipt link is set then set PI disabled
|
["purchase_receipt", "purchase_receipt_item", "purchase_invoice", "purchase_invoice_item"].forEach(
|
||||||
frm.toggle_reqd("purchase_invoice", 0);
|
(field) => {
|
||||||
frm.set_df_property("purchase_invoice", "read_only", 1);
|
frm.toggle_reqd(field, 0);
|
||||||
} else if (frm.doc.purchase_invoice) {
|
frm.set_df_property(field, "read_only", 0);
|
||||||
// if purchase invoice link is set then set PR disabled
|
}
|
||||||
frm.toggle_reqd("purchase_receipt", 0);
|
);
|
||||||
frm.set_df_property("purchase_receipt", "read_only", 1);
|
|
||||||
} else {
|
if (is_submitted) {
|
||||||
frm.toggle_reqd("purchase_receipt", 1);
|
[
|
||||||
frm.set_df_property("purchase_receipt", "read_only", 0);
|
"purchase_receipt",
|
||||||
frm.toggle_reqd("purchase_invoice", 1);
|
"purchase_receipt_item",
|
||||||
frm.set_df_property("purchase_invoice", "read_only", 0);
|
"purchase_invoice",
|
||||||
|
"purchase_invoice_item",
|
||||||
|
].forEach((field) => {
|
||||||
|
frm.set_df_property(field, "read_only", 1);
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_special_asset) {
|
||||||
|
clear_field("purchase_receipt");
|
||||||
|
clear_field("purchase_receipt_item");
|
||||||
|
clear_field("purchase_invoice");
|
||||||
|
clear_field("purchase_invoice_item");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frm.doc.purchase_receipt) {
|
||||||
|
frm.toggle_reqd("purchase_receipt_item", 1);
|
||||||
|
|
||||||
|
["purchase_invoice", "purchase_invoice_item"].forEach((field) => {
|
||||||
|
clear_field(field);
|
||||||
|
frm.set_df_property(field, "read_only", 1);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frm.doc.purchase_invoice) {
|
||||||
|
frm.toggle_reqd("purchase_invoice_item", 1);
|
||||||
|
|
||||||
|
["purchase_receipt", "purchase_receipt_item"].forEach((field) => {
|
||||||
|
clear_field(field);
|
||||||
|
frm.set_df_property(field, "read_only", 1);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
frm.toggle_reqd("purchase_receipt", 1);
|
||||||
|
frm.toggle_reqd("purchase_invoice", 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
make_journal_entry: function (frm) {
|
make_journal_entry: function (frm) {
|
||||||
|
|||||||
Reference in New Issue
Block a user