Expose more Member data, relationships with Customer, Person
This commit is contained in:
parent
eb57ebe62b
commit
0ea4b98b1f
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -30,7 +30,8 @@ import datetime
|
|||
from decimal import Decimal
|
||||
|
||||
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.tags import *
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
|
||||
<%def name="object_helpers()">
|
||||
${parent.object_helpers()}
|
||||
<% people = [] %>
|
||||
<% people = h.OrderedDict() %>
|
||||
% if instance.person:
|
||||
<% people.append(instance.person) %>
|
||||
<% people[instance.person.uuid] = instance.person %>
|
||||
% endif
|
||||
% if instance.customer:
|
||||
<% people.extend(instance.customer.people) %>
|
||||
% for person in instance.customer.people:
|
||||
<% people[person.uuid] = person %>
|
||||
% endfor
|
||||
% endif
|
||||
${view_profiles_helper(people)}
|
||||
${view_profiles_helper(people.values())}
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
||||
|
|
|
@ -59,6 +59,16 @@
|
|||
{{ member.withdrew }}
|
||||
</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 class="buttons" style="align-items: start;">
|
||||
${self.render_member_panel_buttons(member)}
|
||||
|
|
|
@ -143,7 +143,7 @@ class MemberView(MasterView):
|
|||
f.set_label('person_uuid', "Person")
|
||||
else:
|
||||
f.set_readonly('person')
|
||||
# f.set_renderer('person', self.render_person)
|
||||
f.set_renderer('person', self.render_person)
|
||||
|
||||
# customer
|
||||
if self.creating or self.editing:
|
||||
|
|
|
@ -79,6 +79,7 @@ class PeopleView(MasterView):
|
|||
'address',
|
||||
'employee',
|
||||
'customers',
|
||||
'members',
|
||||
'users',
|
||||
]
|
||||
|
||||
|
@ -241,6 +242,13 @@ class PeopleView(MasterView):
|
|||
f.set_readonly('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
|
||||
if self.creating:
|
||||
f.remove_field('users')
|
||||
|
@ -264,15 +272,30 @@ class PeopleView(MasterView):
|
|||
for customer in customers:
|
||||
customer = customer.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)
|
||||
elif customer.number:
|
||||
text = "({}) {}".format(customer.number, text)
|
||||
route = '{}customers.view'.format('mobile.' if self.mobile else '')
|
||||
url = self.request.route_url(route, uuid=customer.uuid)
|
||||
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
||||
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):
|
||||
use_buefy = self.get_use_buefy()
|
||||
users = person.users
|
||||
|
@ -382,6 +405,11 @@ class PeopleView(MasterView):
|
|||
return list(data.values())
|
||||
|
||||
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 {
|
||||
'uuid': member.uuid,
|
||||
'number': member.number,
|
||||
|
@ -389,8 +417,13 @@ class PeopleView(MasterView):
|
|||
'active': member.active,
|
||||
'joined': six.text_type(member.joined) if member.joined 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),
|
||||
'person_display_name': member.person.display_name if member.person else None,
|
||||
'view_url': self.request.route_url('members.view', uuid=member.uuid),
|
||||
'view_profile_url': profile_url,
|
||||
}
|
||||
|
||||
def get_context_employee_history(self, employee):
|
||||
|
|
Loading…
Reference in a new issue