fix: avoid error for trainwreck query when not a customer

when viewing a person's profile, who does not have a customer record,
the trainwreck query can't really return anything since it normally
should be matching on the customer ID
This commit is contained in:
Lance Edgar 2024-11-18 14:59:50 -06:00
parent bcaf0d08bc
commit 980031f524

View file

@ -564,15 +564,19 @@ class PersonView(MasterView):
Method which must return the base query for the profile's POS Method which must return the base query for the profile's POS
Transactions grid data. Transactions grid data.
""" """
app = self.get_rattail_app() customer = self.app.get_customer(person)
customer = app.get_customer(person)
key_field = app.get_customer_key_field() if customer:
key_field = self.app.get_customer_key_field()
customer_key = getattr(customer, key_field) customer_key = getattr(customer, key_field)
if customer_key is not None: if customer_key is not None:
customer_key = str(customer_key) customer_key = str(customer_key)
else:
# nb. this should *not* match anything, so query returns
# no results..
customer_key = person.uuid
trainwreck = app.get_trainwreck_handler() trainwreck = self.app.get_trainwreck_handler()
model = trainwreck.get_model() model = trainwreck.get_model()
query = TrainwreckSession.query(model.Transaction)\ query = TrainwreckSession.query(model.Transaction)\
.filter(model.Transaction.customer_id == customer_key) .filter(model.Transaction.customer_id == customer_key)