Skip to content

fix: make customer search and loyalty assignment context-aware#208

Open
my-dev-jour wants to merge 2 commits intoBrainWise-DEV:developfrom
my-dev-jour:fix/202-203-customers-context-and-search
Open

fix: make customer search and loyalty assignment context-aware#208
my-dev-jour wants to merge 2 commits intoBrainWise-DEV:developfrom
my-dev-jour:fix/202-203-customers-context-and-search

Conversation

@my-dev-jour
Copy link
Copy Markdown
Contributor

Summary

  • apply real search_term filtering to customer lookup instead of returning browse-only results
  • make loyalty auto-assignment use explicit company/profile context instead of the first enabled POS Settings row
  • avoid assigning a loyalty program when the company context is ambiguous
  • add regression tests for customer search filters and loyalty context resolution

Testing

  • python3 -m py_compile pos_next/api/customers.py pos_next/api/test_customers.py
  • local verification was limited to py_compile in this workspace

Closes #202
Closes #203

@engahmed1190
Copy link
Copy Markdown
Contributor

Code review

Found 1 issue:

  1. Loyalty auto-assignment is silently broken for customers created via the POS UI. The PR adds frappe.flags context-passing in create_customer(), but the actual POS frontend (CreateCustomerDialog.vue line 335) creates customers via frappe.client.insert -- it never calls pos_next.api.customers.create_customer. This means frappe.flags.pos_next_customer_company and frappe.flags.pos_next_customer_pos_profile are never set for the normal POS flow. The form_dict fallback in _get_customer_assignment_context() also won't help because frappe.client.insert nests fields inside form_dict.doc, not at the top level where form_dict.get("company") looks. The net result is _get_customer_assignment_context() returns (None, None), causing get_default_loyalty_program_from_settings(None, None) to return None -- no loyalty program is ever assigned for POS-created customers.

"loyalty_program": loyalty_program,
}
)
frappe.flags.pos_next_customer_company = company
frappe.flags.pos_next_customer_pos_profile = pos_profile
try:
customer.insert()
finally:
frappe.flags.pos_next_customer_company = None

Relevant frontend call site that bypasses create_customer():

https://github.com/BrainWise-DEV/POSNext/blob/1f1a3862dbd16b07fe2f66e1f75f94f21d17cee0/POS/src/components/sale/CreateCustomerDialog.vue#L334-L336

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@my-dev-jour
Copy link
Copy Markdown
Contributor Author

I reworked the loyalty part based on the actual POS customer-create flow. Staging validation showed the reviewer was right: with a temporary loyalty program configured, plain frappe.client.insert produced a customer with no loyalty program, while pos_next.api.customers.create_customer(..., pos_profile="Main Counter") assigned the expected program. The updated branch now switches the POS dialog to the explicit POSNext API and adds regression coverage for the backend create_customer path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants