Changeset - e46fbbd62ccd
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-10-15 16:50:18
lance@edbob.org
Limit autocomplete results for customer/phone lookup in new custorder

otherwise it's possible for the whole thing to bog down and freeze the
browser page...
1 file changed with 8 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -346,24 +346,28 @@ class CustomerOrderBatchHandler(BatchHandler):
 
                                 .like('%{}%'.format(phone_term)))
 

	
 
        else: # term does not look like a phone number
 

	
 
            # so just search by name
 
            criteria = [model.Customer.name.ilike('%{}%'.format(word))
 
                        for word in term.split()]
 
            query = query.filter(sa.and_(*criteria))
 

	
 
        # oh, and sort by something useful
 
        query = query.order_by(model.Customer.name)
 

	
 
        # and finally, limit the number of results to something a
 
        # browser is likely to be able to handle easily!
 
        query = query[:100]     # TODO: make configurable?
 

	
 
        # generate result list from query
 
        results = []
 
        for customer in query:
 
            phone = customer.first_phone()
 
            if phone:
 
                label = "{} {}".format(customer.name, phone.number)
 
            else:
 
                label = customer.name
 
            results.append({'value': customer.uuid,
 
                            'label': label,
 
                            'display': customer.name})
 

	
 
@@ -392,24 +396,28 @@ class CustomerOrderBatchHandler(BatchHandler):
 
                                 .like('%{}%'.format(phone_term)))
 

	
 
        else: # term does not look like a phone number
 

	
 
            # so just search by name
 
            criteria = [model.Person.display_name.ilike('%{}%'.format(word))
 
                        for word in term.split()]
 
            query = query.filter(sa.and_(*criteria))
 

	
 
        # oh, and sort by something useful
 
        query = query.order_by(model.Person.display_name)
 

	
 
        # and finally, limit the number of results to something a
 
        # browser is likely to be able to handle easily!
 
        query = query[:100]     # TODO: make configurable?
 

	
 
        # generate result list from query
 
        results = []
 
        for person in query:
 
            phone = person.first_phone()
 
            if phone:
 
                label = "{} {}".format(person.display_name, phone.number)
 
            else:
 
                label = person.display_name
 
            results.append({'value': person.uuid,
 
                            'label': label,
 
                            'display': person.display_name})
 

	
0 comments (0 inline, 0 general)