def test_active_domains(self): self.assertTrue("_Test Domain 1" in frappe.get_active_domains()) self.assertFalse("_Test Domain 2" in frappe.get_active_domains()) self.add_active_domain("_Test Domain 2") self.assertTrue("_Test Domain 2" in frappe.get_active_domains()) self.remove_from_active_domains("_Test Domain 1") self.assertTrue("_Test Domain 1" not in frappe.get_active_domains())
def get_doctype_info(module): """Returns list of non child DocTypes for given module.""" active_domains = frappe.get_active_domains() doctype_info = frappe.get_all( "DocType", filters={ "module": module, "istable": 0 }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=[ "'doctype' as type", "name", "description", "document_type", "custom", "issingle" ], order_by="custom asc, document_type desc, name asc") for d in doctype_info: d.document_type = d.document_type or "" d.description = _(d.description or "") return doctype_info
def get_roles_and_doctypes(): frappe.only_for("System Manager") send_translations(frappe.get_lang_dict("doctype", "DocPerm")) active_domains = frappe.get_active_domains() doctypes = frappe.get_all("DocType", filters={ "istable": 0, "name": ("not in", ",".join(not_allowed_in_permission_manager)), }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) roles = frappe.get_all("Role", filters={ "name": ("not in", "Administrator"), "disabled": 0, }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) doctypes_list = [ {"label":_(d.get("name")), "value":d.get("name")} for d in doctypes] roles_list = [ {"label":_(d.get("name")), "value":d.get("name")} for d in roles] return { "doctypes": sorted(doctypes_list, key=lambda d: d['label']), "roles": sorted(roles_list, key=lambda d: d['label']) }
def update_patient_email_and_phone_numbers(contact, method): ''' Hook validate Contact Update linked Patients' primary mobile and phone numbers ''' if 'Healthcare' not in frappe.get_active_domains( ) or contact.flags.skip_patient_update: return if contact.is_primary_contact and (contact.email_id or contact.mobile_no or contact.phone): patient_links = list( filter(lambda link: link.get('link_doctype') == 'Patient', contact.links)) for link in patient_links: contact_details = frappe.db.get_value('Patient', link.get('link_name'), ['email', 'mobile', 'phone'], as_dict=1) new_contact_details = {} if contact.email_id and contact.email_id != contact_details.get( 'email'): new_contact_details.update({'email': contact.email_id}) if contact.mobile_no and contact.mobile_no != contact_details.get( 'mobile'): new_contact_details.update({'mobile': contact.mobile_no}) if contact.phone and contact.phone != contact_details.get('phone'): new_contact_details.update({'phone': contact.phone}) if new_contact_details: frappe.db.set_value('Patient', link.get('link_name'), new_contact_details)
def restrict_roles_and_modules(self): '''Disable all restricted roles and set `restrict_to_domain` property in Module Def''' active_domains = frappe.get_active_domains() all_domains = list((frappe.get_hooks('domains') or {})) def remove_role(role): frappe.db.delete("Has Role", {"role": role}) frappe.set_value('Role', role, 'disabled', 1) for domain in all_domains: data = frappe.get_domain_data(domain) if not frappe.db.get_value('Domain', domain): frappe.get_doc(dict(doctype='Domain', domain=domain)).insert() if 'modules' in data: for module in data.get('modules'): frappe.db.set_value('Module Def', module, 'restrict_to_domain', domain) if 'restricted_roles' in data: for role in data['restricted_roles']: if not frappe.db.get_value('Role', role): frappe.get_doc(dict(doctype='Role', role_name=role)).insert() frappe.db.set_value('Role', role, 'restrict_to_domain', domain) if domain not in active_domains: remove_role(role) if 'custom_fields' in data: if domain not in active_domains: inactive_domain = frappe.get_doc("Domain", domain) inactive_domain.setup_data() inactive_domain.remove_custom_field()
def restrict_roles_and_modules(self): '''Disable all restricted roles and set `restrict_to_domain` property in Module Def''' active_domains = frappe.get_active_domains() all_domains = (frappe.get_hooks('domains') or {}).keys() def remove_role(role): frappe.db.sql('delete from `tabHas Role` where role=%s', role) frappe.set_value('Role', role, 'disabled', 1) for domain in all_domains: data = frappe.get_domain_data(domain) if not frappe.db.get_value('Domain', domain): frappe.get_doc(dict(doctype='Domain', domain=domain)).insert() if 'modules' in data: for module in data.get('modules'): frappe.db.set_value('Module Def', module, 'restrict_to_domain', domain) if 'restricted_roles' in data: for role in data['restricted_roles']: if not frappe.db.get_value('Role', role): frappe.get_doc(dict(doctype='Role', role_name=role)).insert() frappe.db.set_value('Role', role, 'restrict_to_domain', domain) if domain not in active_domains: remove_role(role)
def restrict_roles_and_modules(self): '''Disable all restricted roles and set `restrict_to_domain` property in Module Def''' active_domains = frappe.get_active_domains() all_domains = (frappe.get_hooks('domains') or {}).keys() def remove_role(role): frappe.db.sql('delete from `tabHas Role` where role=%s', role) frappe.set_value('Role', role, 'disabled', 1) for domain in all_domains: domain = _(domain) data = frappe.get_domain_data(domain) if not frappe.db.get_value('Domain', domain): frappe.get_doc(dict(doctype='Domain', domain=domain)).insert() if 'modules' in data: for module in data.get('modules'): frappe.db.set_value('Module Def', module, 'restrict_to_domain', domain) if 'restricted_roles' in data: for role in data['restricted_roles']: if not frappe.db.get_value('Role', role): frappe.get_doc(dict(doctype='Role', role_name=role)).insert() frappe.db.set_value('Role', role, 'restrict_to_domain', domain) if domain not in active_domains: remove_role(role)
def execute(): if "Education" in frappe.get_active_domains() and not frappe.db.exists( "Role", "Guardian"): doc = frappe.new_doc("Role") doc.update({"role_name": "Guardian", "desk_access": 0}) doc.insert(ignore_permissions=True)
def restrict_roles_and_modules(self): """Disable all restricted roles and set `restrict_to_domain` property in Module Def""" active_domains = frappe.get_active_domains() all_domains = list((frappe.get_hooks("domains") or {})) def remove_role(role): frappe.db.sql("delete from `tabHas Role` where role=%s", role) frappe.set_value("Role", role, "disabled", 1) for domain in all_domains: data = frappe.get_domain_data(domain) if not frappe.db.get_value("Domain", domain): frappe.get_doc(dict(doctype="Domain", domain=domain)).insert() if "modules" in data: for module in data.get("modules"): frappe.db.set_value("Module Def", module, "restrict_to_domain", domain) if "restricted_roles" in data: for role in data["restricted_roles"]: if not frappe.db.get_value("Role", role): frappe.get_doc(dict(doctype="Role", role_name=role)).insert() frappe.db.set_value("Role", role, "restrict_to_domain", domain) if domain not in active_domains: remove_role(role) if "custom_fields" in data: if domain not in active_domains: inactive_domain = frappe.get_doc("Domain", domain) inactive_domain.setup_data() inactive_domain.remove_custom_field()
def get_bootinfo(): """build and return boot info""" frappe.set_user_lang(frappe.session.user) bootinfo = frappe._dict() hooks = frappe.get_hooks() doclist = [] # user get_user(bootinfo) # system info bootinfo.sysdefaults = frappe.defaults.get_defaults() bootinfo.server_date = frappe.utils.nowdate() if frappe.session['user'] != 'Guest': bootinfo.user_info = get_fullnames() bootinfo.sid = frappe.session['sid'] bootinfo.modules = {} bootinfo.module_list = [] load_desktop_icons(bootinfo) bootinfo.letter_heads = get_letter_heads() bootinfo.active_domains = frappe.get_active_domains() bootinfo.all_domains = [d.get("name") for d in frappe.get_all("Domain")] bootinfo.module_app = frappe.local.module_app bootinfo.single_types = frappe.db.sql_list("""select name from tabDocType where issingle=1""") add_home_page(bootinfo, doclist) bootinfo.page_info = get_allowed_pages() load_translations(bootinfo) add_timezone_info(bootinfo) load_conf_settings(bootinfo) load_print(bootinfo, doclist) doclist.extend(get_meta_bundle("Page")) bootinfo.home_folder = frappe.db.get_value("File", {"is_home_folder": 1}) # ipinfo if frappe.session.data.get('ipinfo'): bootinfo.ipinfo = frappe.session['data']['ipinfo'] # add docs bootinfo.docs = doclist for method in hooks.boot_session or []: frappe.get_attr(method)(bootinfo) if bootinfo.lang: bootinfo.lang = unicode(bootinfo.lang) bootinfo.versions = {k: v['version'] for k, v in get_versions().items()} bootinfo.error_report_email = frappe.get_hooks("error_report_email") bootinfo.calendars = sorted(frappe.get_hooks("calendars")) bootinfo.treeviews = frappe.get_hooks("treeviews") or [] bootinfo.lang_dict = get_lang_dict() bootinfo.feedback_triggers = get_enabled_feedback_trigger() bootinfo.gsuite_enabled = get_gsuite_status() bootinfo.update(get_email_accounts(user=frappe.session.user)) return bootinfo
def get_roles_and_doctypes(): frappe.only_for("System Manager") send_translations(frappe.get_lang_dict("doctype", "DocPerm")) active_domains = frappe.get_active_domains() doctypes = frappe.get_all("DocType", filters={ "istable": 0, "name": ("not in", "DocType"), }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) roles = frappe.get_all("Role", filters={ "name": ("not in", "Administrator"), "disabled": 0, }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) return { "doctypes": [d.get("name") for d in doctypes], "roles": [d.get("name") for d in roles] }
def get_desk_sidebar_items(): """Get list of sidebar items for desk""" # don't get domain restricted pages blocked_modules = frappe.get_doc('User', frappe.session.user).get_blocked_modules() filters = { 'restrict_to_domain': ['in', frappe.get_active_domains()], 'extends_another_page': 0, 'for_user': '', 'module': ['not in', blocked_modules] } if not frappe.local.conf.developer_mode: filters['developer_mode_only'] = '0' # pages sorted based on pinned to top and then by name order_by = "pin_to_top desc, pin_to_bottom asc, name asc" all_pages = frappe.get_all("Workspace", fields=["name", "category", "icon", "module"], filters=filters, order_by=order_by, ignore_permissions=True) pages = [] # Filter Page based on Permission for page in all_pages: try: wspace = Workspace(page.get('name'), True) if wspace.is_page_allowed(): pages.append(page) page['label'] = _(page.get('name')) except frappe.PermissionError: pass return pages
def update_patient_email_and_phone_numbers(contact, method): """ Hook validate Contact Update linked Patients' primary mobile and phone numbers """ if "Healthcare" not in frappe.get_active_domains( ) or contact.flags.skip_patient_update: return if contact.is_primary_contact and (contact.email_id or contact.mobile_no or contact.phone): patient_links = list( filter(lambda link: link.get("link_doctype") == "Patient", contact.links)) for link in patient_links: contact_details = frappe.db.get_value("Patient", link.get("link_name"), ["email", "mobile", "phone"], as_dict=1) new_contact_details = {} if contact.email_id and contact.email_id != contact_details.get( "email"): new_contact_details.update({"email": contact.email_id}) if contact.mobile_no and contact.mobile_no != contact_details.get( "mobile"): new_contact_details.update({"mobile": contact.mobile_no}) if contact.phone and contact.phone != contact_details.get("phone"): new_contact_details.update({"phone": contact.phone}) if new_contact_details: frappe.db.set_value("Patient", link.get("link_name"), new_contact_details)
def execute(): if "Healthcare" not in frappe.get_active_domains(): return if frappe.db.exists('DocType', 'Healthcare Service Unit'): frappe.reload_doc('healthcare', 'doctype', 'healthcare_service_unit') if frappe.db.has_column('Healthcare Service Unit', 'occupancy_status'): rename_field('Healthcare Service Unit', 'occupancy_status', 'status')
def execute(): frappe.reload_doc("accounts", "doctype", "loyalty_program") frappe.reload_doc("accounts", "doctype", "sales_invoice_item") if "Healthcare" not in frappe.get_active_domains(): return healthcare_custom_field_in_sales_invoice() for si_ref_doc in sales_invoice_referenced_doc: if frappe.db.exists("DocType", si_ref_doc): frappe.reload_doc(get_doctype_module(si_ref_doc), "doctype", scrub(si_ref_doc)) if frappe.db.has_column( si_ref_doc, sales_invoice_referenced_doc[si_ref_doc] ) and frappe.db.has_column(si_ref_doc, "invoiced"): # Set Reference DocType and Reference Docname doc_list = frappe.db.sql(""" select name from `tab{0}` where {1} is not null """.format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc])) if doc_list: frappe.reload_doc(get_doctype_module("Sales Invoice"), "doctype", "sales_invoice") for doc_id in doc_list: invoice_id = frappe.db.get_value( si_ref_doc, doc_id[0], sales_invoice_referenced_doc[si_ref_doc]) if frappe.db.exists("Sales Invoice", invoice_id): if si_ref_doc == "Lab Test": template = frappe.db.get_value( "Lab Test", doc_id[0], "template") if template: item = frappe.db.get_value( "Lab Test Template", template, "item") if item: frappe.db.sql( """update `tabSales Invoice Item` set reference_dt = '{0}', reference_dn = '{1}' where parent = '{2}' and item_code='{3}'""". format(si_ref_doc, doc_id[0], invoice_id, item)) else: invoice = frappe.get_doc( "Sales Invoice", invoice_id) for item_line in invoice.items: if not item_line.reference_dn: item_line.db_set({ "reference_dt": si_ref_doc, "reference_dn": doc_id[0] }) break # Documents mark invoiced for submitted sales invoice frappe.db.sql("""update `tab{0}` doc, `tabSales Invoice` si set doc.invoiced = 1 where si.docstatus = 1 and doc.{1} = si.name """.format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]))
def get_onboarding_slides(): slides = [] slide_list = get_onboarding_slides_as_list() active_domains = frappe.get_active_domains() for slide in slide_list: if not slide.domains or any(domain in active_domains for domain in slide.domains): slides.append(slide) return slides
def get_desk_sidebar_items(flatten=False, cache=True): """Get list of sidebar items for desk """ pages = [] _cache = frappe.cache() if cache: pages = _cache.get_value("desk_sidebar_items", user=frappe.session.user) if not pages or not cache: # don't get domain restricted pages blocked_modules = frappe.get_doc( 'User', frappe.session.user).get_blocked_modules() filters = { 'restrict_to_domain': ['in', frappe.get_active_domains()], 'extends_another_page': 0, 'for_user': '', 'module': ['not in', blocked_modules] } if not frappe.local.conf.developer_mode: filters['developer_mode_only'] = '0' # pages sorted based on pinned to top and then by name order_by = "pin_to_top desc, pin_to_bottom asc, name asc" all_pages = frappe.get_all("Desk Page", fields=["name", "category", "module"], filters=filters, order_by=order_by, ignore_permissions=True) pages = [] # Filter Page based on Permission for page in all_pages: try: wspace = Workspace(page.get('name'), True) if wspace.is_page_allowed(): pages.append(page) except frappe.PermissionError: pass _cache.set_value("desk_sidebar_items", pages, frappe.session.user) if flatten: return pages from collections import defaultdict sidebar_items = defaultdict(list) # The order will be maintained while categorizing for page in pages: # Translate label page['label'] = _(page.get('name')) sidebar_items[page["category"]].append(page) return sidebar_items
def build_doctype_map(self): """build map of special doctype properties""" active_domains = frappe.get_active_domains() self.doctype_map = {} for r in frappe.db.sql("""select name, in_create, issingle, istable, read_only, restrict_to_domain, module from tabDocType""", as_dict=1): if (not r.restrict_to_domain) or (r.restrict_to_domain in active_domains): self.doctype_map[r['name']] = r
def build_domain_restricted_doctype_cache(*args, **kwargs): if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_import: return _cache = frappe.cache() active_domains = frappe.get_active_domains() doctypes = frappe.get_all( "DocType", filters={'restrict_to_domain': ('IN', active_domains)}) doctypes = [doc.name for doc in doctypes] _cache.set_value("domain_restricted_doctypes", doctypes) return doctypes
def get_modules_from_app(app): try: fields = ['name','module_name', 'hidden', 'label', 'link', 'type', 'icon', 'color', 'description', 'category', '_doctype', '_report', 'idx', 'force_show', 'reverse', 'custom', 'standard', 'blocked'] modules = frappe.db.get_all('Kard Desktop Icon', fields=fields, filters={'standard': 1,'type':'module','app':app}) except ImportError: return [] active_domains = frappe.get_active_domains() if isinstance(modules, dict): active_modules_list = [] for m, module in iteritems(modules): module['module_name'] = m module['app'] = app active_modules_list.append(module) else: for m in modules: if m.get("type") == "module" and "category" not in m: m["category"] = "Modules" # Only newly formatted modules that have a category to be shown on desk modules = [m for m in modules if m.get("category")] active_modules_list = [] for m in modules: to_add = True module_name = m.get("module_name") # Check Domain if is_domain(m) and module_name not in active_domains: to_add = False if not in_domains(m,active_domains): to_add = False # Check if config # if is_module(m) and not config_exists(app, frappe.scrub(module_name)): # to_add = False if not is_module(m): to_add = False if "condition" in m and not m["condition"]: to_add = False if to_add: m["app"] = app active_modules_list.append(m) return active_modules_list
def execute(): if "Healthcare" not in frappe.get_active_domains(): return frappe.reload_doc("healthcare", "doctype", "Inpatient Medication Order") frappe.reload_doc("healthcare", "doctype", "Therapy Session") frappe.reload_doc("healthcare", "doctype", "Patient History Settings") frappe.reload_doc("healthcare", "doctype", "Patient History Standard Document Type") frappe.reload_doc("healthcare", "doctype", "Patient History Custom Document Type") setup_patient_history_settings()
def execute(): frappe.reload_doc("core", "doctype", "domain") frappe.reload_doc("core", "doctype", "has_domain") active_domains = frappe.get_active_domains() all_domains = frappe.get_all("Domain") for d in all_domains: if d.name not in active_domains: inactive_domain = frappe.get_doc("Domain", d.name) inactive_domain.setup_data() inactive_domain.remove_custom_field()
def build_domain_restricted_page_cache(*args, **kwargs): if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_import: return _cache = frappe.cache() active_domains = frappe.get_active_domains() pages = frappe.get_all( "Page", filters={'restrict_to_domain': ('IN', active_domains)}) pages = [page.name for page in pages] _cache.set_value("domain_restricted_pages", pages) return pages
def get_all_roles(arg=None): """return all roles""" active_domains = frappe.get_active_domains() roles = frappe.get_all( "Role", filters={"name": ("not in", "Administrator,Guest,All"), "disabled": 0}, or_filters={"ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains)}, order_by="name", ) return [role.get("name") for role in roles]
def get_user_progress_slides(): slides = [] slide_settings = get_slide_settings() domains = frappe.get_active_domains() for s in slide_settings: if not s.domains or any(d in domains for d in s.domains): s.mark_as_done_method = "erpnext.setup.doctype.setup_progress.setup_progress.set_action_completed_state" s.done = get_action_completed_state(s.action_name) or 0 slides.append(s) return slides
def get_roles_and_doctypes(): frappe.only_for("System Manager") send_translations(frappe.get_lang_dict("doctype", "DocPerm")) active_domains = frappe.get_active_domains() doctypes = frappe.get_all( "DocType", filters={ "istable": 0, "name": ("not in", ",".join(not_allowed_in_permission_manager)), }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) restricted_roles = ['Administrator'] if frappe.session.user != 'Administrator': custom_user_type_roles = frappe.get_all('User Type', filters={'is_standard': 0}, fields=['role']) for row in custom_user_type_roles: restricted_roles.append(row.role) restricted_roles.append('All') roles = frappe.get_all("Role", filters={ "name": ("not in", restricted_roles), "disabled": 0, }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["name"]) doctypes_list = [{ "label": _(d.get("name")), "value": d.get("name") } for d in doctypes] roles_list = [{ "label": _(d.get("name")), "value": d.get("name") } for d in roles] return { "doctypes": sorted(doctypes_list, key=lambda d: d['label']), "roles": sorted(roles_list, key=lambda d: d['label']) }
def get_all_roles(arg=None): """return all roles""" active_domains = frappe.get_active_domains() roles = frappe.get_all("Role", filters={ "name": ("not in", "Administrator,Guest,All"), "disabled": 0 }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, order_by="name") return [ role.get("name") for role in roles ]
def build_domain_restriced_doctype_cache(*args, **kwargs): if (frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_migrate or frappe.flags.in_import or frappe.flags.in_setup_wizard): return _cache = frappe.cache() active_domains = frappe.get_active_domains() doctypes = frappe.get_all( "DocType", filters={"restrict_to_domain": ("IN", active_domains)}) doctypes = [doc.name for doc in doctypes] _cache.set_value("domain_restricted_doctypes", doctypes) return doctypes
def build_domain_restriced_page_cache(*args, **kwargs): if (frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_migrate or frappe.flags.in_import or frappe.flags.in_setup_wizard): return _cache = frappe.cache() active_domains = frappe.get_active_domains() pages = frappe.get_all( "Page", filters={"restrict_to_domain": ("IN", active_domains)}) pages = [page.name for page in pages] _cache.set_value("domain_restricted_pages", pages) return pages
def get_pages_to_extend(self): pages = frappe.get_all("Workspace", filters={ "extends": self.page_name, 'restrict_to_domain': ['in', frappe.get_active_domains()], 'for_user': '', 'module': ['in', self.allowed_modules] }) pages = [frappe.get_cached_doc("Workspace", page['name']) for page in pages] for page in pages: self.extended_links = self.extended_links + page.get_link_groups() self.extended_charts = self.extended_charts + page.charts self.extended_shortcuts = self.extended_shortcuts + page.shortcuts
def get_wspace_sidebar_items(): """Get list of sidebar items for desk""" has_access = "Workspace Manager" in frappe.get_roles() # don't get domain restricted pages blocked_modules = frappe.get_doc( 'User', frappe.session.user).get_blocked_modules() blocked_modules.append('Dummy Module') filters = { 'restrict_to_domain': ['in', frappe.get_active_domains()], 'module': ['not in', blocked_modules] } if has_access: filters = [] # pages sorted based on sequence id order_by = "sequence_id asc" fields = [ "name", "title", "for_user", "parent_page", "content", "public", "module", "icon" ] all_pages = frappe.get_all("Workspace", fields=fields, filters=filters, order_by=order_by, ignore_permissions=True) pages = [] private_pages = [] # Filter Page based on Permission for page in all_pages: try: wspace = Workspace(page) if wspace.is_permitted() and wspace.is_page_allowed( ) or has_access: if page.public: pages.append(page) elif page.for_user == frappe.session.user: private_pages.append(page) page['label'] = _(page.get('name')) except frappe.PermissionError: pass if private_pages: pages.extend(private_pages) return {'pages': pages, 'has_access': has_access}
def execute(): """ assign lft and rgt appropriately """ if "Healthcare" not in frappe.get_active_domains(): return frappe.reload_doc("healthcare", "doctype", "healthcare_service_unit") frappe.reload_doc("healthcare", "doctype", "healthcare_service_unit_type") company = frappe.get_value("Company", {"domain": "Healthcare"}, "name") if company: frappe.get_doc({ 'doctype': 'Healthcare Service Unit', 'healthcare_service_unit_name': _('All Healthcare Service Units'), 'is_group': 1, 'company': company }).insert(ignore_permissions=True)
def get_pages_to_extend(self): pages = frappe.get_all( "Workspace", filters={ "extends": self.page_name, "restrict_to_domain": ["in", frappe.get_active_domains()], "for_user": "", "module": ["in", self.allowed_modules], }, ) pages = [frappe.get_cached_doc("Workspace", page["name"]) for page in pages] for page in pages: self.extended_links = self.extended_links + page.get_link_groups() self.extended_charts = self.extended_charts + page.charts self.extended_shortcuts = self.extended_shortcuts + page.shortcuts
def get_doctype_info(module): """Returns list of non child DocTypes for given module.""" active_domains = frappe.get_active_domains() doctype_info = frappe.get_all("DocType", filters={ "module": module, "istable": 0 }, or_filters={ "ifnull(restrict_to_domain, '')": "", "restrict_to_domain": ("in", active_domains) }, fields=["'doctype' as type", "name", "description", "document_type", "custom", "issingle"], order_by="custom asc, document_type desc, name asc") for d in doctype_info: d.document_type = d.document_type or "" d.description = _(d.description or "") return doctype_info
def execute(): if 'Manufacturing' in frappe.get_active_domains(): return role = 'Manufacturing User' frappe.db.set_value('Role', role, 'restrict_to_domain', '') frappe.db.set_value('Role', role, 'disabled', 0) users = frappe.get_all('Has Role', filters = { 'parenttype': 'User', 'role': ('in', ['System Manager', 'Manufacturing Manager']) }, fields=['parent'], as_list=1) for user in users: _user = frappe.get_doc('User', user[0]) _user.append('roles', { 'role': role }) _user.flags.ignore_validate = True _user.save()
def execute(): frappe.reload_doc('accounts', 'doctype', 'loyalty_program') frappe.reload_doc('accounts', 'doctype', 'sales_invoice_item') if "Healthcare" not in frappe.get_active_domains(): return healthcare_custom_field_in_sales_invoice() for si_ref_doc in sales_invoice_referenced_doc: if frappe.db.exists('DocType', si_ref_doc): frappe.reload_doc(get_doctype_module(si_ref_doc), 'doctype', scrub(si_ref_doc)) if frappe.db.has_column(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]) \ and frappe.db.has_column(si_ref_doc, 'invoiced'): # Set Reference DocType and Reference Docname doc_list = frappe.db.sql(""" select name from `tab{0}` where {1} is not null """.format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc])) if doc_list: frappe.reload_doc(get_doctype_module("Sales Invoice"), 'doctype', 'sales_invoice') for doc_id in doc_list: invoice_id = frappe.db.get_value(si_ref_doc, doc_id[0], sales_invoice_referenced_doc[si_ref_doc]) if frappe.db.exists("Sales Invoice", invoice_id): if si_ref_doc == "Lab Test": template = frappe.db.get_value("Lab Test", doc_id[0], "template") if template: item = frappe.db.get_value("Lab Test Template", template, "item") if item: frappe.db.sql("""update `tabSales Invoice Item` set reference_dt = '{0}', reference_dn = '{1}' where parent = '{2}' and item_code='{3}'""".format\ (si_ref_doc, doc_id[0], invoice_id, item)) else: invoice = frappe.get_doc("Sales Invoice", invoice_id) for item_line in invoice.items: if not item_line.reference_dn: item_line.db_set({"reference_dt":si_ref_doc, "reference_dn": doc_id[0]}) break # Documents mark invoiced for submitted sales invoice frappe.db.sql("""update `tab{0}` doc, `tabSales Invoice` si set doc.invoiced = 1 where si.docstatus = 1 and doc.{1} = si.name """.format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]))
def filter_by_restrict_to_domain(data): """ filter Pages and DocType depending on the Active Module(s) """ mapper = { "page": "Page", "doctype": "DocType" } active_domains = frappe.get_active_domains() for d in data: _items = [] for item in d.get("items", []): doctype = mapper.get(item.get("type")) doctype_domain = frappe.db.get_value(doctype, item.get("name"), "restrict_to_domain") or '' if not doctype_domain or (doctype_domain in active_domains): _items.append(item) d.update({ "items": _items }) return data
def get_data(): config = [ { "label": _("Billing"), "items": [ { "type": "doctype", "name": "Sales Invoice", "description": _("Bills raised to Customers.") }, { "type": "doctype", "name": "Purchase Invoice", "description": _("Bills raised by Suppliers.") }, { "type": "doctype", "name": "Payment Request", "description": _("Payment Request") }, { "type": "doctype", "name": "Payment Entry", "description": _("Bank/Cash transactions against party or for internal transfer") } ] }, { "label": _("Company and Accounts"), "items": [ { "type": "doctype", "name": "Company", "description": _("Company (not Customer or Supplier) master.") }, { "type": "doctype", "name": "Journal Entry", "description": _("Accounting journal entries.") }, { "type": "doctype", "name": "Account", "icon": "fa fa-sitemap", "label": _("Chart of Accounts"), "route": "Tree/Account", "description": _("Tree of financial accounts."), }, { "type": "report", "name": "General Ledger", "doctype": "GL Entry", "is_query_report": True, }, ] }, { "label": _("Masters"), "items": [ { "type": "doctype", "name": "Customer", "description": _("Customer database.") }, { "type": "doctype", "name": "Supplier", "description": _("Supplier database.") }, { "type": "doctype", "name": "Item", }, { "type": "doctype", "name": "Bank", }, { "type": "doctype", "name": "Bank Account", } ] }, { "label": _("Accounting Statements"), "items": [ { "type": "report", "name": "Accounts Receivable", "doctype": "Sales Invoice", "is_query_report": True }, { "type": "report", "name": "Accounts Payable", "doctype": "Purchase Invoice", "is_query_report": True }, { "type": "report", "name": "Trial Balance", "doctype": "GL Entry", "is_query_report": True, }, { "type": "report", "name": "Balance Sheet", "doctype": "GL Entry", "is_query_report": True }, { "type": "report", "name": "Cash Flow", "doctype": "GL Entry", "is_query_report": True }, { "type": "report", "name": "Profit and Loss Statement", "doctype": "GL Entry", "is_query_report": True }, { "type": "report", "name": "Consolidated Financial Statement", "doctype": "GL Entry", "is_query_report": True }, ] }, { "label": _("Banking and Payments"), "items": [ { "type": "doctype", "label": _("Update Bank Transaction Dates"), "name": "Bank Reconciliation", "description": _("Update bank payment dates with journals.") }, { "type": "page", "label": _("Reconcile payments and bank transactions"), "name": "bank-reconciliation", "description": _("Link bank transactions with payments.") }, { "type": "doctype", "label": _("Match Payments with Invoices"), "name": "Payment Reconciliation", "description": _("Match non-linked Invoices and Payments.") }, { "type": "report", "name": "Bank Reconciliation Statement", "is_query_report": True, "doctype": "Journal Entry" }, { "type": "report", "name": "Bank Clearance Summary", "is_query_report": True, "doctype": "Journal Entry" }, { "type": "doctype", "name": "Bank Guarantee", "doctype": "Bank Guarantee" }, ] }, { "label": _("Taxes"), "items": [ { "type": "doctype", "name": "Sales Taxes and Charges Template", "description": _("Tax template for selling transactions.") }, { "type": "doctype", "name": "Purchase Taxes and Charges Template", "description": _("Tax template for buying transactions.") }, { "type": "doctype", "name": "Tax Rule", "description": _("Tax Rule for transactions.") }, { "type": "doctype", "name": "Tax Withholding Category", "description": _("Tax Withholding rates to be applied on transactions.") }, { "type": "report", "name": "Sales Register", "doctype": "Sales Invoice", "is_query_report": True }, { "type": "report", "name": "Purchase Register", "doctype": "Purchase Invoice", "is_query_report": True }, ] }, { "label": _("Budget and Cost Center"), "items": [ { "type": "doctype", "name": "Cost Center", "icon": "fa fa-sitemap", "label": _("Chart of Cost Centers"), "route": "Tree/Cost Center", "description": _("Tree of financial Cost Centers."), }, { "type": "doctype", "name": "Budget", "description": _("Define budget for a financial year.") }, { "type": "report", "name": "Budget Variance Report", "is_query_report": True, "doctype": "Cost Center" }, { "type": "doctype", "name": "Monthly Distribution", "description": _("Seasonality for setting budgets, targets etc.") }, ] }, { "label": _("Tools"), "items": [ { "type": "doctype", "name": "Period Closing Voucher", "description": _("Close Balance Sheet and book Profit or Loss.") }, { "type": "doctype", "name": "Cheque Print Template", "description": _("Setup cheque dimensions for printing") }, { "type": "doctype", "name": "Opening Invoice Creation Tool", "description": _("Make Opening Sales and Purchase Invoices") }, ] }, { "label": _("Setup"), "icon": "fa fa-cog", "items": [ { "type": "doctype", "name": "Accounts Settings", "description": _("Default settings for accounting transactions.") }, { "type": "doctype", "name": "Fiscal Year", "description": _("Financial / accounting year.") }, { "type": "doctype", "name": "Currency", "description": _("Enable / disable currencies.") }, { "type": "doctype", "name": "Currency Exchange", "description": _("Currency exchange rate master.") }, { "type": "doctype", "name": "Payment Gateway Account", "description": _("Setup Gateway accounts.") }, { "type": "doctype", "name": "Terms and Conditions", "label": _("Terms and Conditions Template"), "description": _("Template of terms or contract.") }, { "type": "doctype", "name": "Mode of Payment", "description": _("e.g. Bank, Cash, Credit Card") }, { "type": "doctype", "name": "Auto Repeat", "label": _("Auto Repeat"), "description": _("To make recurring documents") }, { "type": "doctype", "name": "C-Form", "description": _("C-Form records"), "country": "India" } ] }, { "label": _("To Bill"), "items": [ { "type": "report", "name": "Ordered Items To Be Billed", "is_query_report": True, "doctype": "Sales Invoice" }, { "type": "report", "name": "Delivered Items To Be Billed", "is_query_report": True, "doctype": "Sales Invoice" }, { "type": "report", "name": "Purchase Order Items To Be Billed", "is_query_report": True, "doctype": "Purchase Invoice" }, { "type": "report", "name": "Received Items To Be Billed", "is_query_report": True, "doctype": "Purchase Invoice" }, ] }, { "label": _("Analytics"), "items": [ { "type": "report", "name": "Gross Profit", "doctype": "Sales Invoice", "is_query_report": True }, { "type": "report", "name": "Purchase Invoice Trends", "is_query_report": True, "doctype": "Purchase Invoice" }, { "type": "report", "name": "Sales Invoice Trends", "is_query_report": True, "doctype": "Sales Invoice" }, { "type": "report", "name": "Item-wise Sales Register", "is_query_report": True, "doctype": "Sales Invoice" }, { "type": "report", "name": "Item-wise Purchase Register", "is_query_report": True, "doctype": "Purchase Invoice" }, { "type": "report", "name": "Profitability Analysis", "doctype": "GL Entry", "is_query_report": True, }, { "type": "report", "name": "Customer Ledger Summary", "doctype": "Sales Invoice", "is_query_report": True, }, { "type": "report", "name": "Supplier Ledger Summary", "doctype": "Sales Invoice", "is_query_report": True, } ] }, { "label": _("Other Reports"), "icon": "fa fa-table", "items": [ { "type": "report", "name": "Trial Balance for Party", "doctype": "GL Entry", "is_query_report": True, }, { "type": "report", "name": "Payment Period Based On Invoice Date", "is_query_report": True, "doctype": "Journal Entry" }, { "type": "report", "name": "Sales Partners Commission", "is_query_report": True, "doctype": "Sales Invoice" }, { "type": "report", "name": "Accounts Receivable Summary", "doctype": "Sales Invoice", "is_query_report": True }, { "type": "report", "name": "Accounts Payable Summary", "doctype": "Purchase Invoice", "is_query_report": True }, { "type": "report", "is_query_report": True, "name": "Customer Credit Balance", "doctype": "Customer" }, { "type": "report", "is_query_report": True, "name": "Sales Payment Summary", "doctype": "Sales Invoice" }, { "type": "report", "is_query_report": True, "name": "Address And Contacts", "doctype": "Address" } ] }, { "label": _("Share Management"), "icon": "fa fa-microchip ", "items": [ { "type": "doctype", "name": "Shareholder", "description": _("List of available Shareholders with folio numbers") }, { "type": "doctype", "name": "Share Transfer", "description": _("List of all share transactions"), }, { "type": "report", "name": "Share Ledger", "doctype": "Share Transfer", "is_query_report": True }, { "type": "report", "name": "Share Balance", "doctype": "Share Transfer", "is_query_report": True } ] }, { "label": _("Help"), "icon": "fa fa-facetime-video", "items": [ { "type": "help", "label": _("Chart of Accounts"), "youtube_id": "DyR-DST-PyA" }, { "type": "help", "label": _("Opening Accounting Balance"), "youtube_id": "kdgM20Q-q68" }, { "type": "help", "label": _("Setting up Taxes"), "youtube_id": "nQ1zZdPgdaQ" } ] } ] gst = { "label": _("Goods and Services Tax (GST India)"), "items": [ { "type": "doctype", "name": "GST Settings", }, { "type": "doctype", "name": "GST HSN Code", }, { "type": "report", "name": "GSTR-1", "is_query_report": True }, { "type": "report", "name": "GSTR-2", "is_query_report": True }, { "type": "report", "name": "GST Sales Register", "is_query_report": True }, { "type": "report", "name": "GST Purchase Register", "is_query_report": True }, { "type": "report", "name": "GST Itemised Sales Register", "is_query_report": True }, { "type": "report", "name": "GST Itemised Purchase Register", "is_query_report": True }, ] } retail = { "label": _("Retail Operations"), "items": [ { "type": "page", "name": "pos", "label": _("POS"), "description": _("Point of Sale") }, { "type": "doctype", "name": "Cashier Closing", "description": _("Cashier Closing") }, { "type": "doctype", "name": "POS Settings", "description": _("Setup mode of POS (Online / Offline)") }, { "type": "doctype", "name": "POS Profile", "label": _("Point-of-Sale Profile"), "description": _("Setup default values for POS Invoices") }, { "type": "doctype", "name": "Loyalty Program", "label": _("Loyalty Program"), "description": _("To make Customer based incentive schemes.") }, { "type": "doctype", "name": "Loyalty Point Entry", "label": _("Loyalty Point Entry"), "description": _("To view logs of Loyalty Points assigned to a Customer.") } ] } subscriptions = { "label": _("Subscription Management"), "icon": "fa fa-microchip ", "items": [ { "type": "doctype", "name": "Subscription Plan", }, { "type": "doctype", "name": "Subscription" }, { "type": "doctype", "name": "Subscription Settings" } ] } countries = frappe.get_all("Company", fields="country") countries = [country["country"] for country in countries] if "India" in countries: config.insert(7, gst) domains = frappe.get_active_domains() if "Retail" in domains: config.insert(2, retail) else: config.insert(7, retail) if "Services" in domains: config.insert(2, subscriptions) else: config.insert(7, subscriptions) return config
def get_desktop_icons(user=None): '''Return desktop icons for user''' if not user: user = frappe.session.user user_icons = frappe.cache().hget('desktop_icons', user) if not user_icons: fields = ['module_name', 'hidden', 'label', 'link', 'type', 'icon', 'color', '_doctype', '_report', 'idx', 'force_show', 'reverse', 'custom', 'standard', 'blocked'] active_domains = frappe.get_active_domains() blocked_doctypes = frappe.get_all("DocType", filters={ "ifnull(restrict_to_domain, '')": ("not in", ",".join(active_domains)) }, fields=["name"]) blocked_doctypes = [ d.get("name") for d in blocked_doctypes ] standard_icons = frappe.db.get_all('Desktop Icon', fields=fields, filters={'standard': 1}) standard_map = {} for icon in standard_icons: if icon._doctype in blocked_doctypes: icon.blocked = 1 standard_map[icon.module_name] = icon user_icons = frappe.db.get_all('Desktop Icon', fields=fields, filters={'standard': 0, 'owner': user}) # update hidden property for icon in user_icons: standard_icon = standard_map.get(icon.module_name, None) if icon._doctype in blocked_doctypes: icon.blocked = 1 # override properties from standard icon if standard_icon: for key in ('route', 'label', 'color', 'icon', 'link'): if standard_icon.get(key): icon[key] = standard_icon.get(key) if standard_icon.blocked: icon.hidden = 1 # flag for modules_select dialog icon.hidden_in_standard = 1 elif standard_icon.force_show: icon.hidden = 0 # add missing standard icons (added via new install apps?) user_icon_names = [icon.module_name for icon in user_icons] for standard_icon in standard_icons: if standard_icon.module_name not in user_icon_names: # if blocked, hidden too! if standard_icon.blocked: standard_icon.hidden = 1 standard_icon.hidden_in_standard = 1 user_icons.append(standard_icon) user_blocked_modules = frappe.get_doc('User', user).get_blocked_modules() for icon in user_icons: if icon.module_name in user_blocked_modules: icon.hidden = 1 # sort by idx user_icons.sort(key = lambda a: a.idx) # translate for d in user_icons: if d.label: d.label = _(d.label) frappe.cache().hset('desktop_icons', user, user_icons) return user_icons
def get_bootinfo(): """build and return boot info""" frappe.set_user_lang(frappe.session.user) bootinfo = frappe._dict() hooks = frappe.get_hooks() doclist = [] # user get_user(bootinfo) # system info bootinfo.sitename = frappe.local.site bootinfo.sysdefaults = frappe.defaults.get_defaults() bootinfo.user_permissions = get_user_permissions() bootinfo.server_date = frappe.utils.nowdate() if frappe.session['user'] != 'Guest': bootinfo.user_info = get_fullnames() bootinfo.sid = frappe.session['sid']; bootinfo.modules = {} bootinfo.module_list = [] load_desktop_icons(bootinfo) bootinfo.letter_heads = get_letter_heads() bootinfo.active_domains = frappe.get_active_domains() bootinfo.all_domains = [d.get("name") for d in frappe.get_all("Domain")] bootinfo.module_app = frappe.local.module_app bootinfo.single_types = frappe.db.sql_list("""select name from tabDocType where issingle=1""") add_home_page(bootinfo, doclist) bootinfo.page_info = get_allowed_pages() load_translations(bootinfo) add_timezone_info(bootinfo) load_conf_settings(bootinfo) load_print(bootinfo, doclist) doclist.extend(get_meta_bundle("Page")) bootinfo.home_folder = frappe.db.get_value("File", {"is_home_folder": 1}) # ipinfo if frappe.session.data.get('ipinfo'): bootinfo.ipinfo = frappe.session['data']['ipinfo'] # add docs bootinfo.docs = doclist for method in hooks.boot_session or []: frappe.get_attr(method)(bootinfo) if bootinfo.lang: bootinfo.lang = text_type(bootinfo.lang) bootinfo.versions = {k: v['version'] for k, v in get_versions().items()} bootinfo.error_report_email = frappe.get_hooks("error_report_email") bootinfo.calendars = sorted(frappe.get_hooks("calendars")) bootinfo.treeviews = frappe.get_hooks("treeviews") or [] bootinfo.lang_dict = get_lang_dict() bootinfo.feedback_triggers = get_enabled_feedback_trigger() bootinfo.gsuite_enabled = get_gsuite_status() bootinfo.update(get_email_accounts(user=frappe.session.user)) return bootinfo