Skip to content

Commit

Permalink
Add: URY_pos api for role restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafnianusha committed Jan 9, 2024
1 parent bc144cb commit 2560f2a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 30 deletions.
54 changes: 54 additions & 0 deletions ury/fixtures/custom_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,60 @@
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": "This role is used as a Cashier Role For Restricting Table Order in URY POS",
"docstatus": 0,
"doctype": "Custom Field",
"dt": "POS Profile",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "role_restricted_for_table_order",
"fieldtype": "Table MultiSelect",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "role_allowed_for_billing",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Role Restricted For Table Order",
"length": 0,
"mandatory_depends_on": null,
"modified": "2024-01-05 20:16:47.345168",
"module": null,
"name": "POS Profile-role_restricted_for_table_order",
"no_copy": 0,
"non_negative": 0,
"options": "Role Permitted",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
Expand Down
20 changes: 0 additions & 20 deletions ury/ury/api/button_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@ def cancel_check():
else:
permission = False
return permission


# # custom_autocomplete.py
# import frappe


@frappe.whitelist()
def get_filtered_users(doctype, txt, searchfield, start, page_len, filters):
role = filters.get("role")
result = frappe.get_all("Has Role", filters={"role": role}, fields=["parent"])
users_with_role = [record.parent for record in result]

# Explicitly specify the table alias for the 'name' column
users = frappe.get_all(
"User",
filters={"name": ("in", users_with_role)},
fields=["name"],
limit_page_length=page_len,
)
return [user["name"] for user in users]
73 changes: 63 additions & 10 deletions ury/ury_pos/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,69 @@


@frappe.whitelist()
def getRestaurantMenu():
menuItems = []
branchName = getBranch()
menu = frappe.db.exists("URY Menu", {"branch": branchName})
if not menu:
frappe.throw(_("Please set an active menu for Branch {0}").format(branchName))
restaurantMenuItems = frappe.get_doc("URY Menu", menu)
for items in restaurantMenuItems.items:
menuItems.append(items)
return menuItems
def getRestaurantMenu(pos_profile, table=None):
menu_items = []

user_role = frappe.get_roles()

pos_profile = frappe.get_doc("POS Profile", pos_profile)

cashier = any(
role.role in user_role for role in pos_profile.role_allowed_for_billing
)

if cashier:
branch_name = getBranch()
menu = frappe.db.get_value(
"URY Restaurant", {"branch": branch_name}, "active_menu"
)

if menu:
menu_items = frappe.get_all(
"URY Menu Item",
filters={"parent": menu},
fields=["item", "item_name", "rate", "special_dish", "disabled"],
)

elif table:
if not table:
frappe.throw(_("Please select a table"))

restaurant, branch, room = frappe.get_value(
"URY Table",
table,
["restaurant", "branch", "restaurant_room"],
)

room_wise_menu = frappe.db.get_value(
"URY Restaurant",
restaurant,
"room_wise_menu",
)

if not room_wise_menu:
menu = frappe.db.get_value("URY Restaurant", restaurant, "active_menu")

else:
menu = frappe.db.get_value(
"Menu for Room",
{"parent": restaurant, "room": room},
"menu",
)

if not menu:
frappe.throw(
_("Please set an active menu for Restaurant {0}").format(restaurant)
)

else:
menu_items = frappe.get_all(
"URY Menu Item",
filters={"parent": menu},
fields=["item", "item_name", "rate", "special_dish", "disabled"],
)

return menu_items


@frappe.whitelist()
Expand Down

0 comments on commit 2560f2a

Please sign in to comment.