Ejemplo n.º 1
0
	def test_active_domains(self):
		self.assertTrue("_Test Domain 1" in dataent.get_active_domains())
		self.assertFalse("_Test Domain 2" in dataent.get_active_domains())

		self.add_active_domain("_Test Domain 2")
		self.assertTrue("_Test Domain 2" in dataent.get_active_domains())

		self.remove_from_active_domains("_Test Domain 1")
		self.assertTrue("_Test Domain 1" not in dataent.get_active_domains())
Ejemplo n.º 2
0
def get_roles_and_doctypes():
	dataent.only_for("System Manager")
	send_translations(dataent.get_lang_dict("doctype", "DocPerm"))

	active_domains = dataent.get_active_domains()

	doctypes = dataent.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 = dataent.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'])
	}
Ejemplo n.º 3
0
def execute():
    if 'Education' in dataent.get_active_domains() and not dataent.db.exists(
            "Role", "Guardian"):
        doc = dataent.new_doc("Role")
        doc.update({"role_name": "Guardian", "desk_access": 0})

        doc.insert(ignore_permissions=True)
Ejemplo n.º 4
0
    def restrict_roles_and_modules(self):
        '''Disable all restricted roles and set `restrict_to_domain` property in Module Def'''
        active_domains = dataent.get_active_domains()
        all_domains = list((dataent.get_hooks('domains') or {}))

        def remove_role(role):
            dataent.db.sql('delete from `tabHas Role` where role=%s', role)
            dataent.set_value('Role', role, 'disabled', 1)

        for domain in all_domains:
            data = dataent.get_domain_data(domain)
            if not dataent.db.get_value('Domain', domain):
                dataent.get_doc(dict(doctype='Domain', domain=domain)).insert()
            if 'modules' in data:
                for module in data.get('modules'):
                    dataent.db.set_value('Module Def', module,
                                         'restrict_to_domain', domain)

            if 'restricted_roles' in data:
                for role in data['restricted_roles']:
                    if not dataent.db.get_value('Role', role):
                        dataent.get_doc(dict(doctype='Role',
                                             role_name=role)).insert()
                    dataent.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 = dataent.get_doc("Domain", domain)
                    inactive_domain.setup_data()
                    inactive_domain.remove_custom_field()
Ejemplo n.º 5
0
	def build_doctype_map(self):
		"""build map of special doctype properties"""

		active_domains = dataent.get_active_domains()

		self.doctype_map = {}
		for r in dataent.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 execute():
    dataent.reload_doc("core", "doctype", "domain")
    dataent.reload_doc("core", "doctype", "has_domain")
    active_domains = dataent.get_active_domains()
    all_domains = dataent.get_all("Domain")

    for d in all_domains:
        if d.name not in active_domains:
            inactive_domain = dataent.get_doc("Domain", d.name)
            inactive_domain.setup_data()
            inactive_domain.remove_custom_field()
Ejemplo n.º 7
0
def execute():
    dataent.reload_doc('accounts', 'doctype', 'loyalty_program')
    dataent.reload_doc('accounts', 'doctype', 'sales_invoice_item')

    if "Healthcare" not in dataent.get_active_domains():
        return

    healthcare_custom_field_in_sales_invoice()
    for si_ref_doc in sales_invoice_referenced_doc:
        if dataent.db.exists('DocType', si_ref_doc):
            dataent.reload_doc(get_doctype_module(si_ref_doc), 'doctype',
                               scrub(si_ref_doc))

            if dataent.db.has_column(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]) \
            and dataent.db.has_column(si_ref_doc, 'invoiced'):
                # Set Reference DocType and Reference Docname
                doc_list = dataent.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:
                    dataent.reload_doc(get_doctype_module("Sales Invoice"),
                                       'doctype', 'sales_invoice')
                    for doc_id in doc_list:
                        invoice_id = dataent.db.get_value(
                            si_ref_doc, doc_id[0],
                            sales_invoice_referenced_doc[si_ref_doc])
                        if dataent.db.exists("Sales Invoice", invoice_id):
                            if si_ref_doc == "Lab Test":
                                template = dataent.db.get_value(
                                    "Lab Test", doc_id[0], "template")
                                if template:
                                    item = dataent.db.get_value(
                                        "Lab Test Template", template, "item")
                                    if item:
                                        dataent.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 = dataent.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
                dataent.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]))
Ejemplo n.º 8
0
def get_user_progress_slides():
    slides = []
    slide_settings = get_slide_settings()

    domains = dataent.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 = "epaas.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
Ejemplo n.º 9
0
def get_all_roles(arg=None):
    """return all roles"""
    active_domains = dataent.get_active_domains()

    roles = dataent.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]
Ejemplo n.º 10
0
def get_doctype_info(module):
	"""Returns list of non child DocTypes for given module."""
	active_domains = dataent.get_active_domains()

	doctype_info = dataent.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
Ejemplo n.º 11
0
def filter_by_restrict_to_domain(data):
	""" filter Pages and DocType depending on the Active Module(s) """
	mapper = {
		"page": "Page",
		"doctype": "DocType"
	}
	active_domains = dataent.get_active_domains()

	for d in data:
		_items = []
		for item in d.get("items", []):
			doctype = mapper.get(item.get("type"))

			doctype_domain = dataent.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
Ejemplo n.º 12
0
def execute():
    """ assign lft and rgt appropriately """
    if "Healthcare" not in dataent.get_active_domains():
        return

    dataent.reload_doc("healthcare", "doctype", "healthcare_service_unit")
    dataent.reload_doc("healthcare", "doctype", "healthcare_service_unit_type")
    company = dataent.get_value("Company", {"domain": "Healthcare"}, "name")

    if company:
        dataent.get_doc({
            'doctype':
            'Healthcare Service Unit',
            'healthcare_service_unit_name':
            _('All Healthcare Service Units'),
            'is_group':
            1,
            'company':
            company
        }).insert(ignore_permissions=True)
Ejemplo n.º 13
0
def execute():
    if 'Manufacturing' in dataent.get_active_domains(): return

    role = 'Manufacturing User'
    dataent.db.set_value('Role', role, 'restrict_to_domain', '')
    dataent.db.set_value('Role', role, 'disabled', 0)

    users = dataent.get_all('Has Role',
                            filters={
                                'parenttype':
                                'User',
                                'role':
                                ('in',
                                 ['System Manager', 'Manufacturing Manager'])
                            },
                            fields=['parent'],
                            as_list=1)

    for user in users:
        _user = dataent.get_doc('User', user[0])
        _user.append('roles', {'role': role})
        _user.flags.ignore_validate = True
        _user.save()
Ejemplo n.º 14
0
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")
        }, {
            "type": "doctype",
            "name": "Payment Term",
            "description": _("Payment Terms based on conditions")
        }]
    }, {
        "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": "Exchange Rate Revaluation",
            "description": _("Exchange Rate Revaluation 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 = dataent.get_all("Company", fields="country")
    countries = [country["country"] for country in countries]
    if "India" in countries:
        config.insert(7, gst)
    domains = dataent.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
Ejemplo n.º 15
0
def get_desktop_icons(user=None):
    '''Return desktop icons for user'''
    if not user:
        user = dataent.session.user

    user_icons = dataent.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 = dataent.get_active_domains()

        blocked_doctypes = dataent.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 = dataent.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 = dataent.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 = dataent.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)

        dataent.cache().hset('desktop_icons', user, user_icons)

    return user_icons
Ejemplo n.º 16
0
def get_bootinfo():
    """build and return boot info"""
    dataent.set_user_lang(dataent.session.user)
    bootinfo = dataent._dict()
    hooks = dataent.get_hooks()
    doclist = []

    # user
    get_user(bootinfo)

    # system info
    bootinfo.sitename = dataent.local.site
    bootinfo.sysdefaults = dataent.defaults.get_defaults()
    bootinfo.server_date = dataent.utils.nowdate()

    if dataent.session['user'] != 'Guest':
        bootinfo.user_info = get_fullnames()
        bootinfo.sid = dataent.session['sid']

    bootinfo.modules = {}
    bootinfo.module_list = []
    load_desktop_icons(bootinfo)
    bootinfo.letter_heads = get_letter_heads()
    bootinfo.active_domains = dataent.get_active_domains()
    bootinfo.all_domains = [d.get("name") for d in dataent.get_all("Domain")]

    bootinfo.module_app = dataent.local.module_app
    bootinfo.single_types = [
        d.name for d in dataent.get_all('DocType', {'issingle': 1})
    ]
    bootinfo.nested_set_doctypes = [
        d.parent
        for d in dataent.get_all('DocField', {'fieldname': 'lft'}, ['parent'])
    ]
    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 = dataent.db.get_value("File", {"is_home_folder": 1})

    # ipinfo
    if dataent.session.data.get('ipinfo'):
        bootinfo.ipinfo = dataent.session['data']['ipinfo']

    # add docs
    bootinfo.docs = doclist

    for method in hooks.boot_session or []:
        dataent.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 = dataent.conf.error_report_email
    bootinfo.calendars = sorted(dataent.get_hooks("calendars"))
    bootinfo.treeviews = dataent.get_hooks("treeviews") or []
    bootinfo.lang_dict = get_lang_dict()
    bootinfo.feedback_triggers = get_enabled_feedback_trigger()
    bootinfo.gsuite_enabled = get_gsuite_status()
    bootinfo.success_action = get_success_action()
    bootinfo.update(get_email_accounts(user=dataent.session.user))

    return bootinfo