mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-27 00:26:03 +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_person", "");
|
||||
}
|
||||
|
||||
if (frm.doc.payment_type && frm.doc.party_type && frm.doc.party && frm.doc.company) {
|
||||
if (!frm.doc.posting_date) {
|
||||
frappe.msgprint(__("Please select Posting Date before selecting Party"));
|
||||
frm.set_value("party", "");
|
||||
return;
|
||||
}
|
||||
|
||||
erpnext.utils.get_employee_contact_details(frm);
|
||||
|
||||
frm.set_party_account_based_on_party = true;
|
||||
|
||||
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) {
|
||||
if (frm.updating_party_details) return;
|
||||
|
||||
if (frm.doc["contact_person"]) {
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
||||
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: "",
|
||||
});
|
||||
if (!frm.doc.contact_person) {
|
||||
reset_contact_fields(frm);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
erpnext.utils.get_employee_contact_details = async function (employee) {
|
||||
if (!employee) return;
|
||||
|
||||
const response = await frappe.xcall("erpnext.setup.doctype.employee.employee.get_contact_details", {
|
||||
employee,
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
||||
args: { contact: frm.doc.contact_person },
|
||||
callback: function (r) {
|
||||
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) {
|
||||
if (!value) {
|
||||
frm.doc[trigger_on] = "";
|
||||
|
||||
Reference in New Issue
Block a user