Expose more Member data, relationships with Customer, Person

This commit is contained in:
Lance Edgar 2020-03-18 13:15:11 -05:00
parent eb57ebe62b
commit 0ea4b98b1f
5 changed files with 56 additions and 10 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -30,7 +30,8 @@ import datetime
from decimal import Decimal from decimal import Decimal
from rattail.time import localtime, make_utc from rattail.time import localtime, make_utc
from rattail.util import pretty_quantity, pretty_hours, hours_as_decimal from rattail.util import (pretty_quantity, pretty_hours, hours_as_decimal,
OrderedDict)
from webhelpers2.html import * from webhelpers2.html import *
from webhelpers2.html.tags import * from webhelpers2.html.tags import *

View file

@ -4,14 +4,16 @@
<%def name="object_helpers()"> <%def name="object_helpers()">
${parent.object_helpers()} ${parent.object_helpers()}
<% people = [] %> <% people = h.OrderedDict() %>
% if instance.person: % if instance.person:
<% people.append(instance.person) %> <% people[instance.person.uuid] = instance.person %>
% endif % endif
% if instance.customer: % if instance.customer:
<% people.extend(instance.customer.people) %> % for person in instance.customer.people:
<% people[person.uuid] = person %>
% endfor
% endif % endif
${view_profiles_helper(people)} ${view_profiles_helper(people.values())}
</%def> </%def>
${parent.body()} ${parent.body()}

View file

@ -59,6 +59,16 @@
{{ member.withdrew }} {{ member.withdrew }}
</b-field> </b-field>
<b-field horizontal label="Person">
<a v-if="member.person_uuid != person.uuid"
:href="member.view_profile_url">
{{ member.person_display_name }}
</a>
<span v-if="member.person_uuid == person.uuid">
{{ member.person_display_name }}
</span>
</b-field>
</div> </div>
<div class="buttons" style="align-items: start;"> <div class="buttons" style="align-items: start;">
${self.render_member_panel_buttons(member)} ${self.render_member_panel_buttons(member)}

View file

@ -143,7 +143,7 @@ class MemberView(MasterView):
f.set_label('person_uuid', "Person") f.set_label('person_uuid', "Person")
else: else:
f.set_readonly('person') f.set_readonly('person')
# f.set_renderer('person', self.render_person) f.set_renderer('person', self.render_person)
# customer # customer
if self.creating or self.editing: if self.creating or self.editing:

View file

@ -79,6 +79,7 @@ class PeopleView(MasterView):
'address', 'address',
'employee', 'employee',
'customers', 'customers',
'members',
'users', 'users',
] ]
@ -241,6 +242,13 @@ class PeopleView(MasterView):
f.set_readonly('customers') f.set_readonly('customers')
f.set_renderer('customers', self.render_customers) f.set_renderer('customers', self.render_customers)
# members
if self.creating:
f.remove_field('members')
else:
f.set_readonly('members')
f.set_renderer('members', self.render_members)
# users # users
if self.creating: if self.creating:
f.remove_field('users') f.remove_field('users')
@ -264,15 +272,30 @@ class PeopleView(MasterView):
for customer in customers: for customer in customers:
customer = customer.customer customer = customer.customer
text = six.text_type(customer) text = six.text_type(customer)
if customer.id: if customer.number:
text = "(#{}) {}".format(customer.number, text)
elif customer.id:
text = "({}) {}".format(customer.id, text) text = "({}) {}".format(customer.id, text)
elif customer.number:
text = "({}) {}".format(customer.number, text)
route = '{}customers.view'.format('mobile.' if self.mobile else '') route = '{}customers.view'.format('mobile.' if self.mobile else '')
url = self.request.route_url(route, uuid=customer.uuid) url = self.request.route_url(route, 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):
members = person.members
if not members:
return ""
items = []
for member in members:
text = six.text_type(member)
if member.number:
text = "(#{}) {}".format(member.number, text)
elif member.id:
text = "({}) {}".format(member.id, text)
url = self.request.route_url('members.view', uuid=member.uuid)
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
return HTML.tag('ul', c=items)
def render_users(self, person, field): def render_users(self, person, field):
use_buefy = self.get_use_buefy() use_buefy = self.get_use_buefy()
users = person.users users = person.users
@ -382,6 +405,11 @@ class PeopleView(MasterView):
return list(data.values()) return list(data.values())
def get_context_member(self, member): def get_context_member(self, member):
profile_url = None
if member.person:
profile_url = self.request.route_url('people.view_profile',
uuid=member.person_uuid)
return { return {
'uuid': member.uuid, 'uuid': member.uuid,
'number': member.number, 'number': member.number,
@ -389,8 +417,13 @@ class PeopleView(MasterView):
'active': member.active, 'active': member.active,
'joined': six.text_type(member.joined) if member.joined else None, 'joined': six.text_type(member.joined) if member.joined else None,
'withdrew': six.text_type(member.withdrew) if member.withdrew else None, 'withdrew': six.text_type(member.withdrew) if member.withdrew else None,
'customer_uuid': member.customer_uuid,
'customer_name': member.customer.name if member.customer else None,
'person_uuid': member.person_uuid,
'display': six.text_type(member), 'display': six.text_type(member),
'person_display_name': member.person.display_name if member.person else None,
'view_url': self.request.route_url('members.view', uuid=member.uuid), 'view_url': self.request.route_url('members.view', uuid=member.uuid),
'view_profile_url': profile_url,
} }
def get_context_employee_history(self, employee): def get_context_employee_history(self, employee):