diff --git a/rmax_custom/rmax_custom/doctype/__init__.py b/rmax_custom/rmax_custom/doctype/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration/__init__.py b/rmax_custom/rmax_custom/doctype/branch_configuration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.js b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.js new file mode 100644 index 0000000..2317234 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.js @@ -0,0 +1,8 @@ +// Copyright (c) 2026, Enfono and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("Branch Configuration", { +// refresh(frm) { + +// }, +// }); diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.json b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.json new file mode 100644 index 0000000..e767870 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.json @@ -0,0 +1,76 @@ + +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:branch", + "naming_rule": "By fieldname", + "creation": "2026-03-05 12:22:51.812112", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "branch", + "section_break_tzxx", + "warehouse", + "cost_center", + "user" + ], + "fields": [ + { + "fieldname": "branch", + "fieldtype": "Link", + "label": "Branch", + "options": "Branch", + "reqd": 1, + "in_list_view": 1 + }, + { + "fieldname": "section_break_tzxx", + "fieldtype": "Section Break" + }, + { + "fieldname": "warehouse", + "fieldtype": "Table", + "label": "Warehouse", + "options": "Branch Configuration Warehouse" + }, + { + "fieldname": "cost_center", + "fieldtype": "Table", + "label": "Cost Center", + "options": "Branch Configuration Cost Center" + }, + { + "fieldname": "user", + "fieldtype": "Table", + "label": "User", + "options": "Branch Configuration User" + } + ], + "grid_page_length": 50, + "index_web_pages_for_search": 1, + "links": [], + "modified": "2026-03-05 12:26:24.845956", + "modified_by": "Administrator", + "module": "Rmax Custom", + "name": "Branch Configuration", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "row_format": "Dynamic", + "rows_threshold_for_grid_search": 20, + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.py b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.py new file mode 100644 index 0000000..40c9938 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration/branch_configuration.py @@ -0,0 +1,81 @@ +#user permissions are created for branch, warehouse and cost center. + +import frappe +from frappe.model.document import Document + + +class BranchConfiguration(Document): + + def before_save(self): + + if self.is_new(): + return + + old_doc = self.get_doc_before_save() + + old_users = {d.user for d in old_doc.user} + new_users = {d.user for d in self.user} + + removed_users = old_users - new_users + + for user in removed_users: + + delete_permission(user, "Branch", old_doc.branch) + + for w in old_doc.warehouse: + delete_permission(user, "Warehouse", w.warehouse) + + for c in old_doc.cost_center: + delete_permission(user, "Cost Center", c.cost_center) + + def on_update(self): + self.create_permissions() + + def create_permissions(self): + + for u in self.user: + + create_permission(u.user, "Branch", self.branch) + + for w in self.warehouse: + create_permission(u.user, "Warehouse", w.warehouse) + + for c in self.cost_center: + create_permission(u.user, "Cost Center", c.cost_center) + +def create_permission(user, allow, value): + + if not value: + return + + if not frappe.db.exists("User Permission", { + "user": user, + "allow": allow, + "for_value": value + }): + + doc = frappe.new_doc("User Permission") + doc.user = user + doc.allow = allow + doc.for_value = value + doc.apply_to_all_doctypes = 1 + doc.insert(ignore_permissions=True) + + +def delete_permission(user, allow, value): + + if not value: + return + + perms = frappe.get_all( + "User Permission", + filters={ + "user": user, + "allow": allow, + "for_value": value + }, + pluck="name" + ) + + for p in perms: + frappe.delete_doc("User Permission", p, ignore_permissions=True) \ No newline at end of file diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration/test_branch_configuration.py b/rmax_custom/rmax_custom/doctype/branch_configuration/test_branch_configuration.py new file mode 100644 index 0000000..0f63679 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration/test_branch_configuration.py @@ -0,0 +1,9 @@ +# Copyright (c) 2026, Enfono and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestBranchConfiguration(FrappeTestCase): + pass diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/__init__.py b/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.json b/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.json new file mode 100644 index 0000000..d21d024 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.json @@ -0,0 +1,35 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2026-03-05 12:19:10.865575", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "cost_center" + ], + "fields": [ + { + "fieldname": "cost_center", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Cost Center", + "options": "Cost Center" + } + ], + "grid_page_length": 50, + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2026-03-05 12:21:00.361306", + "modified_by": "Administrator", + "module": "Rmax Custom", + "name": "Branch Configuration Cost Center", + "owner": "Administrator", + "permissions": [], + "row_format": "Dynamic", + "rows_threshold_for_grid_search": 20, + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.py b/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.py new file mode 100644 index 0000000..9071483 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_cost_center/branch_configuration_cost_center.py @@ -0,0 +1,9 @@ +# Copyright (c) 2026, Enfono and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class BranchConfigurationCostCenter(Document): + pass diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_user/__init__.py b/rmax_custom/rmax_custom/doctype/branch_configuration_user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.json b/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.json new file mode 100644 index 0000000..6124e8f --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.json @@ -0,0 +1,35 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2026-03-05 12:20:16.705104", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "user" + ], + "fields": [ + { + "fieldname": "user", + "fieldtype": "Link", + "in_list_view": 1, + "label": "User", + "options": "User" + } + ], + "grid_page_length": 50, + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2026-03-05 12:20:44.460491", + "modified_by": "Administrator", + "module": "Rmax Custom", + "name": "Branch Configuration User", + "owner": "Administrator", + "permissions": [], + "row_format": "Dynamic", + "rows_threshold_for_grid_search": 20, + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.py b/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.py new file mode 100644 index 0000000..88b3551 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_user/branch_configuration_user.py @@ -0,0 +1,9 @@ +# Copyright (c) 2026, Enfono and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class BranchConfigurationUser(Document): + pass diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/__init__.py b/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.json b/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.json new file mode 100644 index 0000000..ea09869 --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.json @@ -0,0 +1,35 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2026-03-05 12:17:55.385600", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "warehouse" + ], + "fields": [ + { + "fieldname": "warehouse", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Warehouse", + "options": "Warehouse" + } + ], + "grid_page_length": 50, + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2026-03-05 12:21:12.868254", + "modified_by": "Administrator", + "module": "Rmax Custom", + "name": "Branch Configuration Warehouse", + "owner": "Administrator", + "permissions": [], + "row_format": "Dynamic", + "rows_threshold_for_grid_search": 20, + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.py b/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.py new file mode 100644 index 0000000..a354d9b --- /dev/null +++ b/rmax_custom/rmax_custom/doctype/branch_configuration_warehouse/branch_configuration_warehouse.py @@ -0,0 +1,9 @@ +# Copyright (c) 2026, Enfono and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class BranchConfigurationWarehouse(Document): + pass