Prefer account holder, shoppers over legacy Customers.people
but until all are migrated, support both
This commit is contained in:
parent
eab3b75ae5
commit
961cf803f2
|
@ -4,16 +4,7 @@
|
||||||
|
|
||||||
<%def name="object_helpers()">
|
<%def name="object_helpers()">
|
||||||
${parent.object_helpers()}
|
${parent.object_helpers()}
|
||||||
<% people = h.OrderedDict() %>
|
${view_profiles_helper(show_profiles_people)}
|
||||||
% if instance.person:
|
|
||||||
<% people[instance.person.uuid] = instance.person %>
|
|
||||||
% endif
|
|
||||||
% if instance.customer:
|
|
||||||
% for person in instance.customer.people:
|
|
||||||
<% people[person.uuid] = person %>
|
|
||||||
% endfor
|
|
||||||
% endif
|
|
||||||
${view_profiles_helper(people.values())}
|
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
|
@ -27,6 +27,7 @@ Customer Views
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import orm
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
from pyramid.httpexceptions import HTTPNotFound
|
from pyramid.httpexceptions import HTTPNotFound
|
||||||
|
@ -125,10 +126,18 @@ class CustomerView(MasterView):
|
||||||
'customers.expose_people',
|
'customers.expose_people',
|
||||||
default=True)
|
default=True)
|
||||||
|
|
||||||
|
def query(self, session):
|
||||||
|
query = super().query(session)
|
||||||
|
model = self.model
|
||||||
|
return query.outerjoin(model.Person,
|
||||||
|
model.Person.uuid == model.Customer.account_holder_uuid)
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(CustomerView, self).configure_grid(g)
|
super().configure_grid(g)
|
||||||
|
app = self.get_rattail_app()
|
||||||
model = self.model
|
model = self.model
|
||||||
route_prefix = self.get_route_prefix()
|
route_prefix = self.get_route_prefix()
|
||||||
|
legacy = app.get_clientele_handler().should_use_legacy_people()
|
||||||
|
|
||||||
# customer key
|
# customer key
|
||||||
field = self.get_customer_key_field()
|
field = self.get_customer_key_field()
|
||||||
|
@ -162,15 +171,23 @@ class CustomerView(MasterView):
|
||||||
# email_preference
|
# email_preference
|
||||||
g.set_enum('email_preference', self.enum.EMAIL_PREFERENCE)
|
g.set_enum('email_preference', self.enum.EMAIL_PREFERENCE)
|
||||||
|
|
||||||
|
# account_holder_*_name
|
||||||
|
g.set_filter('account_holder_first_name', model.Person.first_name)
|
||||||
|
g.set_filter('account_holder_last_name', model.Person.last_name)
|
||||||
|
|
||||||
# person
|
# person
|
||||||
|
g.set_renderer('person', self.grid_render_person)
|
||||||
|
if legacy:
|
||||||
|
LegacyPerson = orm.aliased(model.Person)
|
||||||
g.set_joiner('person', lambda q:
|
g.set_joiner('person', lambda q:
|
||||||
q.outerjoin(model.CustomerPerson,
|
q.outerjoin(model.CustomerPerson,
|
||||||
sa.and_(
|
sa.and_(
|
||||||
model.CustomerPerson.customer_uuid == model.Customer.uuid,
|
model.CustomerPerson.customer_uuid == model.Customer.uuid,
|
||||||
model.CustomerPerson.ordinal == 1))\
|
model.CustomerPerson.ordinal == 1))\
|
||||||
.outerjoin(model.Person))
|
.outerjoin(LegacyPerson))
|
||||||
|
g.set_sorter('person', LegacyPerson.display_name)
|
||||||
|
else:
|
||||||
g.set_sorter('person', model.Person.display_name)
|
g.set_sorter('person', model.Person.display_name)
|
||||||
g.set_renderer('person', self.grid_render_person)
|
|
||||||
|
|
||||||
# active_in_pos
|
# active_in_pos
|
||||||
if self.get_expose_active_in_pos():
|
if self.get_expose_active_in_pos():
|
||||||
|
@ -395,6 +412,10 @@ class CustomerView(MasterView):
|
||||||
if kwargs['show_profiles_helper']:
|
if kwargs['show_profiles_helper']:
|
||||||
people = OrderedDict()
|
people = OrderedDict()
|
||||||
|
|
||||||
|
if customer.account_holder:
|
||||||
|
person = customer.account_holder
|
||||||
|
people.setdefault(person.uuid, person)
|
||||||
|
|
||||||
for shopper in customer.shoppers:
|
for shopper in customer.shoppers:
|
||||||
person = shopper.person
|
person = shopper.person
|
||||||
people.setdefault(person.uuid, person)
|
people.setdefault(person.uuid, person)
|
||||||
|
@ -434,6 +455,7 @@ class CustomerView(MasterView):
|
||||||
url = self.request.route_url('people.view', uuid=person.uuid)
|
url = self.request.route_url('people.view', uuid=person.uuid)
|
||||||
return tags.link_to(text, url)
|
return tags.link_to(text, url)
|
||||||
|
|
||||||
|
# TODO: remove if no longer used
|
||||||
def render_people(self, customer, field):
|
def render_people(self, customer, field):
|
||||||
people = customer.people
|
people = customer.people
|
||||||
if not people:
|
if not people:
|
||||||
|
|
|
@ -282,6 +282,25 @@ class MemberView(MasterView):
|
||||||
'withdrew',
|
'withdrew',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def template_kwargs_view(self, **kwargs):
|
||||||
|
kwargs = super().template_kwargs_view(**kwargs)
|
||||||
|
member = kwargs['instance']
|
||||||
|
|
||||||
|
people = OrderedDict()
|
||||||
|
if member.person:
|
||||||
|
person = member.person
|
||||||
|
people.setdefault(person.uuid, person)
|
||||||
|
if member.customer:
|
||||||
|
customer = member.customer
|
||||||
|
if customer.account_holder:
|
||||||
|
person = customer.account_holder
|
||||||
|
people.setdefault(person.uuid, person)
|
||||||
|
for person in customer.people:
|
||||||
|
people.setdefault(person.uuid, person)
|
||||||
|
kwargs['show_profiles_people'] = list(people.values())
|
||||||
|
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def render_default_email(self, member, field):
|
def render_default_email(self, member, field):
|
||||||
if member.emails:
|
if member.emails:
|
||||||
return member.emails[0].address
|
return member.emails[0].address
|
||||||
|
|
|
@ -371,12 +371,15 @@ class PersonView(MasterView):
|
||||||
return tags.link_to(text, url)
|
return tags.link_to(text, url)
|
||||||
|
|
||||||
def render_customers(self, person, field):
|
def render_customers(self, person, field):
|
||||||
customers = person._customers
|
app = self.get_rattail_app()
|
||||||
|
clientele = app.get_clientele_handler()
|
||||||
|
|
||||||
|
customers = clientele.get_customers_for_account_holder(person)
|
||||||
if not customers:
|
if not customers:
|
||||||
return ""
|
return
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
for customer in customers:
|
for customer in customers:
|
||||||
customer = customer.customer
|
|
||||||
text = str(customer)
|
text = str(customer)
|
||||||
if customer.number:
|
if customer.number:
|
||||||
text = "(#{}) {}".format(customer.number, text)
|
text = "(#{}) {}".format(customer.number, text)
|
||||||
|
@ -384,6 +387,7 @@ class PersonView(MasterView):
|
||||||
text = "({}) {}".format(customer.id, text)
|
text = "({}) {}".format(customer.id, text)
|
||||||
url = self.request.route_url('customers.view', uuid=customer.uuid)
|
url = self.request.route_url('customers.view', uuid=customer.uuid)
|
||||||
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
||||||
|
|
||||||
return HTML.tag('ul', c=items)
|
return HTML.tag('ul', c=items)
|
||||||
|
|
||||||
def render_members(self, person, field):
|
def render_members(self, person, field):
|
||||||
|
@ -595,6 +599,7 @@ class PersonView(MasterView):
|
||||||
app = self.get_rattail_app()
|
app = self.get_rattail_app()
|
||||||
clientele = app.get_clientele_handler()
|
clientele = app.get_clientele_handler()
|
||||||
expose_shoppers = self.customers_should_expose_shoppers()
|
expose_shoppers = self.customers_should_expose_shoppers()
|
||||||
|
expose_people = self.customers_should_expose_people()
|
||||||
|
|
||||||
customers = clientele.get_customers_for_account_holder(person)
|
customers = clientele.get_customers_for_account_holder(person)
|
||||||
key = self.get_customer_key_field()
|
key = self.get_customer_key_field()
|
||||||
|
@ -609,8 +614,6 @@ class PersonView(MasterView):
|
||||||
'name': customer.name,
|
'name': customer.name,
|
||||||
'view_url': self.request.route_url('customers.view',
|
'view_url': self.request.route_url('customers.view',
|
||||||
uuid=customer.uuid),
|
uuid=customer.uuid),
|
||||||
'people': [self.get_context_person(p)
|
|
||||||
for p in customer.people],
|
|
||||||
'addresses': [self.get_context_address(a)
|
'addresses': [self.get_context_address(a)
|
||||||
for a in customer.addresses],
|
for a in customer.addresses],
|
||||||
'external_links': [],
|
'external_links': [],
|
||||||
|
@ -624,6 +627,10 @@ class PersonView(MasterView):
|
||||||
context['shoppers'] = [self.get_context_shopper(s)
|
context['shoppers'] = [self.get_context_shopper(s)
|
||||||
for s in customer.shoppers]
|
for s in customer.shoppers]
|
||||||
|
|
||||||
|
if expose_people:
|
||||||
|
context['people'] = [self.get_context_person(p)
|
||||||
|
for p in customer.people]
|
||||||
|
|
||||||
for supp in self.iter_view_supplements():
|
for supp in self.iter_view_supplements():
|
||||||
if hasattr(supp, 'get_context_for_customer'):
|
if hasattr(supp, 'get_context_for_customer'):
|
||||||
context = supp.get_context_for_customer(customer, context)
|
context = supp.get_context_for_customer(customer, context)
|
||||||
|
|
Loading…
Reference in a new issue