[minor] deduplicate dynamic links
This commit is contained in:
parent
f5bbf96fd3
commit
d0ee7d3f0d
3 changed files with 19 additions and 0 deletions
|
|
@ -11,3 +11,17 @@ class DynamicLink(Document):
|
|||
|
||||
def on_doctype_update():
|
||||
frappe.db.add_index("Dynamic Link", ["link_doctype", "link_name"])
|
||||
|
||||
def deduplicate_dynamic_links(doc):
|
||||
links, duplicate = [], False
|
||||
for l in doc.links:
|
||||
t = (l.link_doctype, l.link_name)
|
||||
if not t in links:
|
||||
links.append(t)
|
||||
else:
|
||||
duplicate = True
|
||||
|
||||
if duplicate:
|
||||
doc.links = []
|
||||
for l in links:
|
||||
doc.append('links', dict(link_doctype=l[0], link_name=l[1]))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import frappe
|
|||
from frappe.utils import cstr, has_gravatar
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
|
||||
|
||||
class Contact(Document):
|
||||
def autoname(self):
|
||||
|
|
@ -23,6 +24,8 @@ class Contact(Document):
|
|||
if self.email_id:
|
||||
self.image = has_gravatar(self.email_id)
|
||||
|
||||
deduplicate_dynamic_links(self)
|
||||
|
||||
def set_user(self):
|
||||
if not self.user and self.email_id:
|
||||
self.user = frappe.db.get_value("User", {"email": self.email_id})
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from frappe.model.document import Document
|
|||
from jinja2 import TemplateSyntaxError
|
||||
from frappe.utils.user import is_website_user
|
||||
from frappe.model.naming import make_autoname
|
||||
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
|
||||
|
||||
class Address(Document):
|
||||
def __setup__(self):
|
||||
|
|
@ -33,6 +34,7 @@ class Address(Document):
|
|||
def validate(self):
|
||||
self.link_address()
|
||||
self.validate_reference()
|
||||
deduplicate_dynamic_links(self)
|
||||
|
||||
def link_address(self):
|
||||
"""Link address based on owner"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue