Exemplo n.º 1
0
	def apply_user_permissions_to_all_roles(self):
		# add apply user permissions for all roles that
		# for this doctype
		def show_progress(i, l):
			if l > 2:
				frappe.publish_realtime("progress",
					dict(progress=[i, l], title=_('Updating...')),
						user=frappe.session.user)


		roles = frappe.get_roles(self.user)
		linked = frappe.db.sql('''select distinct parent from tabDocField
			where fieldtype="Link" and options=%s''', self.allow)
		for i, link in enumerate(linked):
			doctype = link[0]
			for perm in get_valid_perms(doctype, self.user):
				# if the role is applicable to the user
				show_progress(i+1, len(linked))
				if perm.role in roles:
					if not perm.apply_user_permissions:
						update_permission_property(doctype, perm.role, 0,
							'apply_user_permissions', '1')

					try:
						user_permission_doctypes = json.loads(perm.user_permission_doctypes or '[]')
					except ValueError:
						user_permission_doctypes = []

					if self.allow not in user_permission_doctypes:
						user_permission_doctypes.append(self.allow)
						update_permission_property(doctype, perm.role, 0,
							'user_permission_doctypes', json.dumps(user_permission_doctypes), validate=False)

		show_progress(len(linked), len(linked))
Exemplo n.º 2
0
def add_permissions():
	for doctype in ('GST HSN Code', 'GST Settings'):
		add_permission(doctype, 'All', 0)
		for role in ('Accounts Manager', 'System Manager', 'Item Manager', 'Stock Manager'):
			add_permission(doctype, role, 0)
			update_permission_property(doctype, role, 0, 'write', 1)
			update_permission_property(doctype, role, 0, 'create', 1)
Exemplo n.º 3
0
def add_permissions():
    """Add Permissions for UAE VAT Settings and UAE VAT Account."""
    for doctype in ("UAE VAT Settings", "UAE VAT Account"):
        add_permission(doctype, "All", 0)
        for role in ("Accounts Manager", "Accounts User", "System Manager"):
            add_permission(doctype, role, 0)
            update_permission_property(doctype, role, 0, "write", 1)
            update_permission_property(doctype, role, 0, "create", 1)
Exemplo n.º 4
0
def add_permissions():
	"""Add Permissions for UAE VAT Settings and UAE VAT Account."""
	for doctype in ('UAE VAT Settings', 'UAE VAT Account'):
		add_permission(doctype, 'All', 0)
		for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
			add_permission(doctype, role, 0)
			update_permission_property(doctype, role, 0, 'write', 1)
			update_permission_property(doctype, role, 0, 'create', 1)
def execute():
    company = frappe.get_all('Company', filters={'country': 'India'})
    if not company:
        return

    for doctype in ('GST HSN Code', 'GST Settings'):
        add_permission(doctype, 'Accounts Manager', 0)
        update_permission_property(doctype, 'Accounts Manager', 0, 'write', 1)
        update_permission_property(doctype, 'Accounts Manager', 0, 'create', 1)
Exemplo n.º 6
0
def add_permissions():
    """Add Permissions for KSA VAT Setting."""
    add_permission("KSA VAT Setting", "All", 0)
    for role in ("Accounts Manager", "Accounts User", "System Manager"):
        add_permission("KSA VAT Setting", role, 0)
        update_permission_property("KSA VAT Setting", role, 0, "write", 1)
        update_permission_property("KSA VAT Setting", role, 0, "create", 1)
    """Enable KSA VAT Report"""
    frappe.db.set_value("Report", "KSA VAT", "disabled", 0)
def execute():
	company = frappe.get_all('Company', filters = {'country': 'India'})
	if not company:
		return

	for doctype in ('GST HSN Code', 'GST Settings'):
		add_permission(doctype, 'Accounts Manager', 0)
		update_permission_property(doctype, 'Accounts Manager', 0, 'write', 1)
		update_permission_property(doctype, 'Accounts Manager', 0, 'create', 1)
Exemplo n.º 8
0
def add_permissions():
    """Add Permissions for KSA VAT Setting."""
    add_permission('KSA VAT Setting', 'All', 0)
    for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
        add_permission('KSA VAT Setting', role, 0)
        update_permission_property('KSA VAT Setting', role, 0, 'write', 1)
        update_permission_property('KSA VAT Setting', role, 0, 'create', 1)
    """Enable KSA VAT Report"""
    frappe.db.set_value('Report', 'KSA VAT', 'disabled', 0)
def set_permissions_to_core_doctypes():
    roles = ['Bank Checker', 'Bank Maker']
    core_doc_list = [
        'Bank Account', 'Company', 'Supplier', 'Customer', 'Employee'
    ]

    # assign select permission
    for role in roles:
        for doc in core_doc_list:
            add_permission(doc, role, 0)
            update_permission_property(doc, role, 0, 'select', 1)
Exemplo n.º 10
0
def execute():
    company = frappe.get_all("Company", filters={"country": "India"})
    if not company:
        return

    frappe.reload_doc("regional", "doctype", "Lower Deduction Certificate")

    add_permission("Lower Deduction Certificate", "Accounts Manager", 0)
    update_permission_property("Lower Deduction Certificate",
                               "Accounts Manager", 0, "write", 1)
    update_permission_property("Lower Deduction Certificate",
                               "Accounts Manager", 0, "create", 1)
Exemplo n.º 11
0
def execute():
    company = frappe.get_all('Company', filters={'country': 'India'})
    if not company:
        return

    frappe.reload_doc('regional', 'doctype', 'Lower Deduction Certificate')

    add_permission('Lower Deduction Certificate', 'Accounts Manager', 0)
    update_permission_property('Lower Deduction Certificate',
                               'Accounts Manager', 0, 'write', 1)
    update_permission_property('Lower Deduction Certificate',
                               'Accounts Manager', 0, 'create', 1)
Exemplo n.º 12
0
def add_permissions():
    doctype = "Product Tax Category"
    for role in (
            "Accounts Manager",
            "Accounts User",
            "System Manager",
            "Item Manager",
            "Stock Manager",
    ):
        add_permission(doctype, role, 0)
        update_permission_property(doctype, role, 0, "write", 1)
        update_permission_property(doctype, role, 0, "create", 1)
def execute():
    company = frappe.get_all('Company', filters={'country': 'Italy'})

    if not company:
        return

    make_custom_fields()

    add_permission('Import Supplier Invoice', 'Accounts Manager', 0)
    update_permission_property('Import Supplier Invoice', 'Accounts Manager',
                               0, 'write', 1)
    update_permission_property('Import Supplier Invoice', 'Accounts Manager',
                               0, 'create', 1)
Exemplo n.º 14
0
def execute():
    company = frappe.get_all("Company", filters={"country": "Italy"})

    if not company:
        return

    make_custom_fields()

    frappe.reload_doc("regional", "doctype", "import_supplier_invoice")

    add_permission("Import Supplier Invoice", "Accounts Manager", 0)
    update_permission_property("Import Supplier Invoice", "Accounts Manager",
                               0, "write", 1)
    update_permission_property("Import Supplier Invoice", "Accounts Manager",
                               0, "create", 1)
Exemplo n.º 15
0
def add_permissions():
	"""Add Permissions for South Africa VAT Settings and South Africa VAT Account
	and VAT Audit Report"""
	for doctype in ("South Africa VAT Settings", "South Africa VAT Account"):
		add_permission(doctype, "All", 0)
		for role in ("Accounts Manager", "Accounts User", "System Manager"):
			add_permission(doctype, role, 0)
			update_permission_property(doctype, role, 0, "write", 1)
			update_permission_property(doctype, role, 0, "create", 1)

	if not frappe.db.get_value("Custom Role", dict(report="VAT Audit Report")):
		frappe.get_doc(
			dict(
				doctype="Custom Role",
				report="VAT Audit Report",
				roles=[dict(role="Accounts User"), dict(role="Accounts Manager"), dict(role="Auditor")],
			)
		).insert()
Exemplo n.º 16
0
def make_role_and_permissions():
    role_name = 'Bank Payments Manager'
    try:
        role = frappe.new_doc('Role')
        role.update({'role_name': role_name, 'desk_access': 1})
        role.save()
    except frappe.DuplicateEntryError:
        pass

    frappe.reload_doc('bank_integration', 'doctype',
                      'bank_integration_settings')
    setup_custom_perms('Bank Integration Settings')

    for doctype in ['Employee', 'Customer', 'Supplier', 'Payment Entry']:
        add_permission(doctype, role_name, 7)
        update_permission_property(doctype, role_name, 7, 'write', 1)

    frappe.db.commit()
Exemplo n.º 17
0
def add_permissions():
    """Add Permissions for South Africa VAT Settings and South Africa VAT Account
		and VAT Audit Report"""
    for doctype in ('South Africa VAT Settings', 'South Africa VAT Account'):
        add_permission(doctype, 'All', 0)
        for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
            add_permission(doctype, role, 0)
            update_permission_property(doctype, role, 0, 'write', 1)
            update_permission_property(doctype, role, 0, 'create', 1)

    if not frappe.db.get_value('Custom Role', dict(report="VAT Audit Report")):
        frappe.get_doc(
            dict(doctype='Custom Role',
                 report="VAT Audit Report",
                 roles=[
                     dict(role='Accounts User'),
                     dict(role='Accounts Manager'),
                     dict(role='Auditor')
                 ])).insert()
Exemplo n.º 18
0
    def apply_user_permissions_to_all_roles(self):
        # add apply user permissions for all roles that
        # for this doctype
        def show_progress(i, l):
            if l > 2:
                frappe.publish_realtime("progress",
                                        dict(progress=[i, l],
                                             title=_('Updating...')),
                                        user=frappe.session.user)

        roles = frappe.get_roles(self.user)
        linked = frappe.db.sql(
            '''select distinct parent from tabDocField
			where fieldtype="Link" and options=%s''', self.allow)
        for i, link in enumerate(linked):
            doctype = link[0]
            for perm in get_valid_perms(doctype, self.user):
                # if the role is applicable to the user
                show_progress(i + 1, len(linked))
                if perm.role in roles:
                    if not perm.apply_user_permissions:
                        update_permission_property(doctype, perm.role, 0,
                                                   'apply_user_permissions',
                                                   '1')

                    try:
                        user_permission_doctypes = json.loads(
                            perm.user_permission_doctypes or '[]')
                    except ValueError:
                        user_permission_doctypes = []

                    if self.allow not in user_permission_doctypes:
                        user_permission_doctypes.append(self.allow)
                        update_permission_property(
                            doctype,
                            perm.role,
                            0,
                            'user_permission_doctypes',
                            json.dumps(user_permission_doctypes),
                            validate=False)

        show_progress(len(linked), len(linked))
Exemplo n.º 19
0
def add_permissions():
    for doctype in ('GST HSN Code', 'GST Settings', 'GSTR 3B Report', 'Lower Deduction Certificate', 'E Invoice Settings'):
        add_permission(doctype, 'All', 0)
        for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
            add_permission(doctype, role, 0)
            update_permission_property(doctype, role, 0, 'write', 1)
            update_permission_property(doctype, role, 0, 'create', 1)

        if doctype == 'GST HSN Code':
            for role in ('Item Manager', 'Stock Manager'):
                add_permission(doctype, role, 0)
                update_permission_property(doctype, role, 0, 'write', 1)
                update_permission_property(doctype, role, 0, 'create', 1)
Exemplo n.º 20
0
def update(doctype, role, permlevel, ptype, value=None):

	try:
		frappe.only_for("System Manager")
		out = update_permission_property(doctype, role, permlevel, ptype, value)
		return 'refresh' if out else None
	except:
		from matajer import test_log
		import traceback
		test_log(traceback.format_exc())
		return 'refresh'
Exemplo n.º 21
0
def update(doctype, role, permlevel, ptype, value=None):
    """Update role permission params

	Args:
		doctype (str): Name of the DocType to update params for
		role (str): Role to be updated for, eg "Website Manager".
		permlevel (int): perm level the provided rule applies to
		ptype (str): permission type, example "read", "delete", etc.
		value (None, optional): value for ptype, None indicates False

	Returns:
		str: Refresh flag is permission is updated successfully
	"""
    frappe.only_for("System Manager")
    out = update_permission_property(doctype, role, permlevel, ptype, value)
    return 'refresh' if out else None
Exemplo n.º 22
0
	def test_select_permission(self):
		# grant only select perm to blog post
		add_permission("Blog Post", "Sales User", 0)
		update_permission_property("Blog Post", "Sales User", 0, "select", 1)
		update_permission_property("Blog Post", "Sales User", 0, "read", 0)
		update_permission_property("Blog Post", "Sales User", 0, "write", 0)

		frappe.clear_cache(doctype="Blog Post")
		frappe.set_user("*****@*****.**")

		# validate select perm
		post = frappe.get_doc("Blog Post", "-test-blog-post")
		self.assertTrue(post.has_permission("select"))

		# validate does not have read and write perm
		self.assertFalse(post.has_permission("read"))
		self.assertRaises(frappe.PermissionError, post.save)
Exemplo n.º 23
0
def add_permissions():
	doctype = "Product Tax Category"
	for role in ('Accounts Manager', 'Accounts User', 'System Manager','Item Manager', 'Stock Manager'):
		add_permission(doctype, role, 0)
		update_permission_property(doctype, role, 0, 'write', 1)
		update_permission_property(doctype, role, 0, 'create', 1)
Exemplo n.º 24
0
def update(doctype, role, permlevel, ptype, value=None):
	frappe.only_for("System Manager")
	out = update_permission_property(doctype, role, permlevel, ptype, value)
	return 'refresh' if out else None
Exemplo n.º 25
0
def add_permissions():
	doctype = "Import Supplier Invoice"
	add_permission(doctype, "All", 0)

	for role in ("Accounts Manager", "Accounts User", "Purchase User", "Auditor"):
		add_permission(doctype, role, 0)
		update_permission_property(doctype, role, 0, "print", 1)
		update_permission_property(doctype, role, 0, "report", 1)

		if role in ("Accounts Manager", "Accounts User"):
			update_permission_property(doctype, role, 0, "write", 1)
			update_permission_property(doctype, role, 0, "create", 1)

	update_permission_property(doctype, "Accounts Manager", 0, "delete", 1)
	add_permission(doctype, "Accounts Manager", 1)
	update_permission_property(doctype, "Accounts Manager", 1, "write", 1)
	update_permission_property(doctype, "Accounts Manager", 1, "create", 1)
Exemplo n.º 26
0
def add_permissions():
    doctype = 'Import Supplier Invoice'
    add_permission(doctype, 'All', 0)

    for role in ('Accounts Manager', 'Accounts User', 'Purchase User',
                 'Auditor'):
        add_permission(doctype, role, 0)
        update_permission_property(doctype, role, 0, 'print', 1)
        update_permission_property(doctype, role, 0, 'report', 1)

        if role in ('Accounts Manager', 'Accounts User'):
            update_permission_property(doctype, role, 0, 'write', 1)
            update_permission_property(doctype, role, 0, 'create', 1)

    update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1)
    add_permission(doctype, 'Accounts Manager', 1)
    update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1)
    update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1)
Exemplo n.º 27
0
def add_permissions():
	for doctype in ('GST HSN Code', 'GST Settings'):
		add_permission(doctype, 'All', 0)
		add_permission(doctype, 'Accounts Manager', 0)
		update_permission_property(doctype, 'Accounts Manager', 0, 'write', 1)
		update_permission_property(doctype, 'Accounts Manager', 0, 'create', 1)
Exemplo n.º 28
0
def update(doctype, role, permlevel, ptype, value=None):
	frappe.only_for("System Manager")
	out = update_permission_property(doctype, role, permlevel, ptype, value)
	return 'refresh' if out else None
Exemplo n.º 29
0
    def validate(self):
        vcheck = frappe.db.exists("DocType", self.check_name)
        # frappe.errprint("hello")
        if vcheck:
            frappe.throw(self.check_name + ' ' + "already exists.")
        else:
            # frappe.errprint("hi")
            ac = frappe.new_doc("All Checks")
            ac.check_name = self.check_name
            ac.check_price = self.check_price
            ac.ce_tat = self.ce_tat
            ac.save(ignore_permissions=True)
            vadd_check = frappe.new_doc("DocType")
            vadd_check.name = self.check_name
            vadd_check.module = "Checkpro"
            vadd_check.autoname = self.check_name + '-.###'
            vadd_check.append("fields", {
                "fieldtype": "Data",
                "label": "CE TAT(days)",
                "read_only": 1,
            })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Data",
                    "label": "Customer",
                    "read_only": 1,
                    "mandatory_depends_on": "eval:!doc.__islocal",
                    "in_standard_filter": 1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Data",
                    "mandatory_depends_on": "eval:!doc.__islocal",
                    "label": "Customer Shortcode",
                    "read_only": 1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Select",
                    "label": "Entry Status",
                    "mandatory_depends_on": "eval:!doc.__islocal",
                    "options":
                    "\nPending\nCompleted\nInsufficient\nHold\nDrop",
                    "default": "Pending",
                    "read_only_depends_on":
                    "eval:doc.workflow_state!=" + '"Draft"'
                })

            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Select",
                    "label":
                    "Report Status",
                    "options":
                    "\nPending\nPositive\nNegative\nDilemma\nInterim",
                    "default":
                    "Pending",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + "doc.workflow_state ==" +
                    '"Pending for Verification"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "depends_on":
                    "eval:doc.workflow_state==" +
                    '"Pending for Verification"' + '||' +
                    'doc.workflow_state ==' + '"Pending for Approval"' + '||' +
                    "doc.workflow_state ==" + '"Approved"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Small Text",
                    "label":
                    "Observation",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + "doc.workflow_state ==" +
                    '"Pending for Verification"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "depends_on":
                    "eval:doc.workflow_state==" +
                    '"Pending for Verification"' + '||' +
                    'doc.workflow_state ==' + '"Pending for Approval"' + '||' +
                    "doc.workflow_state ==" + '"Approved"'
                })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
            })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Check Package",
                    "read_only": 1,
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "in_standard_filter": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Batch",
                    "read_only": 1,
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                })
            vadd_check.append(
                "fields", {
                    "label":
                    "Proof Attachment",
                    "fieldtype":
                    "Attach",
                    "depends_on":
                    "eval:doc.workflow_state==" +
                    '"Pending for Verification"' + '||' +
                    'doc.workflow_state ==' + '"Pending for Approval"' + '||' +
                    "doc.workflow_state ==" + '"Approved"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Data",
                    "label":
                    "Attachment Description",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + "doc.workflow_state ==" +
                    '"Pending for Verification"',
                    "depends_on":
                    "eval:doc.workflow_state==" +
                    '"Pending for Verification"' + '||' +
                    'doc.workflow_state ==' + '"Pending for Approval"' + '||' +
                    "doc.workflow_state ==" + '"Approved"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Date",
                    "label": "Date of Entry",
                    "mandatory_depends_on": "eval:!doc.__islocal",
                    "default": "Today",
                    "read_only_depends_on":
                    "eval:doc.workflow_state!=" + '"Draft"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Select",
                    "label":
                    "Verification Status",
                    "options":
                    "\nPending\nCompleted\nInsufficient\nHold\nDrop",
                    "default":
                    "Pending",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Pending for Verification"',
                    "depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + 'doc.workflow_state ==' +
                    '"Pending for Verification"' + '||' +
                    "doc.workflow_state ==" + '"Approved"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"'
                })
            vadd_check.append("fields", {
                "fieldtype": "Section Break",
                "label": "Case Information",
            })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Case ID",
                    "read_only": 1,
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Name",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Date",
                    "label": "Date of Birth",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Gender",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Age",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
            })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Father Name",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Contact Number",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Email ID",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Client Employee Code",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append(
                "fields",
                {
                    "fieldtype": "Data",
                    "label": "Address",
                    # "mandatory_depends_on":"eval:!doc.__islocal",
                    "read_only": 1
                })
            vadd_check.append("fields", {
                "fieldtype": "Section Break",
            })

            for c in self.check_variables:
                if c.variable_type == "Select":
                    vadd_check.append(
                        "fields",
                        {
                            "fieldtype":
                            "Select",
                            "options":
                            '\n' + c.options,
                            "label":
                            """EPI :""" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            # "mandatory_depends_on":"eval:!doc.__islocal && doc.workflow_state == 'Draft' """,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Number":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Int",
                            "label":
                            """EPI :""" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal && doc.workflow_state ==" +
                            '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Description":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Small Text",
                            "label":
                            'EPI' + " :" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Text":
                    if c.variable != "Specialization":
                        vadd_check.append(
                            "fields", {
                                "fieldtype":
                                "Data",
                                "label":
                                'EPI' + " :" + c.variable,
                                "fieldname":
                                "epi_" + c.variable,
                                "mandatory_depends_on":
                                "eval:!doc.__islocal" + '&&' +
                                "doc.workflow_state ==" + '"Draft"',
                                "read_only_depends_on":
                                "eval:doc.workflow_state!=" + '"Draft"'
                            })
                if c.variable_type == "Date":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Date",
                            "label":
                            'EPI' + " :" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Section":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Section Break",
                            "label":
                            'EPI' + " :" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Column":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Column Break",
                            "label":
                            'EPI' + " :" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable_type == "Link":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Link",
                            "label":
                            'EPI' + ":" + c.variable,
                            "fieldname":
                            "epi_" + c.variable,
                            "options":
                            c.options,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
                if c.variable == "Specialization":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Link",
                            "options":
                            "Specialization",
                            "label":
                            "EPI Specialization",
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" + '"Draft"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state!=" + '"Draft"'
                        })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
            })

            for c in self.check_variables:
                if c.variable_type == "Select":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Select",
                            "options":
                            '\n' + c.options,
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            "doc.workflow_state ==" +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Number":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Int",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Description":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Small Text",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Text":
                    if c.variable != "Specialization":
                        vadd_check.append(
                            "fields", {
                                "fieldtype":
                                "Data",
                                "label":
                                'VPI' + ":" + c.variable,
                                "fieldname":
                                "vpi_" + c.variable,
                                "permlevel":
                                1,
                                "mandatory_depends_on":
                                "eval:!doc.__islocal" + '&&' +
                                'doc.workflow_state ==' +
                                '"Pending for Verification"',
                                "read_only_depends_on":
                                "eval:doc.workflow_state ==" +
                                '"Pending for Approval"' + '||' +
                                "doc.workflow_state ==" + '"Approved"'
                            })
                if c.variable_type == "Date":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Date",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Section":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Section Break",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Column":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Column Break",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable_type == "Link":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Link",
                            "label":
                            'VPI' + ":" + c.variable,
                            "fieldname":
                            "vpi_" + c.variable,
                            "options":
                            c.options,
                            "permlevel":
                            1,
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
                if c.variable == "Specialization":
                    vadd_check.append(
                        "fields", {
                            "fieldtype":
                            "Link",
                            "options":
                            "Specialization",
                            "label":
                            "VPD Specialization",
                            "mandatory_depends_on":
                            "eval:!doc.__islocal" + '&&' +
                            'doc.workflow_state ==' +
                            '"Pending for Verification"',
                            "read_only_depends_on":
                            "eval:doc.workflow_state ==" +
                            '"Pending for Approval"' + '||' +
                            "doc.workflow_state ==" + '"Approved"'
                        })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
                "permlevel": 1
            })
            for c in self.check_variables:
                vadd_check.append(
                    "fields", {
                        "fieldtype":
                        "Select",
                        "options":
                        "\nPositive\nNegative\nDilemma",
                        "label":
                        c.variable + ":" + "Line Status",
                        "fieldname":
                        c.variable + "_line_status",
                        "mandatory_depends_on":
                        "eval:!doc.__islocal" + '&&' +
                        "doc.workflow_state ==" + '"Pending for Verification"',
                        "read_only_depends_on":
                        "eval:doc.workflow_state ==" +
                        '"Pending for Approval"' + '||' +
                        "doc.workflow_state ==" + '"Approved"',
                        "permlevel":
                        1
                    })
            vadd_check.append("fields", {"fieldtype": "Section Break"})
            vadd_check.append("fields", {
                "fieldtype": "Small Text",
                "label": "Remarks"
            })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
            })
            vadd_check.append("fields", {
                "fieldtype": "Attach",
                "label": "Attachment"
            })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Section Break",
                    "label": "Entry Details",
                    "read_only_depends_on":
                    "eval:doc.workflow_state!=" + '"Draft"'
                })
            vadd_check.append(
                "fields", {
                    "label":
                    "Entered By",
                    "fieldtype":
                    "Link",
                    "options":
                    "User",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Draft"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state!=" + '"Draft"'
                })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
            })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Data",
                    "label":
                    "Designation",
                    "fieldname":
                    "entry_designation",
                    "fetch_from":
                    "entered_by.first_name",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Draft"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state!=" + '"Draft"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype": "Section Break",
                    "label": "Verification Details",
                    "permlevel": 1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Link",
                    "label":
                    "Verified By",
                    "options":
                    "User",
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Pending for Verification"',
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "permlevel":
                    1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Data",
                    "label":
                    "Designation",
                    "fetch_from":
                    "verified_by.first_name",
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Pending for Verification"',
                    "permlevel":
                    1
                })
            vadd_check.append("fields", {
                "fieldtype": "Column Break",
                "permlevel": 1
            })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Date",
                    "label":
                    "Start Date",
                    "default":
                    "Today",
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Pending for Verification"',
                    "permlevel":
                    1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Date",
                    "label":
                    "Date of Completion",
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + "doc.workflow_state ==" + '"Approved"',
                    "mandatory_depends_on":
                    "eval:!doc.__islocal" + '&&' + 'doc.workflow_state ==' +
                    '"Pending for Verification"',
                    "permlevel":
                    1
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Section Break",
                    "depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"'
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Link",
                    "options":
                    "User",
                    "label":
                    "Approved By",
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Approved"',
                    "depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + 'doc.workflow_state ==' + '"Approved"',
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Column Break",
                    "depends_on":
                    "doc.workflow_state ==" + '"Pending for Approval"',
                })
            vadd_check.append(
                "fields", {
                    "fieldtype":
                    "Data",
                    "label":
                    "Designation",
                    "read_only_depends_on":
                    "eval:doc.workflow_state ==" + '"Approved"',
                    "fieldname":
                    "approved_designation",
                    "fetch_from":
                    "approved_by.first_name",
                    "depends_on":
                    "eval:doc.workflow_state ==" + '"Pending for Approval"' +
                    '||' + 'doc.workflow_state ==' + '"Approved"',
                })

            vadd_check.append("permissions", {
                "role": "System Manager",
                "read": 1,
                "write": 1,
                "delete": 1
            })
            vadd_check.append("permissions", {
                "role": "VPI user",
                "read": 1,
                "write": 1,
                "delete": 1
            })
            vadd_check.append("permissions", {
                "role": "Check Executive",
                "read": 1,
                "write": 1,
                "delete": 1
            })
            vadd_check.flags.ignore_mandatory = True
            vadd_check.save(ignore_permissions=True)
            doctype = vadd_check.name
            add_permission(doctype, "VPI user", 1)
            update_permission_property(doctype, "VPI user", 1, 'write', 1)
            add_permission(doctype, "Check Executive", 1)
            update_permission_property(doctype, "Check Executive", 1, 'write',
                                       1)
            if (vadd_check.name):
                wf = frappe.new_doc("Workflow")
                wf.workflow_name = vadd_check.name
                wf.document_type = vadd_check.name
                wf.is_active = 1
                wf.append("states", {
                    "state": "Draft",
                    "allow_edit": "System Manager"
                })
                # wf.append("states",{
                #     "state":"Pending for Verification",
                #     "allow_edit":"VPI user"
                # })
                wf.append(
                    "states", {
                        "state": "Pending for Verification",
                        "allow_edit": "Check Executive"
                    })
                wf.append("states", {
                    "state": "Pending for Approval",
                    "allow_edit": "Approver"
                })
                wf.append("states", {
                    "state": "Approved",
                    "allow_edit": "Approver"
                })
                wf.append(
                    "transitions", {
                        "state": "Draft",
                        "action": "EPI QC",
                        "next_state": "Pending for Verification",
                        "condition": "doc.entry_status" + "==" + '"Completed"',
                        "allowed": "System Manager"
                    })
                # wf.append("transitions",{
                #     "state":"Pending for Verification",
                #     "action":"VPD QC",
                #     "next_state":"Pending for QC",
                #     "condition":"doc.execution_status" +"!="+'"Pending"',
                #     "allowed":"VPI user"
                # })
                wf.append(
                    "transitions", {
                        "state": "Pending for Verification",
                        "action": "VPI QC",
                        "next_state": "Pending for Approval",
                        "condition":
                        """doc.report_status=="Positive" and doc.verification_status=="Completed" """,
                        "allowed": "Check Executive"
                    })
                wf.append(
                    "transitions", {
                        "state": "Pending for Approval",
                        "action": "Approve",
                        "next_state": "Approved",
                        "allowed": "Approver"
                    })
                wf.save(ignore_permissions=True)
            if (vadd_check.name):
                ds = frappe.get_doc("Desk Page", "checkPRO")
                for i in ds.cards:
                    # frappe.errprint(i.label)
                    if i.label == "Checks":
                        links = """
                            ,{
                            "label": "%s",
                            "name": "%s",
                            "type": "doctype"
                                }
                            ]""" % (vadd_check.name, vadd_check.name)
                        a = json.dumps(i.links)
                        b = json.loads(a)
                        i.links = b[:-1] + links
                        ds.save(ignore_permissions=True)