Esempio n. 1
0
def migrate_address(doc):
    from locations.models import Address, Country
    from accounts.models import Account
    from users.models import Profile
    from utils import utils
    add = Address()
    add.type = 'user'
    add.profile = Profile.objects.get(primary_phone=doc['mobile'])
    add.name = doc.get('deliveryName','')
    add.phone = doc.get('deliveryPhone','')
    add.pincode = doc.get('pincode2','')
    if doc.get('address2','').strip():
        add.address = doc.get('address2','')
    if doc.get('country2','').strip():
        add.country = utils.get_or_create_country(doc.get('country2',''))
    else:
        add.country = Country.objects.get(name='India')
    if doc.get('state2','').strip():
        add.state = utils.get_or_create_state(doc.get('state2',''), add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2',''), add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)
Esempio n. 2
0
def migrate_address(doc):
    from locations.models import Address, Country
    from accounts.models import Account
    from users.models import Profile
    from utils import utils
    add = Address()
    add.type = 'user'
    add.profile = Profile.objects.get(primary_phone=doc['mobile'])
    add.name = doc.get('deliveryName', '')
    add.phone = doc.get('deliveryPhone', '')
    add.pincode = doc.get('pincode2', '')
    if doc.get('address2', '').strip():
        add.address = doc.get('address2', '')
    if doc.get('country2', '').strip():
        add.country = utils.get_or_create_country(doc.get('country2', ''))
    else:
        add.country = Country.objects.get(name='India')
    if doc.get('state2', '').strip():
        add.state = utils.get_or_create_state(doc.get('state2', ''),
                                              add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2', ''),
                                                add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)
Esempio n. 3
0
def save_billing_info(request, user, data, **kwargs):
    from orders.models import BillingInfo
    try:
        billing_info = BillingInfo.objects.select_related('address').get(
            user=user)
        address = billing_info.address
    except BillingInfo.DoesNotExist:
        billing_info = BillingInfo()
        address = Address()
        address.created_on = datetime.now()
    address.profile = user
    address.address = data['billing_address']

    country_name = data['billing_country']
    country = get_or_create_country(country_name, True)

    city_name = data['billing_city']
    city = get_or_create_city(city_name, address.state, True)

    address.city = city
    address.country = country
    address.phone = data['billing_phone']
    address.pincode = data['billing_pincode']
    address.first_name = data['billing_first_name']
    address.last_name = data['billing_last_name']
    if data['billing_state']:
        state_name = data['billing_state']
        is_reverse = True
        if 'not_reverse' in kwargs:
            is_reverse = False
        state = get_or_create_state(state_name, country, True)
        address.state = state
    if data['email']:
        address.email = data['email']
    address.type = 'billing'
    address.save()

    billing_info.address = address
    billing_info.user = user
    billing_info.phone = data['billing_phone']
    billing_info.first_name = data['billing_first_name']
    billing_info.last_name = data['billing_last_name']

    billing_info.save()
    return address, billing_info
Esempio n. 4
0
def save_billing_info(request, user, data, **kwargs):
    from orders.models import BillingInfo

    try:
        billing_info = BillingInfo.objects.select_related("address").get(user=user)
        address = billing_info.address
    except BillingInfo.DoesNotExist:
        billing_info = BillingInfo()
        address = Address()
        address.created_on = datetime.now()
    address.profile = user
    address.address = data["billing_address"]

    country_name = data["billing_country"]
    country = get_or_create_country(country_name, True)

    city_name = data["billing_city"]
    city = get_or_create_city(city_name, address.state, True)

    address.city = city
    address.country = country
    address.phone = data["billing_phone"]
    address.pincode = data["billing_pincode"]
    address.first_name = data["billing_first_name"]
    address.last_name = data["billing_last_name"]
    if data["billing_state"]:
        state_name = data["billing_state"]
        is_reverse = True
        if "not_reverse" in kwargs:
            is_reverse = False
        state = get_or_create_state(state_name, country, True)
        address.state = state
    if data["email"]:
        address.email = data["email"]
    address.type = "billing"
    address.save()

    billing_info.address = address
    billing_info.user = user
    billing_info.phone = data["billing_phone"]
    billing_info.first_name = data["billing_first_name"]
    billing_info.last_name = data["billing_last_name"]

    billing_info.save()
    return address, billing_info
Esempio n. 5
0
        add.country = Country.objects.get(name='India')
    if doc.get('state2','').strip():
        add.state = utils.get_or_create_state(doc.get('state2',''), add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2',''), add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)


    addr = Address()
    addr.type = 'user'
    addr.profile = Profile.objects.get(primary_phone=doc['mobile'])
    addr.name = doc.get('name','')
    addr.phone = doc.get('mobile','')
    addr.pincode = doc.get('pincode','')
    if doc.get('address','').strip():
        addr.address = doc.get('address','')
    if doc.get('country','').strip():
        addr.country = utils.get_or_create_country(doc.get('country',''))
    else:
        addr.country = Country.objects.get(name='India')
    if doc.get('state','').strip():
        addr.state = utils.get_or_create_state(doc.get('state',''), addr.country, True)
        if doc.get('city', ''):
            addr.city = utils.get_or_create_city(doc.get('city',''), addr.state, True)
    try:
Esempio n. 6
0
    if doc.get('state2', '').strip():
        add.state = utils.get_or_create_state(doc.get('state2', ''),
                                              add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2', ''),
                                                add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)

    addr = Address()
    addr.type = 'user'
    addr.profile = Profile.objects.get(primary_phone=doc['mobile'])
    addr.name = doc.get('name', '')
    addr.phone = doc.get('mobile', '')
    addr.pincode = doc.get('pincode', '')
    if doc.get('address', '').strip():
        addr.address = doc.get('address', '')
    if doc.get('country', '').strip():
        addr.country = utils.get_or_create_country(doc.get('country', ''))
    else:
        addr.country = Country.objects.get(name='India')
    if doc.get('state', '').strip():
        addr.state = utils.get_or_create_state(doc.get('state', ''),
                                               addr.country, True)
        if doc.get('city', ''):
            addr.city = utils.get_or_create_city(doc.get('city', ''),