mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-12 11:25:09 +00:00
Merge pull request #52899 from frappe/mergify/bp/version-15-hotfix/pr-50301
This commit is contained in:
@@ -516,12 +516,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;
|
||||
|
||||
@@ -7,18 +7,16 @@ from frappe import _, msgprint, qb, scrub
|
||||
from frappe.contacts.doctype.address.address import get_company_address, get_default_address
|
||||
from frappe.core.doctype.user_permission.user_permission import get_permitted_documents
|
||||
from frappe.model.utils import get_fetch_values
|
||||
from frappe.query_builder.functions import Abs, Count, Date, Sum
|
||||
from frappe.query_builder.functions import Abs, Date, Sum
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
add_months,
|
||||
add_years,
|
||||
cint,
|
||||
cstr,
|
||||
date_diff,
|
||||
flt,
|
||||
formatdate,
|
||||
get_last_day,
|
||||
get_timestamp,
|
||||
getdate,
|
||||
nowdate,
|
||||
)
|
||||
@@ -302,19 +300,9 @@ def complete_contact_details(party_details):
|
||||
contact_details = frappe._dict()
|
||||
|
||||
if party_details.party_type == "Employee":
|
||||
contact_details = frappe.db.get_value(
|
||||
"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,
|
||||
)
|
||||
from erpnext.setup.doctype.employee.employee import _get_contact_details as get_employee_contact
|
||||
|
||||
contact_details = get_employee_contact(party_details.party)
|
||||
contact_details.update({"contact_person": None, "contact_phone": None})
|
||||
elif party_details.contact_person:
|
||||
contact_details = frappe.db.get_value(
|
||||
|
||||
@@ -293,27 +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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (!value) {
|
||||
frm.doc[trigger_on] = "";
|
||||
|
||||
@@ -436,3 +436,59 @@ def has_upload_permission(doc, ptype="read", user=None):
|
||||
if get_doc_permissions(doc, user=user, ptype=ptype).get(ptype):
|
||||
return True
|
||||
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