Add basic support for editing address for a "contact" record
This commit is contained in:
parent
b0b551af82
commit
e916d4f71f
|
@ -75,6 +75,11 @@ class CustomersView(MasterView):
|
|||
'name',
|
||||
'default_phone',
|
||||
'default_address',
|
||||
'address_street',
|
||||
'address_street2',
|
||||
'address_city',
|
||||
'address_state',
|
||||
'address_zipcode',
|
||||
'default_email',
|
||||
'email_preference',
|
||||
'wholesale',
|
||||
|
@ -189,12 +194,27 @@ class CustomersView(MasterView):
|
|||
f.set_default('default_phone', customer.phones[0].number)
|
||||
|
||||
# default_address
|
||||
if self.creating:
|
||||
if self.creating or self.editing:
|
||||
f.remove_field('default_address')
|
||||
else:
|
||||
f.set_renderer('default_address', self.render_default_address)
|
||||
f.set_readonly('default_address')
|
||||
|
||||
# address_*
|
||||
if not (self.creating or self.editing):
|
||||
f.remove_fields('address_street',
|
||||
'address_street2',
|
||||
'address_city',
|
||||
'address_state',
|
||||
'address_zipcode')
|
||||
elif self.editing and customer.addresses:
|
||||
addr = customer.addresses[0]
|
||||
f.set_default('address_street', addr.street)
|
||||
f.set_default('address_street2', addr.street2)
|
||||
f.set_default('address_city', addr.city)
|
||||
f.set_default('address_state', addr.state)
|
||||
f.set_default('address_zipcode', addr.zipcode)
|
||||
|
||||
f.set_enum('email_preference', self.enum.EMAIL_PREFERENCE)
|
||||
preferences = list(self.enum.EMAIL_PREFERENCE.items())
|
||||
preferences.insert(0, ('', "(no preference)"))
|
||||
|
|
|
@ -2731,6 +2731,30 @@ class MasterView(View):
|
|||
elif number:
|
||||
contact.add_phone_number(number)
|
||||
|
||||
address_fields = ('address_street',
|
||||
'address_street2',
|
||||
'address_city',
|
||||
'address_state',
|
||||
'address_zipcode')
|
||||
|
||||
addr = dict([(field, data[field])
|
||||
for field in address_fields
|
||||
if field in data])
|
||||
|
||||
if any(addr.values()):
|
||||
# we strip 'address_' prefix from fields
|
||||
addr = dict([(field[8:], value)
|
||||
for field, value in addr.items()])
|
||||
if contact.addresses:
|
||||
address = contact.addresses[0]
|
||||
for field, value in addr.items():
|
||||
setattr(address, field, value)
|
||||
else:
|
||||
contact.add_mailing_address(**addr)
|
||||
|
||||
elif contact.addresses:
|
||||
contact.addresses.pop()
|
||||
|
||||
return contact
|
||||
|
||||
def save_form(self, form):
|
||||
|
|
Loading…
Reference in a new issue