fix: fallback to Personal Email for user creation just like client-side

(cherry picked from commit 31af13a5e6)
This commit is contained in:
Rucha Mahabal
2026-03-23 15:31:51 +05:30
committed by Mergify
parent 3023302700
commit 553bc87ac7
2 changed files with 8 additions and 8 deletions

View File

@@ -43,8 +43,8 @@
"contact_details", "contact_details",
"cell_number", "cell_number",
"column_break_40", "column_break_40",
"personal_email",
"company_email", "company_email",
"personal_email",
"column_break4", "column_break4",
"prefered_contact_email", "prefered_contact_email",
"prefered_email", "prefered_email",
@@ -298,7 +298,7 @@
{ {
"default": "0", "default": "0",
"depends_on": "eval:doc.__islocal && !doc.user_id", "depends_on": "eval:doc.__islocal && !doc.user_id",
"description": "This will create User for this employee depending on the Company Email.", "description": "Creates a User account for this employee using the Preferred, Company, or Personal email.",
"fieldname": "create_user_automatically", "fieldname": "create_user_automatically",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Create User Automatically", "label": "Create User Automatically",
@@ -834,7 +834,7 @@
"image_field": "image", "image_field": "image",
"is_tree": 1, "is_tree": 1,
"links": [], "links": [],
"modified": "2026-03-23 14:05:42.144641", "modified": "2026-03-23 15:26:05.149280",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Employee", "name": "Employee",

View File

@@ -161,11 +161,11 @@ class Employee(NestedSet):
self.validate_duplicate_user_id() self.validate_duplicate_user_id()
def validate_auto_user_creation(self): def validate_auto_user_creation(self):
if self.create_user_automatically and not (self.prefered_email or self.company_email): if self.create_user_automatically and not (
self.prefered_email or self.company_email or self.personal_email
):
frappe.throw( frappe.throw(
_( _("Company or Personal Email is mandatory when 'Create User Automatically' is enabled"),
"Company Email or Preferred Email is mandatory when 'Create User Automatically' is enabled"
),
frappe.MandatoryError, frappe.MandatoryError,
title=_("Auto User Creation Error"), title=_("Auto User Creation Error"),
) )
@@ -193,7 +193,7 @@ class Employee(NestedSet):
create_user( create_user(
employee=self.name, employee=self.name,
email=self.prefered_email or self.company_email, email=self.prefered_email or self.company_email or self.personal_email,
create_user_permission=self.create_user_permission, create_user_permission=self.create_user_permission,
) )