您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

__init__.py 1.4 KiB

2 年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ## temp utility
  2. from contextlib import contextmanager
  3. import frappe
  4. from frappe import _
  5. from frappe.utils import cstr
  6. from erpnext.utilities.activation import get_level
  7. def update_doctypes():
  8. for d in frappe.db.sql(
  9. """select df.parent, df.fieldname
  10. from tabDocField df, tabDocType dt where df.fieldname
  11. like "%description%" and df.parent = dt.name and dt.istable = 1""",
  12. as_dict=1,
  13. ):
  14. dt = frappe.get_doc("DocType", d.parent)
  15. for f in dt.fields:
  16. if f.fieldname == d.fieldname and f.fieldtype in ("Text", "Small Text"):
  17. f.fieldtype = "Text Editor"
  18. dt.save()
  19. break
  20. def get_site_info(site_info):
  21. # called via hook
  22. company = frappe.db.get_single_value("Global Defaults", "default_company")
  23. domain = None
  24. if not company:
  25. company = frappe.db.sql("select name from `tabCompany` order by creation asc")
  26. company = company[0][0] if company else None
  27. if company:
  28. domain = frappe.get_cached_value("Company", cstr(company), "domain")
  29. return {"company": company, "domain": domain, "activation": get_level()}
  30. @contextmanager
  31. def payment_app_import_guard():
  32. marketplace_link = '<a href="https://frappecloud.com/marketplace/apps/payments">Marketplace</a>'
  33. github_link = '<a href="https://github.com/frappe/payments/">GitHub</a>'
  34. msg = _("payments app is not installed. Please install it from {} or {}").format(
  35. marketplace_link, github_link
  36. )
  37. try:
  38. yield
  39. except ImportError:
  40. frappe.throw(msg, title=_("Missing Payments App"))