Join the Person model for Customers grid differently based on config

This commit is contained in:
Lance Edgar 2023-06-16 20:08:27 -05:00
parent bf1726a52b
commit 5a03f5c23e

View file

@ -128,9 +128,19 @@ class CustomerView(MasterView):
def query(self, session):
query = super().query(session)
app = self.get_rattail_app()
model = self.model
return query.outerjoin(model.Person,
model.Person.uuid == model.Customer.account_holder_uuid)
if app.get_clientele_handler().should_use_legacy_people():
query = query.outerjoin(model.CustomerPerson,
sa.and_(
model.CustomerPerson.customer_uuid == model.Customer.uuid,
model.CustomerPerson.ordinal == 1))\
.outerjoin(model.Person,
model.Person.uuid == model.CustomerPerson.person_uuid)
else:
query = query.outerjoin(model.Person,
model.Person.uuid == model.Customer.account_holder_uuid)
return query
def configure_grid(self, g):
super().configure_grid(g)