Add "contact update request" workflow for new custorder batch

if user checks "please add phone to customer record" etc. then this
preference is stored in the batch params, and when batch is executed
that will "happen" (which may just mean someone gets email about it)
This commit is contained in:
Lance Edgar 2021-10-06 14:49:13 -04:00
parent 2fa7857daf
commit 9b40096bb7
3 changed files with 41 additions and 18 deletions

View file

@ -63,6 +63,7 @@ class CustomerOrderBatchView(BatchMasterView):
'person',
'phone_number',
'email_address',
'params',
'created',
'created_by',
'rowcount',

View file

@ -260,6 +260,8 @@ class CustomerOrderView(MasterView):
'contact_display': self.handler.get_contact_display(batch),
'contact_phones': self.handler.get_contact_phones(batch),
'contact_emails': self.handler.get_contact_emails(batch),
'add_phone_number': bool(batch.get_param('add_phone_number')),
'add_email_address': bool(batch.get_param('add_email_address')),
'contact_profile_url': None,
'contact_notes': self.handler.get_contact_notes(batch),
'order_items': items,
@ -405,6 +407,8 @@ class CustomerOrderView(MasterView):
'contact_phones': self.handler.get_contact_phones(batch),
'contact_emails': self.handler.get_contact_emails(batch),
'contact_notes': self.handler.get_contact_notes(batch),
'add_phone_number': bool(batch.get_param('add_phone_number')),
'add_email_address': bool(batch.get_param('add_email_address')),
}
# maybe add profile URL
@ -426,9 +430,13 @@ class CustomerOrderView(MasterView):
app = self.get_rattail_app()
batch.phone_number = app.format_phone_number(data['phone_number'])
self.Session.flush()
self.Session.refresh(batch)
if data.get('add_phone_number'):
batch.set_param('add_phone_number', True)
else:
batch.clear_param('add_phone_number')
self.Session.flush()
return {
'success': True,
'phone_number': batch.phone_number,
@ -437,9 +445,13 @@ class CustomerOrderView(MasterView):
def update_email_address(self, batch, data):
batch.email_address = data['email_address']
self.Session.flush()
self.Session.refresh(batch)
if data.get('add_email_address'):
batch.set_param('add_email_address', True)
else:
batch.clear_param('add_email_address')
self.Session.flush()
return {
'success': True,
'email_address': batch.email_address,