mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 15:12:51 +00:00
Merge pull request #50301 from Abdeali099/fixing-emp-contacts
This commit is contained in:
@@ -512,12 +512,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;
|
||||||
|
|||||||
@@ -296,19 +296,9 @@ def complete_contact_details(party_details):
|
|||||||
contact_details = frappe._dict()
|
contact_details = frappe._dict()
|
||||||
|
|
||||||
if party_details.party_type == "Employee":
|
if party_details.party_type == "Employee":
|
||||||
contact_details = frappe.db.get_value(
|
from erpnext.setup.doctype.employee.employee import _get_contact_details as get_employee_contact
|
||||||
"Employee",
|
|
||||||
party_details.party,
|
|
||||||
[
|
|
||||||
"employee_name as contact_display",
|
|
||||||
"prefered_email as contact_email",
|
|
||||||
"cell_number as contact_mobile",
|
|
||||||
"designation as contact_designation",
|
|
||||||
"department as contact_department",
|
|
||||||
],
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
contact_details = get_employee_contact(party_details.party)
|
||||||
contact_details.update({"contact_person": None, "contact_phone": None})
|
contact_details.update({"contact_person": None, "contact_phone": None})
|
||||||
elif party_details.contact_person:
|
elif party_details.contact_person:
|
||||||
contact_details = frappe.db.get_value(
|
contact_details = frappe.db.get_value(
|
||||||
|
|||||||
@@ -294,27 +294,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: "",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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] = "";
|
||||||
|
|||||||
@@ -428,3 +428,59 @@ def has_upload_permission(doc, ptype="read", user=None):
|
|||||||
if get_doc_permissions(doc, user=user, ptype=ptype).get(ptype):
|
if get_doc_permissions(doc, user=user, ptype=ptype).get(ptype):
|
||||||
return True
|
return True
|
||||||
return doc.user_id == user
|
return doc.user_id == user
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_contact_details(employee: str) -> dict:
|
||||||
|
"""
|
||||||
|
Returns basic contact details for the given employee.
|
||||||
|
|
||||||
|
Email is selected based on the following priority:
|
||||||
|
1. Prefered Email
|
||||||
|
2. Company Email
|
||||||
|
3. Personal Email
|
||||||
|
4. User ID
|
||||||
|
"""
|
||||||
|
if not employee:
|
||||||
|
frappe.throw(msg=_("Employee is required"), title=_("Missing Parameter"))
|
||||||
|
|
||||||
|
frappe.has_permission("Employee", "read", employee, throw=True)
|
||||||
|
|
||||||
|
return _get_contact_details(employee)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_contact_details(employee: str) -> dict:
|
||||||
|
contact_data = frappe.db.get_value(
|
||||||
|
"Employee",
|
||||||
|
employee,
|
||||||
|
[
|
||||||
|
"employee_name",
|
||||||
|
"prefered_email",
|
||||||
|
"company_email",
|
||||||
|
"personal_email",
|
||||||
|
"user_id",
|
||||||
|
"cell_number",
|
||||||
|
"designation",
|
||||||
|
"department",
|
||||||
|
],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not contact_data:
|
||||||
|
frappe.throw(msg=_("Employee {0} not found").format(employee), title=_("Not Found"))
|
||||||
|
|
||||||
|
# Email with priority
|
||||||
|
employee_email = (
|
||||||
|
contact_data.get("prefered_email")
|
||||||
|
or contact_data.get("company_email")
|
||||||
|
or contact_data.get("personal_email")
|
||||||
|
or contact_data.get("user_id")
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"contact_display": contact_data.get("employee_name"),
|
||||||
|
"contact_email": employee_email,
|
||||||
|
"contact_mobile": contact_data.get("cell_number"),
|
||||||
|
"contact_designation": contact_data.get("designation"),
|
||||||
|
"contact_department": contact_data.get("department"),
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user