diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 55cbdacf8533c8fa52332c7ba56b9cf5b3fba920..bfc8ef261805004b51ba3d6a0820b6acd2878ef5 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -108,6 +108,38 @@ class CustomerOrderBatchHandler(BatchHandler): 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