From 53e77921cd6b12017e0a6f5a27106bb0ba06eae5 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:38:09 +0200 Subject: [PATCH] feat: set the only email address as primary Some features rely on the Contact having the primary email set. If the Contact has only one email address, we can mark it as primary automatically. Only if there are more than one addresses available, the user has to choose which one should be set as primary. (cherry picked from commit be90d5556e6a4551d91c727e35b34a0112681ba1) --- frappe/contacts/doctype/contact/contact.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frappe/contacts/doctype/contact/contact.py b/frappe/contacts/doctype/contact/contact.py index 82713bf7690..9b8311118e0 100644 --- a/frappe/contacts/doctype/contact/contact.py +++ b/frappe/contacts/doctype/contact/contact.py @@ -91,6 +91,9 @@ def set_primary_email(self): if len([email.email_id for email in self.email_ids if email.is_primary]) > 1: frappe.throw(_("Only one {0} can be set as primary.").format(frappe.bold("Email ID"))) + if len(self.email_ids) == 1: + self.email_ids[0].is_primary = 1 + primary_email_exists = False for d in self.email_ids: if d.is_primary == 1: