def add_business_addresses(business, offices_json): for office_type in offices_json: delivery_address = create_delivery_address( offices_json[office_type]['deliveryAddress']) #business.delivery_address.append(delivery_address) mailing_address = None if offices_json[office_type]['mailingAddress'] == None: # clone delivery to mailing mailing_address = copy.deepcopy(delivery_address) else: mailing_address = Address() mailing_json = offices_json[office_type]['mailingAddress'] mailing_address.city = mailing_json['addressCity'] mailing_address.country = pycountry.countries.search_fuzzy( mailing_json['addressCountry'])[0].alpha_2 mailing_address.delivery_instructions = mailing_json[ 'deliveryInstructions'] mailing_address.postal_code = mailing_json['postalCode'] mailing_address.region = mailing_json['addressRegion'] mailing_address.street = mailing_json['streetAddress'] mailing_address.street_additional = mailing_json[ 'streetAddressAdditional'] mailing_address.address_type = Address.MAILING create_office(business, [mailing_address, delivery_address], office_type)
def create_business_address(business, type): """Create an address.""" from legal_api.models import Address address = Address( city='Test City', street=f'{business.identifier}-Test Street', postal_code='T3S3T3', country='TA', region='BC', ) if type == 'mailing': address.address_type = Address.MAILING business.mailing_address.append(address) else: address.address_type = Address.DELIVERY business.delivery_address.append(address) business.save() return business
def create_business_address(business, type): """Create an address.""" from legal_api.models import Address, Office address = Address( city='Test City', street=f'{business.identifier}-Test Street', postal_code='T3S3T3', country='TA', region='BC', ) if type == 'mailing': address.address_type = Address.MAILING else: address.address_type = Address.DELIVERY office = Office(office_type='registeredOffice') office.addresses.append(address) business.offices.append(office) business.save() return business
def create_delivery_address(delivery_json): delivery_address = Address() delivery_address.address_type = Address.DELIVERY delivery_address.city = delivery_json['addressCity'] # delivery_address.country = delivery_json['addressCountry'] delivery_address.country = 'CA' delivery_address.delivery_instructions = delivery_json['deliveryInstructions'] delivery_address.postal_code = delivery_json['postalCode'] # delivery_address.region = delivery_json['addressRegion'] delivery_address.region = 'BC' delivery_address.street = delivery_json['streetAddress'] delivery_address.street_additional = delivery_json['streetAddressAdditional'] return delivery_address
def create_address(address_json: dict, address_type: Address.ADDRESS_TYPES) -> Address: """Create a new address in lear via the model.""" address = Address() address.address_type = address_type address.city = address_json['addressCity'] address.country = pycountry.countries.search_fuzzy( address_json['addressCountry'])[0].alpha_2 address.delivery_instructions = address_json['deliveryInstructions'] address.postal_code = address_json['postalCode'] address.region = address_json['addressRegion'] address.street = address_json['streetAddress'] address.street_additional = address_json['streetAddressAdditional'] return address