refactor(user): cleaner code in send_password_notification

Small refactor for cleaner code.

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
This commit is contained in:
AarDG10 2026-03-02 11:17:09 +05:30
parent fd40eef2d3
commit 503150f99f

View file

@ -447,23 +447,24 @@ class User(Document):
def send_password_notification(self, new_password): def send_password_notification(self, new_password):
try: try:
if self.flags.in_insert: if self.flags.in_insert:
if self.name not in STANDARD_USERS: if self.name in STANDARD_USERS:
if new_password: return
# new password given, no email required if new_password:
_update_password( # new password given, no email required
user=self.name, pwd=new_password, logout_all_sessions=self.logout_all_sessions _update_password(
) user=self.name, pwd=new_password, logout_all_sessions=self.logout_all_sessions
)
if ( if (
not self.flags.no_welcome_mail not self.flags.no_welcome_mail
and cint(self.send_welcome_email) and cint(self.send_welcome_email)
and not self.flags.email_sent and not self.flags.email_sent
): ):
self.send_welcome_mail_to_user() self.send_welcome_mail_to_user()
self.flags.email_sent = 1 self.flags.email_sent = 1
if frappe.session.user != "Guest": if frappe.session.user != "Guest":
msgprint(_("Welcome email sent")) msgprint(_("Welcome email sent"))
return return
else: else:
self.set_new_password(new_password) self.set_new_password(new_password)