Skip to content

URY POS Restructuring and User Room Management - #247

Open
swafa-as wants to merge 26 commits into
developfrom
pos-user-branch-restructuring
Open

URY POS Restructuring and User Room Management#247
swafa-as wants to merge 26 commits into
developfrom
pos-user-branch-restructuring

Conversation

@swafa-as

@swafa-as swafa-as commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

1. Overview

This PR restructures the POS architecture of the URY application. It deprecates the previous sub-cashier closing model, enables multiple POS profiles per branch, decouples room assignment from individual branch users to the POS Profile itself, implements branch-level atomic order counters, and decouples production units from specific POS profiles.

2. Key Changes

Schema & Metadata Customizations (Fixtures)

  • New Child Doctypes:
    • POS Profile Captain - Child table storing captain users associated with a POS Profile.
    • POS Profile Link - Child table linking extra accessible profiles to a POS Profile.
  • Modified Doctypes:
    • Branch - Added branch settings and counter tracking fields:
      • custom_reset_order_number_daily (Check, defaults to 1)
      • custom_order_counter (Int, defaults to 0, hidden)
      • custom_aggregator_order_counter (Int, defaults to 0, hidden)
      • custom_last_reset_date (Date, hidden)
    • POS Profile - Deprecated custom_enable_multiple_cashier and its multi-cashier configuration section. Added:
      • custom_captains (Table: POS Profile Captain)
      • custom_rooms (Table MultiSelect: URY Room)
      • custom_captain_access_to_other_profiles (Check)
      • custom_cashier_access_to_other_profiles (Check)
      • custom_captain_accessible_profiles (Table MultiSelect: POS Profile)
      • custom_cashier_accessible_profiles (Table MultiSelect: POS Profile)
    • URY User - Deprecated room field as room mappings move to POS Profile.
    • URY Production Unit - Decoupled from POS Profile by removing the pos_profile field and making branch mandatory (reqd=1 and read_only=0).
  • Deprecated Doctypes (Historical preservation):
    • Sub POS Closing, Sub POS Closing Payment, Sub POS Invoices are marked as deprecated in their doctype definitions.

Backend Python Logic

  • ury_pos/api.py
    • Introduced private helper _resolve_pos_profile(user, branch) that resolves profiles for cashiers (via applicable_for_users) and captains (via custom_captains), falling back to the first profile on the branch.
    • Added get_allowed_profiles(user, branch) to build a list of visible profiles for a user based on captain/cashier accessibility configurations.
    • Refactored getBranchRoom and getRoom to retrieve active rooms from the user's resolved POS Profile custom rooms.
    • Simplified getPosProfile() to resolve profile names using the new helper, returning a simplified dict without the deprecated cashier/owner/room-matching logic.
    • Scoped past orders (getInvoiceForCashier and getPosInvoice) to the list of allowed_profiles using SQL IN conditions rather than the generic branch scope.
  • ury/hooks.py
    • Cleaned up sub-cashier hooks from POS Closing Entry and POS Opening Entry.
    • Registered on_submit event on POS Closing Entry to invoke counter reset logic.
  • ury/hooks/ury_pos_opening_entry.py
    • Removed the cashier check constraints.
    • Rewrote set_cashier_room to retrieve assigned rooms from the target POS Profile.
  • ury/hooks/ury_pos_closing_entry.py
    • Replaced validation code with on_submit logic: if all other POS sessions for the branch are closed, resets the branch order counters.
  • ury/hooks/ury_pos_invoice.py
    • Set owner/cashier fields to the current session user upon submission to support multiple cashiers.
  • ury/api/ury_kot_order_number.py
    • Removed the naming series subtraction arithmetic.
    • Implemented daily-resetting branch-level sequential numbering via atomic SQL increments on the Branch doctype.
  • ury/api/pos_extend.py
    • Scoped overrided_past_order_list() queries to the active profile's custom_rooms.
  • ury/api/ury_kot_display.py
    • Scoped alerts and resets to the active user's resolved profile and branch.

Frontend Integration

  • pos-profile-api.ts & invoiceData.js
    • Modified store merging and interface declarations to handle optional configurations and fallback gracefully when multiple_cashier or owner is missing from the API response.

Data Migration Patch

  • restructure_pos_and_counters.py
    • Automatically creates missing custom fields on execution.
    • Queries and migrates reset_order_number_daily configurations from profiles to branches.
    • Queries the highest order numbers for the current date per branch and initializes the new branch-level order counters.
    • Migrates branch users to applicable_for_users child table on POS Profiles with custom_enable_multiple_cashier=1.
    • Migrates room mapping from deprecated URY User.room to POS Profile.custom_rooms.
    • Ensures branch and warehouse are set on existing URY Production Unit records before pos_profile is deleted.

3. Test Coverage and Verification

  • Added comprehensive integration tests in test_restructure.py:
    • test_room_resolution - Verifies that rooms are fetched from the POS Profile instead of the deprecated branch user settings.
    • test_order_counter_increments - Confirms atomic branch counters increment correctly on new invoice inserts and store values as string format.
    • test_cashier_owner_assignment - Checks cashier user and owner synchronization on the submitted invoice.
    • test_pos_closing_resets_counter - Confirms counters are only reset when all sessions are closed and custom_reset_order_number_daily is enabled.
    • test_allowed_profiles - Asserts correct profile list is resolved based on access configurations.

Extract the 3-step POS Profile lookup (profile_user -> captain -> branch
fallback) into a reusable _resolve_pos_profile(user, branch) helper.

Callers updated:
- getPosProfile(): replaced inline 24-line block with one-liner
- get_allowed_profiles(): direct call instead of full getPosProfile()
- getInvoiceForCashier(): direct call instead of full getPosProfile()
- pos_extend.overrided_past_order_list(): same
- ury_kot_display.kot_list(): same
- ury_kot_display.served_kot_list(): same
@swafa-as swafa-as changed the title Pos user branch restructuring URY POS Restructuring and User Room Management Jul 21, 2026
@swafa-as
swafa-as force-pushed the pos-user-branch-restructuring branch from c91dfd3 to e6fb875 Compare July 23, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants