Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

80 wiersze
2.5 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. def sendmail_to_system_managers(subject, content):
  6. frappe.sendmail(recipients=get_system_managers(), subject=subject, content=content)
  7. @frappe.whitelist()
  8. def get_contact_list(txt):
  9. """Returns contacts (from autosuggest)"""
  10. txt = txt.replace('%', '')
  11. def get_users():
  12. return filter(None, frappe.db.sql_list('select email from tabUser where email like %s',
  13. ('%' + txt + '%')))
  14. try:
  15. out = filter(None, frappe.db.sql_list("""select distinct email_id from `tabContact`
  16. where email_id like %(txt)s or concat(first_name, " ", last_name) like %(txt)s order by
  17. if (locate( %(_txt)s, concat(first_name, " ", last_name)), locate( %(_txt)s, concat(first_name, " ", last_name)), 99999),
  18. if (locate( %(_txt)s, email_id), locate( %(_txt)s, email_id), 99999)""",
  19. {'txt': "%%%s%%" % frappe.db.escape(txt),
  20. '_txt': txt.replace("%", "")
  21. })
  22. )
  23. if not out:
  24. out = get_users()
  25. except Exception, e:
  26. if e.args[0]==1146:
  27. # no Contact, use User
  28. out = get_users()
  29. else:
  30. raise
  31. return out
  32. def get_system_managers():
  33. return frappe.db.sql_list("""select parent FROM tabUserRole
  34. WHERE role='System Manager'
  35. AND parent!='Administrator'
  36. AND parent IN (SELECT email FROM tabUser WHERE enabled=1)""")
  37. @frappe.whitelist()
  38. def relink(name, reference_doctype=None, reference_name=None):
  39. frappe.db.sql("""update
  40. `tabCommunication`
  41. set
  42. reference_doctype = %s,
  43. reference_name = %s,
  44. status = "Linked"
  45. where
  46. communication_type = "Communication" and
  47. name = %s""", (reference_doctype, reference_name, name))
  48. def get_communication_doctype(doctype, txt, searchfield, start, page_len, filters):
  49. user_perms = frappe.utils.user.UserPermissions(frappe.session.user)
  50. user_perms.build_permissions()
  51. can_read = user_perms.can_read
  52. from frappe.modules import load_doctype_module
  53. com_doctypes = []
  54. if len(txt)<2:
  55. for name in ["Customer", "Supplier"]:
  56. try:
  57. module = load_doctype_module(name, suffix='_dashboard')
  58. if hasattr(module, 'get_data'):
  59. for i in module.get_data()['transactions']:
  60. com_doctypes += i["items"]
  61. except ImportError:
  62. pass
  63. else:
  64. com_doctypes = [d[0] for d in frappe.db.get_values("DocType", {"issingle": 0, "istable": 0, "hide_toolbar": 0})]
  65. out = []
  66. for dt in com_doctypes:
  67. if txt.lower().replace("%", "") in dt.lower() and dt in can_read:
  68. out.append([dt])
  69. return out