Add basic Shopper tab for profile view
This commit is contained in:
parent
c601d46970
commit
b1489c56e2
|
@ -670,7 +670,7 @@
|
|||
<div v-if="customers.length">
|
||||
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<p>{{ person.display_name }} is associated with <strong>{{ customers.length }}</strong> customer account(s)</p>
|
||||
<p>{{ person.display_name }} has <strong>{{ customers.length }}</strong> customer account(s)</p>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
@ -701,17 +701,6 @@
|
|||
{{ customer.name }}
|
||||
</b-field>
|
||||
|
||||
<b-field horizontal label="Account Holder">
|
||||
<span v-if="customer.account_holder && customer.account_holder.uuid == person.uuid">
|
||||
{{ customer.account_holder.display_name }}
|
||||
</span>
|
||||
<a v-if="customer.account_holder && customer.account_holder.uuid != person.uuid"
|
||||
:href="customer.account_holder.view_profile_url">
|
||||
{{ customer.account_holder.display_name }}
|
||||
</a>
|
||||
<span v-if="!customer.account_holder"></span>
|
||||
</b-field>
|
||||
|
||||
% if expose_customer_shoppers:
|
||||
<b-field horizontal label="Shoppers">
|
||||
<ul>
|
||||
|
@ -784,6 +773,72 @@
|
|||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="render_shopper_tab()">
|
||||
<b-tab-item label="Shopper"
|
||||
value="shopper"
|
||||
icon-pack="fas"
|
||||
:icon="shoppers.length ? 'check' : null">
|
||||
|
||||
<div v-if="shoppers.length">
|
||||
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<p>{{ person.display_name }} is shopper for <strong>{{ shoppers.length }}</strong> customer account(s)</p>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<b-collapse v-for="shopper in shoppers"
|
||||
:key="shopper.uuid"
|
||||
class="panel"
|
||||
:open="shoppers.length == 1">
|
||||
|
||||
<div slot="trigger"
|
||||
slot-scope="props"
|
||||
class="panel-heading"
|
||||
role="button">
|
||||
<b-icon pack="fas"
|
||||
icon="caret-right">
|
||||
</b-icon>
|
||||
<strong>{{ shopper.customer_key }} - {{ shopper.customer_name }}</strong>
|
||||
</div>
|
||||
|
||||
<div class="panel-block">
|
||||
<div style="display: flex; justify-content: space-between; width: 100%;">
|
||||
<div style="flex-grow: 1;">
|
||||
|
||||
<b-field horizontal label="${customer_key_label}">
|
||||
{{ shopper.customer_key }}
|
||||
</b-field>
|
||||
|
||||
<b-field horizontal label="Account Name">
|
||||
{{ shopper.customer_name }}
|
||||
</b-field>
|
||||
|
||||
<b-field horizontal label="Account Holder">
|
||||
<span v-if="!shopper.account_holder_view_profile_url">
|
||||
{{ shopper.account_holder_name }}
|
||||
</span>
|
||||
<a v-if="shopper.account_holder_view_profile_url"
|
||||
:href="shopper.account_holder_view_profile_url">
|
||||
{{ shopper.account_holder_name }}
|
||||
</a>
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
## <div class="buttons" style="align-items: start;">
|
||||
## ${self.render_shopper_panel_buttons(shopper)}
|
||||
## </div>
|
||||
</div>
|
||||
</div>
|
||||
</b-collapse>
|
||||
</div>
|
||||
|
||||
<div v-if="!shoppers.length">
|
||||
<p>{{ person.display_name }} is not a shopper.</p>
|
||||
</div>
|
||||
|
||||
</b-tab-item> <!-- Shopper -->
|
||||
</%def>
|
||||
|
||||
<%def name="render_employee_tab_template()">
|
||||
<script type="text/x-template" id="employee-tab-template">
|
||||
<div>
|
||||
|
@ -1095,6 +1150,9 @@
|
|||
${self.render_personal_tab()}
|
||||
${self.render_member_tab()}
|
||||
${self.render_customer_tab()}
|
||||
% if expose_customer_shoppers:
|
||||
${self.render_shopper_tab()}
|
||||
% endif
|
||||
${self.render_employee_tab()}
|
||||
${self.render_user_tab()}
|
||||
</%def>
|
||||
|
@ -1782,6 +1840,9 @@
|
|||
activeTab: location.hash ? location.hash.substring(1) : undefined,
|
||||
person: ${json.dumps(person_data)|n},
|
||||
customers: ${json.dumps(customers_data)|n},
|
||||
% if expose_customer_shoppers:
|
||||
shoppers: ${json.dumps(shoppers_data)|n},
|
||||
% endif
|
||||
member: null, // TODO
|
||||
members: ${json.dumps(members_data)|n},
|
||||
employee: ${json.dumps(employee_data)|n},
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue