Delete pending customer if deleting custorder batch

also invoke handler to update pending customer info for batch, so the
handler can add validation, e.g. unique email address check
This commit is contained in:
Lance Edgar 2021-10-07 13:08:48 -04:00
parent 5e339bb7ea
commit 284078ff71

View file

@ -302,6 +302,13 @@ class CustomerOrderView(MasterView):
return batch
def start_over_entirely(self, batch):
# delete pending customer if present
pending = batch.pending_customer
if pending:
batch.pending_customer = None
self.Session.delete(pending)
# just delete current batch outright
# TODO: should use self.handler.do_delete() instead?
self.Session.delete(batch)
@ -314,6 +321,13 @@ class CustomerOrderView(MasterView):
return self.redirect(url)
def delete_batch(self, batch):
# delete pending customer if present
pending = batch.pending_customer
if pending:
batch.pending_customer = None
self.Session.delete(pending)
# just delete current batch outright
# TODO: should use self.handler.do_delete() instead?
self.Session.delete(batch)
@ -488,33 +502,11 @@ class CustomerOrderView(MasterView):
}
def update_pending_customer(self, batch, data):
model = self.model
app = self.get_rattail_app()
people = app.get_people_handler()
# clear out any contact it may have
self.handler.unassign_contact(batch)
# create pending customer if needed
pending = batch.pending_customer
if not pending:
pending = model.PendingCustomer()
pending.user = self.request.user
pending.status_code = self.enum.PENDING_CUSTOMER_STATUS_PENDING
batch.pending_customer = pending
# update pending customer info
pending.first_name = data['first_name']
pending.last_name = data['last_name']
pending.display_name = people.normalize_full_name(pending.first_name,
pending.last_name)
pending.phone_number = app.format_phone_number(data['phone_number'])
pending.email_address = data['email_address']
# also update the batch w/ contact info
batch.contact_name = pending.display_name
batch.phone_number = pending.phone_number
batch.email_address = pending.email_address
try:
self.handler.update_pending_customer(batch, self.request.user, data)
except Exception as error:
return {'error': six.text_type(error)}
self.Session.flush()
context = self.get_context_contact(batch)