Changeset - f189a95bce1e
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-10-07 12:07:29
lance@edbob.org
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
1 file changed with 41 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)