From f189a95bce1e7b460a4653363a3e8b00ae6cefd1 2021-10-07 12:07:29 From: Lance Edgar Date: 2021-10-07 12:07:29 Subject: [PATCH] Add `update_pending_customer()` for custorder batch handler and perhaps more importantly, `validate_pending_customer_data()` this was needed for sake of unique email address checks --- diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index ab14123361c9dfa2c1db30018988ba36aa3c2cee..861e0fb365ecb1393f2b9af0fe82651f470e0366 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -265,6 +265,47 @@ class CustomerOrderBatchHandler(BatchHandler): session.flush() session.refresh(batch) + def validate_pending_customer_data(self, batch, user, data): + pass + + def update_pending_customer(self, batch, user, data): + model = self.model + people = self.app.get_people_handler() + + # first validate all data + self.validate_pending_customer_data(batch, user, data) + + # clear out any contact it may have + self.unassign_contact(batch) + + # create pending customer if needed + pending = batch.pending_customer + if not pending: + pending = model.PendingCustomer() + pending.user = user + pending.status_code = self.enum.PENDING_CUSTOMER_STATUS_PENDING + batch.pending_customer = pending + + # update pending customer info + if 'first_name' in data: + pending.first_name = data['first_name'] + if 'last_name' in data: + pending.last_name = data['last_name'] + if 'display_name' in data: + pending.display_name = data['display_name'] + else: + pending.display_name = people.normalize_full_name(pending.first_name, + pending.last_name) + if 'phone_number' in data: + pending.phone_number = self.app.format_phone_number(data['phone_number']) + if 'email_address' in data: + 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 + def get_case_size_for_product(self, product): if product.case_size: return product.case_size