Expose default email address, phone number when editing a Person

This commit is contained in:
Lance Edgar 2020-03-17 18:50:07 -05:00
parent ff3e83b1c5
commit 8ac0bb2334
4 changed files with 55 additions and 13 deletions

View file

@ -65,6 +65,12 @@
</ul> </ul>
</b-field> </b-field>
<b-field horizontal label="Address"
v-for="address in customer.addresses"
:key="address.uuid">
{{ address.display }}
</b-field>
</div> </div>
<div class="buttons" style="align-items: start;"> <div class="buttons" style="align-items: start;">
${self.render_customer_panel_buttons(customer)} ${self.render_customer_panel_buttons(customer)}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -263,14 +263,6 @@ class CustomersView(MasterView):
if query.count(): if query.count():
raise colander.Invalid(node, "Customer ID must be unique") raise colander.Invalid(node, "Customer ID must be unique")
def render_default_email(self, customer, field):
if customer.emails:
return customer.emails[0].address
def render_default_phone(self, customer, field):
if customer.phones:
return customer.phones[0].number
def render_default_address(self, customer, field): def render_default_address(self, customer, field):
if customer.addresses: if customer.addresses:
return six.text_type(customer.addresses[0]) return six.text_type(customer.addresses[0])

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -847,6 +847,20 @@ class MasterView(View):
'importer_host_title': importer_host_title, 'importer_host_title': importer_host_title,
}) })
def render_default_phone(self, obj, field):
"""
Render the "default" (first) phone number for the given contact.
"""
if obj.phones:
return obj.phones[0].number
def render_default_email(self, obj, field):
"""
Render the "default" (first) email address for the given contact.
"""
if obj.emails:
return obj.emails[0].address
def render_product_key_value(self, obj): def render_product_key_value(self, obj):
""" """
Render the "canonical" product key value for the given object. Render the "canonical" product key value for the given object.

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -52,8 +52,14 @@ class PeopleView(MasterView):
has_versions = True has_versions = True
supports_mobile = True supports_mobile = True
bulk_deletable = True bulk_deletable = True
is_contact = True
manage_notes_from_profile_view = False manage_notes_from_profile_view = False
labels = {
'default_phone': "Phone Number",
'default_email': "Email Address",
}
grid_columns = [ grid_columns = [
'display_name', 'display_name',
'first_name', 'first_name',
@ -67,8 +73,8 @@ class PeopleView(MasterView):
'middle_name', 'middle_name',
'last_name', 'last_name',
'display_name', 'display_name',
'phone', 'default_phone',
'email', 'default_email',
'address', 'address',
'employee', 'employee',
'customers', 'customers',
@ -197,15 +203,26 @@ class PeopleView(MasterView):
def configure_common_form(self, f): def configure_common_form(self, f):
super(PeopleView, self).configure_common_form(f) super(PeopleView, self).configure_common_form(f)
person = f.model_instance
f.set_label('display_name', "Full Name") f.set_label('display_name', "Full Name")
# TODO: should remove this?
f.set_readonly('phone') f.set_readonly('phone')
f.set_label('phone', "Phone Number") f.set_label('phone', "Phone Number")
f.set_renderer('default_phone', self.render_default_phone)
if not self.creating and person.phones:
f.set_default('default_phone', person.phones[0].number)
# TODO: should remove this?
f.set_readonly('email') f.set_readonly('email')
f.set_label('email', "Email Address") f.set_label('email', "Email Address")
f.set_renderer('default_email', self.render_default_email)
if not self.creating and person.emails:
f.set_default('default_email', person.emails[0].address)
f.set_readonly('address') f.set_readonly('address')
f.set_label('address', "Mailing Address") f.set_label('address', "Mailing Address")
@ -319,6 +336,17 @@ class PeopleView(MasterView):
'view_profile_url': self.get_action_url('view_profile', person), 'view_profile_url': self.get_action_url('view_profile', person),
} }
def get_context_address(self, address):
return {
'uuid': address.uuid,
'street': address.street,
'street2': address.street2,
'city': address.city,
'state': address.state,
'zipcode': address.zipcode,
'display': six.text_type(address),
}
def get_context_customers(self, person): def get_context_customers(self, person):
data = [] data = []
for cp in person._customers: for cp in person._customers:
@ -333,6 +361,8 @@ class PeopleView(MasterView):
uuid=customer.uuid), uuid=customer.uuid),
'people': [self.get_context_person(p) 'people': [self.get_context_person(p)
for p in customer.people], for p in customer.people],
'addresses': [self.get_context_address(a)
for a in customer.addresses],
}) })
return data return data