diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 2d85e5a7..0c80b8a4 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -1114,19 +1114,33 @@ class PersonView(MasterView): .filter(cls.parent_uuid == person.uuid) versions.extend(query.all()) - # CustomerPerson - cls = continuum.version_class(model.CustomerPerson) + # Customer (account_holder) + cls = continuum.version_class(model.Customer) query = self.Session.query(cls)\ - .filter(cls.person_uuid == person.uuid) + .filter(cls.account_holder_uuid == person.uuid) versions.extend(query.all()) - # Customer + # Customer (new-style via CustomerShopper) + cls = continuum.version_class(model.Customer) + query = self.Session.query(cls)\ + .join(model.CustomerShopper, + model.CustomerShopper.customer_uuid == cls.uuid)\ + .filter(model.CustomerShopper.person_uuid == person.uuid) + versions.extend(query.all()) + + # Customer (old-style via CustomerPerson) cls = continuum.version_class(model.Customer) query = self.Session.query(cls)\ .join(model.CustomerPerson, model.CustomerPerson.customer_uuid == cls.uuid)\ .filter(model.CustomerPerson.person_uuid == person.uuid) versions.extend(query.all()) + # CustomerPerson + cls = continuum.version_class(model.CustomerPerson) + query = self.Session.query(cls)\ + .filter(cls.person_uuid == person.uuid) + versions.extend(query.all()) + # nb. this is used in some queries below FirstShopper = orm.aliased(model.CustomerShopper)