Example #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)
Example #2
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
Example #3
0
    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)


    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)
Example #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
Example #5
0
def new_order(atg_order, tinla_profile, client):
    # Ensure that there is no profile with this atg login
    map_entry = None
    try:
        map_entry = AtgOrderMigrationMap.objects.select_related('order').get(
            atg_order=atg_order.order.order)
        log.info("Already migrated %s, skipping new_order" %
                 atg_order.order.order)
        return map_entry.order
    except AtgOrderMigrationMap.DoesNotExist:
        pass

    # create new order
    order = Order()
    order.user = tinla_profile
    order.state = get_order_state(atg_order.order.order_state)
    order.timestamp = atg_order.order.atg_creation_date
    order.payment_realized_on = atg_order.order.atg_submitted_date
    order.modified_on = atg_order.order.last_modified_date
    order.reference_order_id = atg_order.order.order
    order.client = client

    order.save()

    # delivery info
    shipping = DcsppShipGroup.objects.filter(order_ref=atg_order.order.order)
    if shipping:
        shipping = shipping[0]
        dcspp_addr = DcsppShipAddr.objects.filter(
            shipping_group=shipping.shipping_group)
        if dcspp_addr:
            shipping = dcspp_addr[0]
            if shipping:
                addr = Address()
                addr.profile = tinla_profile
                addr.account = client.account_set.all()[0]
                addr.first_name = shipping.first_name
                addr.last_name = shipping.last_name
                addr.phone = shipping.phone_number
                addr.email = shipping.email
                addr.pincode = shipping.postal_code
                country, state, city = '', '', ''
                try:
                    if shipping.county: country = get_country(shipping.county)
                    if shipping.state and country:
                        state = get_state(shipping.state.state_name, country)
                    if shipping.city and state:
                        city = get_city(shipping.city, state)
                    if country: addr.country = country
                    if state: addr.state = state
                    if city: addr.city = city
                except:
                    pass

                addr.save()

                del_info = DeliveryInfo()
                del_info.address = addr
                del_info.order = order
                del_info.save()

    order_items = atg_order.order.dcspporderitem_set.all()
    list_price_total, shipping_charges = Decimal(0), Decimal(0)
    for atg_oi in order_items:
        oi = OrderItem()
        ci = atg_oi.commerce_items
        oi.order = order
        oi.state = get_order_state(ci.state)
        try:
            src = SellerRateChart.objects.get(sku=ci.sku.sku.sku_id,
                                              seller__client=client)
            oi.seller_rate_chart = src
        except SellerRateChart.DoesNotExist:
            pass

        oi.list_price = ci.amount_info.list_price
        list_price_total += ci.amount_info.list_price

        oi.sale_price = ci.amount_info.sale_price

        del_item = FtbShipitemRel.objects.filter(
            relationship__commerce_item=atg_oi)
        if del_item:
            del_item = del_item[0]
            oi.shipping_charges = del_item.shipping_cost
            shipping_charges += del_item.shipping_cost
            "shipping found for ", atg_order.order

        oi.qty = ci.quantity
        oi.save()

    # amount info
    order_discount_total = Decimal(str(atg_order.ord_misc_field1))
    sale_price_total = atg_order.order.price_info.raw_subtotal

    total_order_shipping = atg_order.order.price_info.shipping + shipping_charges
    order.shipping_charges = total_order_shipping
    order.list_price_total = list_price_total
    order.total = sale_price_total
    order.payable_amount = sale_price_total + total_order_shipping - order_discount_total
    order.save()

    print order.id
    print order.reference_order_id

    # map entry
    map_entry = AtgOrderMigrationMap(order=order,
                                     atg_order=atg_order.order.order)
    map_entry.save()
Example #6
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)
Example #7
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', ''):
Example #8
0
def new_order(atg_order, tinla_profile, client):
    # Ensure that there is no profile with this atg login
    map_entry = None
    try:
        map_entry = AtgOrderMigrationMap.objects.select_related('order').get(
                        atg_order = atg_order.order.order)
        log.info("Already migrated %s, skipping new_order" % atg_order.order.order)
        return map_entry.order
    except AtgOrderMigrationMap.DoesNotExist:
        pass

    # create new order
    order = Order()
    order.user = tinla_profile
    order.state = get_order_state(atg_order.order.order_state)
    order.timestamp = atg_order.order.atg_creation_date
    order.payment_realized_on = atg_order.order.atg_submitted_date
    order.modified_on = atg_order.order.last_modified_date
    order.reference_order_id = atg_order.order.order
    order.client = client

    order.save()

    # delivery info
    shipping = DcsppShipGroup.objects.filter(order_ref = atg_order.order.order)
    if shipping: 
        shipping = shipping[0]
        dcspp_addr = DcsppShipAddr.objects.filter(shipping_group=shipping.shipping_group)
        if dcspp_addr:
            shipping = dcspp_addr[0]
            if shipping:
                addr = Address()
                addr.profile = tinla_profile
                addr.account = client.account_set.all()[0]
                addr.first_name = shipping.first_name
                addr.last_name = shipping.last_name
                addr.phone = shipping.phone_number
                addr.email = shipping.email
                addr.pincode = shipping.postal_code
                country, state, city = '', '', ''
                try:
                    if shipping.county: country = get_country(shipping.county)
                    if shipping.state and country: state = get_state(shipping.state.state_name, country)
                    if shipping.city and state: city = get_city(shipping.city, state)
                    if country: addr.country = country
                    if state: addr.state = state
                    if city: addr.city = city
                except:
                    pass

                addr.save()

                del_info = DeliveryInfo()
                del_info.address = addr
                del_info.order = order
                del_info.save()


    order_items = atg_order.order.dcspporderitem_set.all()
    list_price_total, shipping_charges = Decimal(0), Decimal(0)
    for atg_oi in order_items:
        oi = OrderItem()
        ci = atg_oi.commerce_items
        oi.order = order
        oi.state = get_order_state(ci.state)
        try:
            src = SellerRateChart.objects.get(sku=ci.sku.sku.sku_id, seller__client = client)
            oi.seller_rate_chart = src
        except SellerRateChart.DoesNotExist:
            pass

        oi.list_price = ci.amount_info.list_price
        list_price_total += ci.amount_info.list_price
        
        oi.sale_price = ci.amount_info.sale_price

        del_item = FtbShipitemRel.objects.filter(relationship__commerce_item = atg_oi)
        if del_item:
            del_item = del_item[0]
            oi.shipping_charges = del_item.shipping_cost
            shipping_charges += del_item.shipping_cost
            "shipping found for ", atg_order.order

        oi.qty = ci.quantity
        oi.save()

    # amount info
    order_discount_total = Decimal(str(atg_order.ord_misc_field1))
    sale_price_total = atg_order.order.price_info.raw_subtotal

    total_order_shipping = atg_order.order.price_info.shipping + shipping_charges
    order.shipping_charges = total_order_shipping
    order.list_price_total = list_price_total
    order.total = sale_price_total
    order.payable_amount = sale_price_total + total_order_shipping - order_discount_total
    order.save()

    print order.id
    print order.reference_order_id

    # map entry
    map_entry = AtgOrderMigrationMap(order = order, atg_order = atg_order.order.order)
    map_entry.save()