Add basic Shopper tab for profile view

This commit is contained in:
Lance Edgar 2023-06-17 02:22:18 -05:00
parent c601d46970
commit b1489c56e2
2 changed files with 106 additions and 14 deletions

View file

@ -436,8 +436,9 @@ class PersonView(MasterView):
related customer, employee, user info etc.
"""
self.viewing = True
app = self.get_rattail_app()
person = self.get_instance()
employee = person.employee
employee = app.get_employee(person)
context = {
'person': person,
'instance': person,
@ -463,6 +464,13 @@ class PersonView(MasterView):
'dynamic_content_title': self.get_context_content_title(person),
}
if context['expose_customer_shoppers']:
shoppers = person.customer_shoppers
# TODO: what a hack! surely this belongs in handler at least..?
shoppers = [shopper for shopper in shoppers
if shopper.shopper_number != 1]
context['shoppers_data'] = self.get_context_shoppers(shoppers)
if self.request.has_perm('people_profile.view_versions'):
context['revisions_grid'] = self.profile_revisions_grid(person)
@ -561,10 +569,24 @@ class PersonView(MasterView):
return context
def get_context_shoppers(self, shoppers):
data = []
for shopper in shoppers:
data.append(self.get_context_shopper(shopper))
return data
def get_context_shopper(self, shopper):
app = self.get_rattail_app()
customer = shopper.customer
person = shopper.person
return {
customer_key = self.get_customer_key_field()
account_holder = app.get_person(customer)
context = {
'uuid': shopper.uuid,
'customer_uuid': customer.uuid,
'customer_key': getattr(customer, customer_key),
'customer_name': customer.name,
'account_holder_uuid': customer.account_holder_uuid,
'person_uuid': person.uuid,
'first_name': person.first_name,
'middle_name': person.middle_name,
@ -575,6 +597,15 @@ class PersonView(MasterView):
'emails': self.get_context_emails(person),
}
if account_holder:
context.update({
'account_holder_name': account_holder.display_name,
'account_holder_view_profile_url': self.get_action_url(
'view_profile', account_holder),
})
return context
def get_context_content_title(self, person):
return str(person)