Changeset - 194bca3ebcd3
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-10-04 11:18:37
lance@edbob.org
Add `get_contact_phones()` method for custorder batch handler

for presenting options to user when making new order
1 file changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -99,24 +99,56 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        batch.phone_number = None
 
        batch.email_address = None
 
        if customer_required:
 
            batch.phone_number = clientele.get_first_phone_number(customer)
 
            batch.email_address = clientele.get_first_email_address(customer)
 
        else:
 
            batch.phone_number = person.first_phone_number()
 
            batch.email_address = person.first_email_address()
 

	
 
        session = self.app.get_session(batch)
 
        session.flush()
 

	
 
    def get_contact_phones(self, batch):
 
        """
 
        Retrieve all phone records on file for the batch contact, to
 
        be presented as options for user to choose from when making a
 
        new order.
 
        """
 
        customer_required = self.new_order_requires_customer()
 

	
 
        phones = []
 
        if customer_required:
 
            if batch.customer:
 
                phones = batch.customer.phones
 
        else:
 
            if batch.person:
 
                phones = batch.person.phones
 

	
 
        return [self.normalize_phone(phone)
 
                for phone in phones]
 

	
 
    def normalize_phone(self, phone):
 
        """
 
        Normalize the given phone record to simple data dict, for
 
        passing around via JSON etc.
 
        """
 
        return {
 
            'uuid': phone.uuid,
 
            'type': phone.type,
 
            'number': phone.number,
 
            'preference': phone.preference,
 
            'preferred': phone.preference == 1,
 
        }
 

	
 
    def get_contact_notes(self, batch):
 
        """
 
        Get extra "contact notes" which should be made visible to the
 
        user who is entering the new order.
 
        """
 
        notes = []
 
        customer_required = self.new_order_requires_customer()
 

	
 
        invalid = False
 
        if customer_required:
 
            if batch.customer:
 
                invalid = [email for email in batch.customer.emails
0 comments (0 inline, 0 general)