Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 1 | ## temp utility |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 2 | |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 3 | from contextlib import contextmanager |
| 4 | |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 5 | import frappe |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 6 | from frappe import _ |
Saurabh | f4ee682 | 2017-05-16 08:30:27 +0530 | [diff] [blame] | 7 | from frappe.utils import cstr |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 8 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 9 | from erpnext.utilities.activation import get_level |
| 10 | |
| 11 | |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 12 | def update_doctypes(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 13 | for d in frappe.db.sql( |
| 14 | """select df.parent, df.fieldname |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 15 | from tabDocField df, tabDocType dt where df.fieldname |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 16 | like "%description%" and df.parent = dt.name and dt.istable = 1""", |
| 17 | as_dict=1, |
| 18 | ): |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 19 | dt = frappe.get_doc("DocType", d.parent) |
| 20 | |
| 21 | for f in dt.fields: |
| 22 | if f.fieldname == d.fieldname and f.fieldtype in ("Text", "Small Text"): |
Rushabh Mehta | 81e9d4e | 2015-08-19 13:00:03 +0530 | [diff] [blame] | 23 | f.fieldtype = "Text Editor" |
| 24 | dt.save() |
| 25 | break |
Anand Doshi | f576f3b | 2016-06-25 19:51:48 +0530 | [diff] [blame] | 26 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 27 | |
Anand Doshi | f576f3b | 2016-06-25 19:51:48 +0530 | [diff] [blame] | 28 | def get_site_info(site_info): |
| 29 | # called via hook |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 30 | company = frappe.db.get_single_value("Global Defaults", "default_company") |
Anand Doshi | f576f3b | 2016-06-25 19:51:48 +0530 | [diff] [blame] | 31 | domain = None |
| 32 | |
| 33 | if not company: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 34 | company = frappe.db.sql("select name from `tabCompany` order by creation asc") |
Anand Doshi | f576f3b | 2016-06-25 19:51:48 +0530 | [diff] [blame] | 35 | company = company[0][0] if company else None |
| 36 | |
| 37 | if company: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 38 | domain = frappe.get_cached_value("Company", cstr(company), "domain") |
Anand Doshi | f576f3b | 2016-06-25 19:51:48 +0530 | [diff] [blame] | 39 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 40 | return {"company": company, "domain": domain, "activation": get_level()} |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 41 | |
| 42 | |
| 43 | @contextmanager |
| 44 | def payment_app_import_guard(): |
| 45 | marketplace_link = '<a href="https://frappecloud.com/marketplace/apps/payments">Marketplace</a>' |
| 46 | github_link = '<a href="https://github.com/frappe/payments/">GitHub</a>' |
| 47 | msg = _("payments app is not installed. Please install it from {} or {}").format( |
| 48 | marketplace_link, github_link |
| 49 | ) |
| 50 | try: |
| 51 | yield |
| 52 | except ImportError: |
| 53 | frappe.throw(msg, title=_("Missing Payments App")) |