b2fd83dc51
- Ten "Makap - ..." role profiles map the PRD Section 3 roles (sales, prepress, planner, procurement, warehouse, operator, supervisor, QC/QA, finance, management) onto standard and Makap roles. Created only if missing, so desk edits survive migrate (M6). - New Machine Operator and Prepress roles. Operators can run Job Cards, label rolls and raise in-process inspections, but cannot plan or release. - Quality eligibility, disposition and concession fields move to permlevel 1: only Quality Manager / Concession Authority can set them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162 lines
5.3 KiB
Python
162 lines
5.3 KiB
Python
import frappe
|
|
|
|
|
|
def ensure_makap_roles():
|
|
role_name = "Commercial Reviewer"
|
|
if not frappe.db.exists("Role", role_name):
|
|
frappe.get_doc(
|
|
{
|
|
"doctype": "Role",
|
|
"role_name": role_name,
|
|
"desk_access": 1,
|
|
"is_custom": 1,
|
|
}
|
|
).insert(ignore_permissions=True)
|
|
frappe.db.commit()
|
|
return role_name
|
|
|
|
|
|
def grant_onboarding_permissions():
|
|
doctype = frappe.get_doc("DocType", "Customer Onboarding Request")
|
|
role_name = "Commercial Reviewer"
|
|
|
|
existing_roles = {perm.role for perm in doctype.permissions}
|
|
if role_name not in existing_roles:
|
|
doctype.append(
|
|
"permissions",
|
|
{
|
|
"role": role_name,
|
|
"read": 1,
|
|
"write": 1,
|
|
"create": 1,
|
|
"delete": 0,
|
|
"submit": 0,
|
|
"cancel": 0,
|
|
"amend": 0,
|
|
"print": 1,
|
|
"email": 1,
|
|
"export": 1,
|
|
"report": 1,
|
|
"share": 1,
|
|
},
|
|
)
|
|
doctype.save(ignore_permissions=True)
|
|
frappe.db.commit()
|
|
|
|
return role_name
|
|
|
|
|
|
def smoke_test_onboarding_validation():
|
|
base = {
|
|
"doctype": "Customer Onboarding Request",
|
|
"organisation_name": "MAKAP Smoke Test Organisation",
|
|
"customer_type": "Company",
|
|
"contact_name": "Smoke Test Contact",
|
|
"email_id": "makap-smoke-test@example.invalid",
|
|
"telephone": "+256000000000",
|
|
"registration_source": "Website",
|
|
"privacy_notice_acknowledged": 1,
|
|
"onboarding_status": "Approved",
|
|
"customer_match_result": "Not Checked",
|
|
}
|
|
|
|
blocked = frappe.new_doc("Customer Onboarding Request")
|
|
blocked.update(base)
|
|
try:
|
|
blocked.insert(ignore_permissions=True)
|
|
except Exception as exc:
|
|
blocked_error = str(exc)
|
|
else:
|
|
frappe.delete_doc("Customer Onboarding Request", blocked.name, ignore_permissions=True)
|
|
frappe.db.commit()
|
|
frappe.throw("Smoke test failed: unresolved request was Approved.")
|
|
|
|
approved = frappe.new_doc("Customer Onboarding Request")
|
|
approved.update(base)
|
|
approved.organisation_name = "MAKAP Smoke Test Approved Organisation"
|
|
approved.email_id = "makap-smoke-approved@example.invalid"
|
|
approved.customer_match_result = "New Customer Confirmed"
|
|
approved.insert(ignore_permissions=True)
|
|
approved_name = approved.name
|
|
frappe.delete_doc("Customer Onboarding Request", approved_name, ignore_permissions=True)
|
|
frappe.db.commit()
|
|
|
|
return {
|
|
"unresolved_request_blocked": "Customer Match Result" in blocked_error,
|
|
"approved_confirmed_request_allowed": True,
|
|
"temporary_record_deleted": not frappe.db.exists(
|
|
"Customer Onboarding Request", approved_name
|
|
),
|
|
}
|
|
|
|
|
|
def ensure_makap_functional_roles():
|
|
role_names = [
|
|
"Technical Authority",
|
|
"Production Authority",
|
|
"Materials Controller",
|
|
"Supply Assurance Manager",
|
|
"Concession Authority",
|
|
# Module 8A
|
|
"Dispatch Preparer",
|
|
"Dispatch Authority",
|
|
"Commercial Authority",
|
|
# Module 8B
|
|
"Credit Authority",
|
|
# Shop floor and prepress (PRD Section 3)
|
|
"Machine Operator",
|
|
"Prepress",
|
|
]
|
|
created = []
|
|
for role_name in role_names:
|
|
if not frappe.db.exists("Role", role_name):
|
|
frappe.get_doc(
|
|
{
|
|
"doctype": "Role",
|
|
"role_name": role_name,
|
|
"desk_access": 1,
|
|
"is_custom": 1,
|
|
}
|
|
).insert(ignore_permissions=True)
|
|
created.append(role_name)
|
|
frappe.db.commit()
|
|
return created
|
|
|
|
|
|
def ensure_makap_object_permissions():
|
|
permissions = {
|
|
"Customer Onboarding Request": {
|
|
"Commercial Reviewer": {"read": 1, "write": 1, "create": 1, "print": 1, "report": 1, "export": 1},
|
|
},
|
|
"Packaging Specification": {
|
|
"Commercial Reviewer": {"read": 1, "write": 1, "create": 1, "print": 1, "report": 1, "export": 1},
|
|
"Technical Authority": {"read": 1, "write": 1, "create": 1, "print": 1, "report": 1, "export": 1},
|
|
"Production Authority": {"read": 1, "print": 1, "report": 1},
|
|
"Quality Manager": {"read": 1, "print": 1, "report": 1},
|
|
},
|
|
"Order Closure And Margin View": {
|
|
"Commercial Reviewer": {"read": 1, "print": 1, "report": 1, "export": 1},
|
|
"Credit Authority": {"read": 1, "write": 1, "print": 1, "report": 1, "export": 1},
|
|
"Dispatch Authority": {"read": 1, "print": 1, "report": 1},
|
|
},
|
|
}
|
|
|
|
for doctype_name, role_map in permissions.items():
|
|
if not frappe.db.exists("DocType", doctype_name):
|
|
continue
|
|
doc = frappe.get_doc("DocType", doctype_name)
|
|
existing = {perm.role for perm in doc.permissions}
|
|
changed = False
|
|
for role_name, flags in role_map.items():
|
|
if role_name in existing:
|
|
continue
|
|
row = {"role": role_name}
|
|
row.update(flags)
|
|
doc.append("permissions", row)
|
|
changed = True
|
|
if changed:
|
|
doc.save(ignore_permissions=True)
|
|
|
|
frappe.db.commit()
|
|
return True
|