mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
refactor: fetch employee contact details in realtime
This commit is contained in:
@@ -493,12 +493,16 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
frm.set_value("contact_email", "");
|
frm.set_value("contact_email", "");
|
||||||
frm.set_value("contact_person", "");
|
frm.set_value("contact_person", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frm.doc.payment_type && frm.doc.party_type && frm.doc.party && frm.doc.company) {
|
if (frm.doc.payment_type && frm.doc.party_type && frm.doc.party && frm.doc.company) {
|
||||||
if (!frm.doc.posting_date) {
|
if (!frm.doc.posting_date) {
|
||||||
frappe.msgprint(__("Please select Posting Date before selecting Party"));
|
frappe.msgprint(__("Please select Posting Date before selecting Party"));
|
||||||
frm.set_value("party", "");
|
frm.set_value("party", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.utils.get_employee_contact_details(frm);
|
||||||
|
|
||||||
frm.set_party_account_based_on_party = true;
|
frm.set_party_account_based_on_party = true;
|
||||||
|
|
||||||
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
|
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
|
||||||
|
|||||||
@@ -293,37 +293,49 @@ erpnext.utils.set_taxes = function (frm, triggered_from_field) {
|
|||||||
erpnext.utils.get_contact_details = function (frm) {
|
erpnext.utils.get_contact_details = function (frm) {
|
||||||
if (frm.updating_party_details) return;
|
if (frm.updating_party_details) return;
|
||||||
|
|
||||||
if (frm.doc["contact_person"]) {
|
if (!frm.doc.contact_person) {
|
||||||
frappe.call({
|
reset_contact_fields(frm);
|
||||||
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
return;
|
||||||
args: { contact: frm.doc.contact_person },
|
|
||||||
callback: function (r) {
|
|
||||||
if (r.message) frm.set_value(r.message);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
frm.set_value({
|
|
||||||
contact_person: "",
|
|
||||||
contact_display: "",
|
|
||||||
contact_email: "",
|
|
||||||
contact_mobile: "",
|
|
||||||
contact_phone: "",
|
|
||||||
contact_designation: "",
|
|
||||||
contact_department: "",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
erpnext.utils.get_employee_contact_details = async function (employee) {
|
frappe.call({
|
||||||
if (!employee) return;
|
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
||||||
|
args: { contact: frm.doc.contact_person },
|
||||||
const response = await frappe.xcall("erpnext.setup.doctype.employee.employee.get_contact_details", {
|
callback: function (r) {
|
||||||
employee,
|
if (r.message) frm.set_value(r.message);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return response?.message;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
erpnext.utils.get_employee_contact_details = function (frm) {
|
||||||
|
if (frm.updating_party_details || frm.doc.party_type !== "Employee") return;
|
||||||
|
|
||||||
|
if (!frm.doc.party) {
|
||||||
|
reset_contact_fields(frm);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.setup.doctype.employee.employee.get_contact_details",
|
||||||
|
args: { employee: frm.doc.party },
|
||||||
|
callback: function (r) {
|
||||||
|
if (r.message) frm.set_value(r.message);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function reset_contact_fields(frm) {
|
||||||
|
frm.set_value({
|
||||||
|
contact_person: "",
|
||||||
|
contact_display: "",
|
||||||
|
contact_email: "",
|
||||||
|
contact_mobile: "",
|
||||||
|
contact_phone: "",
|
||||||
|
contact_designation: "",
|
||||||
|
contact_department: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
erpnext.utils.validate_mandatory = function (frm, label, value, trigger_on) {
|
erpnext.utils.validate_mandatory = function (frm, label, value, trigger_on) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
frm.doc[trigger_on] = "";
|
frm.doc[trigger_on] = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user