def search_records_using(searchtype): soapheaders = get_soapheaders() if soapheaders: soapheaders['searchPreferences'] = SearchPreferences( bodyFieldsOnly=False, returnSearchColumns=True, pageSize=20) return get_service().search(searchRecord=searchtype, _soapheaders=soapheaders)
def create_cashsale_salesorder(data, sale_models): addressee = '%s %s' % (data.first_name, data.last_name) shipping_address = prepare_address(addressee, data.shipping_address) billing_address = prepare_address(addressee, data.billing_address) raw_item = [ sale_models['item'](item=get_item_reference(item), quantity=item.quantity) for item in data.line_items ] item_list = sale_models['item_list'](item=raw_item) customer = get_or_create_customer(prepare_customer_data(data)) sale_data = { 'itemList': item_list, 'entity': RecordRef(internalId=customer.internalId), 'email': data.email, 'shippingAddress': Address(**shipping_address), 'billingAddress': Address(**billing_address), 'ccExpireDate': datetime(int(data.expiration_date_year), int(data.expiration_date_month), 1), 'ccNumber': data.credit_card_number, 'ccName': data.credit_card_owner, 'ccSecurityCode': data.cvc2, 'shippingCost': data.shipping_cost } if sale_models['sale'] == SalesOrder: sale_data['shipAddressList'] = ListOrRecordRef(internalId=2) sale = sale_models['sale'](**sale_data) response = get_service().add(sale, _soapheaders={ 'passport': passport, 'applicationInfo': app_info }) r = response.body.writeResponse if r.status.isSuccess: record_type = None if sale_models['sale'] == SalesOrder: record_type = 'salesOrder' else: record_type = 'cashSale' result = get_record_by_type(record_type, r.baseRef.internalId) return True, result return False, r
def get_multiple(array_of_record_references): soapheaders = get_soapheaders() if not array_of_record_references: return None if len(array_of_record_references) <= 0: return None if not soapheaders: return None response = get_service().getList(array_of_record_references, _soapheaders=soapheaders) return response
def get_or_create_customer(customer_data): soapheaders = get_soapheaders() if not soapheaders: return None """ Lookup customer, add a customer if lookup fails. """ internal_id = lookup_customer_id_by_name_and_email(customer_data) if not internal_id: customer_data['entityId'] = str(uuid.uuid4()) customer = Customer(**customer_data) response = get_service().add(customer, _soapheaders=soapheaders) r = response.body.writeResponse if r.status.isSuccess: internal_id = r.baseRef.internalId return get_customer(internal_id)
def delete(record): return _call(record, get_service().delete)
def update(record): return _call(record, get_service().update)
def add(record): return _call(record, get_service().add)
def get(record): return _call(record, get_service().get)