de-duplicate email account name
This commit is contained in:
parent
6b1640d795
commit
6d41379fc4
2 changed files with 14 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ from frappe.email.receive import POP3Server, Email
|
|||
from poplib import error_proto
|
||||
import markdown2
|
||||
from datetime import datetime, timedelta
|
||||
from frappe.model.naming import de_duplicate
|
||||
|
||||
class EmailAccount(Document):
|
||||
def autoname(self):
|
||||
|
|
@ -22,7 +23,8 @@ class EmailAccount(Document):
|
|||
if self.service:
|
||||
self.email_account_name = self.email_account_name + " " + self.service
|
||||
|
||||
self.name = self.email_account_name
|
||||
# if same email address is used for different Email Account settings, append a number like account_name-1
|
||||
self.name = de_duplicate("Email Account", self.email_account_name)
|
||||
|
||||
def validate(self):
|
||||
"""Validate email id and check POP3 and SMTP connections is enabled."""
|
||||
|
|
|
|||
|
|
@ -186,3 +186,14 @@ def append_number_if_name_exists(doc):
|
|||
|
||||
doc.name = "{0}-{1}".format(doc.name, count)
|
||||
|
||||
def de_duplicate(doctype, name):
|
||||
original_name = name
|
||||
count = 0
|
||||
while True:
|
||||
if frappe.db.exists(doctype, name):
|
||||
count += 1
|
||||
name = "{0}-{1}".format(original_name, count)
|
||||
else:
|
||||
break
|
||||
|
||||
return name
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue