Пример #1
0
def quoted_bill_cal(request):
    old_post = request.session.get('old_post')
    quoted_order_id = request.session.get('quoted_order_id')
    quoted_order = QuotedOrder.objects.get(id=quoted_order_id)
    quoted_order_obj = QuotedOrder.objects.values('total_discount').\
    get(id=quoted_order_id)
    quoted_item = QuotedItem.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('price'))
    total = quoted_item['price__sum']
    price_total = total - quoted_order_obj['total_discount']
    totalplusdelivery = price_total
    surcharge = Surcharge.objects.values('id', 'value', 'taxes_included')
    delivery_rate = Surcharge.objects.values('value').\
    filter(tax_name='Transportation')
    distance = QuotedSuspenseOrder.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('distance_estimated'))
    if distance['distance_estimated__sum']:
        delivery_charges = int(distance['distance_estimated__sum'])*\
            delivery_rate[0]['value']
        totalplusdelivery = totalplusdelivery + delivery_charges

    else:
        delivery_charges = 0

    for value in surcharge:
        surcharge_id = value['id']
        surcharge_value = value['value']
        surcharge_tax = value['taxes_included']
        if surcharge_tax == 1:
            taxes = round((totalplusdelivery * surcharge_value) / 100)
            surcharge_obj = Surcharge.objects.get(id=surcharge_id)
            taxes_applied = QuotedTaxesApplied(quoted_order=quoted_order,
                                               surcharge=surcharge_obj,
                                               tax=taxes)
            taxes_applied.save()
    taxes_applied_obj = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('tax'))
    tax_total = taxes_applied_obj['tax__sum']
    grand_total = price_total + tax_total + delivery_charges
    amount_received = grand_total
    bill = QuotedBill(quoted_order=quoted_order,
                      total_cost=price_total,
                      total_tax=tax_total,
                      grand_total=grand_total,
                      delivery_charges=delivery_charges,
                      amount_received=amount_received,
                      totalplusdelivery=totalplusdelivery)
    bill.save()
    request.session['old_post'] = old_post
    request.session['quoted_order_id'] = quoted_order_id
    return HttpResponseRedirect(reverse("librehatti.bills.views.select_note"))
Пример #2
0
def quoted_bill_cal(request):
    old_post = request.session.get('old_post')
    quoted_order_id = request.session.get('quoted_order_id')
    quoted_order = QuotedOrder.objects.get(id=quoted_order_id)
    quoted_order_obj = QuotedOrder.objects.values('total_discount').\
    get(id=quoted_order_id)
    quoted_item = QuotedItem.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('price'))
    total = quoted_item['price__sum']
    price_total = total - quoted_order_obj['total_discount']
    totalplusdelivery = price_total
    surcharge = Surcharge.objects.values('id', 'value', 'taxes_included')
    delivery_rate = Surcharge.objects.values('value').\
    filter(tax_name='Transportation')
    distance = QuotedSuspenseOrder.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('distance_estimated'))
    if distance['distance_estimated__sum']:
        delivery_charges = int(distance['distance_estimated__sum'])*\
            delivery_rate[0]['value']
        totalplusdelivery = totalplusdelivery + delivery_charges

    else:
        delivery_charges = 0

    for value in surcharge:
        surcharge_id = value['id']
        surcharge_value = value['value']
        surcharge_tax = value['taxes_included']
        if surcharge_tax == 1:
            taxes = round((totalplusdelivery * surcharge_value)/100)
            surcharge_obj = Surcharge.objects.get(id=surcharge_id)
            taxes_applied = QuotedTaxesApplied(quoted_order=quoted_order,
            surcharge=surcharge_obj, tax=taxes)
            taxes_applied.save()
    taxes_applied_obj = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('tax'))
    tax_total = taxes_applied_obj['tax__sum']
    grand_total = price_total + tax_total + delivery_charges
    amount_received = grand_total
    bill = QuotedBill(quoted_order=quoted_order, total_cost=price_total,
    total_tax=tax_total, grand_total=grand_total,
    delivery_charges=delivery_charges, amount_received=amount_received,
    totalplusdelivery=totalplusdelivery)
    bill.save()
    request.session['old_post'] = old_post
    request.session['quoted_order_id'] = quoted_order_id
    return HttpResponseRedirect(reverse("librehatti.bills.views.select_note"))
Пример #3
0
def quoted_bill_cal(request):
    """
    This view calculate taxes on quoted order, bill data
    and save those values in database.
    argument: Http request
    returns: Redirects to select option page after calculatations. 
    """
    old_post = request.session.get('old_post')
    quoted_order_id = request.session.get('quoted_order_id')
    generate_tax = 1
    first_item = QuotedItem.objects.values('item__category__id').\
    filter(quoted_order=quoted_order_id)[0]
    category_check = SpecialCategories.objects.filter(category=
        first_item['item__category__id'])
    if category_check:
        specialcategories = SpecialCategories.objects.values('tax').\
        filter(category=first_item['item__category__id'])[0]
        if specialcategories['tax'] == False:
            generate_tax = 0
    quoted_order = QuotedOrder.objects.get(id=quoted_order_id)
    quoted_order_obj = QuotedOrder.objects.values('total_discount').\
    get(id=quoted_order_id)
    quoted_item = QuotedItem.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('price'))
    total = quoted_item['price__sum']
    price_total = total - quoted_order_obj['total_discount']
    totalplusdelivery = price_total
    surcharge = Surcharge.objects.values('id', 'value', 'taxes_included', 'tax_name')
    delivery_rate = Surcharge.objects.values('value').\
    filter(tax_name='Transportation')
    distance = QuotedSuspenseOrder.objects.\
    filter(quoted_order=quoted_order_id).aggregate(Sum('distance_estimated'))
    if distance['distance_estimated__sum']:
        delivery_charges = int(distance['distance_estimated__sum'])*\
            delivery_rate[0]['value']
        totalplusdelivery = totalplusdelivery + delivery_charges

    else:
        delivery_charges = 0

    for value in surcharge:
        surcharge_id = value['id']
        surcharge_val = value['value']
        surcharge_tax = value['taxes_included']
        if surcharge_tax == 1 and generate_tax == 1:
            taxes = round((totalplusdelivery * surcharge_val)/100)
            surcharge_obj = Surcharge.objects.get(id=surcharge_id)
            taxes_applied = QuotedTaxesApplied(quoted_order=quoted_order,
            surcharge=surcharge_obj, tax=taxes, surcharge_name = value['tax_name'],
                surcharge_value = value['value'])
            taxes_applied.save()
    taxes_applied_temp = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order_id)
    if taxes_applied_temp:
        taxes_applied_obj = QuotedTaxesApplied.objects.\
        filter(quoted_order=quoted_order_id).aggregate(Sum('tax'))
        tax_total = taxes_applied_obj['tax__sum']
    else:
        tax_total = 0
    grand_total = price_total + tax_total + delivery_charges
    amount_received = grand_total
    bill = QuotedBill(quoted_order=quoted_order, total_cost=price_total,
    total_tax=tax_total, grand_total=grand_total,
    delivery_charges=delivery_charges, amount_received=amount_received,
    totalplusdelivery=totalplusdelivery)
    bill.save()
    request.session['old_post'] = old_post
    request.session['quoted_order_id'] = quoted_order_id
    return HttpResponseRedirect(reverse("librehatti.bills.views.select_note"))
Пример #4
0
def quoted_bill_cal(request):
    """
    This view calculate taxes on quoted order, bill data
    and save those values in database.
    argument: Http request
    returns: Redirects to select option page after calculations.
    """
    old_post = request.session.get("old_post")
    quoted_order_id = request.session.get("quoted_order_id")
    generate_tax = 1
    first_item = QuotedItem.objects.values("item__category__id").filter(
        quoted_order=quoted_order_id)[0]
    category_check = SpecialCategories.objects.filter(
        category=first_item["item__category__id"])
    if category_check:
        specialcategories = SpecialCategories.objects.values("tax").filter(
            category=first_item["item__category__id"])[0]
        if not specialcategories["tax"]:
            generate_tax = 0
    quoted_order = QuotedOrder.objects.get(id=quoted_order_id)
    quoted_order_obj = QuotedOrder.objects.values("total_discount").get(
        id=quoted_order_id)
    quoted_item = QuotedItem.objects.filter(
        quoted_order=quoted_order_id).aggregate(Sum("price"))
    total = quoted_item["price__sum"]
    price_total = total - quoted_order_obj["total_discount"]
    totalplusdelivery = price_total
    surcharge = Surcharge.objects.values("id", "value", "taxes_included",
                                         "tax_name")
    delivery_rate = Surcharge.objects.values("value").filter(
        tax_name="Transportation")
    distance = QuotedSuspenseOrder.objects.filter(
        quoted_order=quoted_order_id).aggregate(Sum("distance_estimated"))
    if distance["distance_estimated__sum"]:
        delivery_charges = (int(distance["distance_estimated__sum"]) *
                            delivery_rate[0]["value"])
        totalplusdelivery = totalplusdelivery + delivery_charges

    else:
        delivery_charges = 0

    for value in surcharge:
        surcharge_id = value["id"]
        surcharge_val = value["value"]
        surcharge_tax = value["taxes_included"]
        if surcharge_tax == 1 and generate_tax == 1:
            taxes = round((totalplusdelivery * surcharge_val) / 100)
            surcharge_obj = Surcharge.objects.get(id=surcharge_id)
            taxes_applied = QuotedTaxesApplied(
                quoted_order=quoted_order,
                surcharge=surcharge_obj,
                tax=taxes,
                surcharge_name=value["tax_name"],
                surcharge_value=value["value"],
            )
            taxes_applied.save()
    taxes_applied_temp = QuotedTaxesApplied.objects.filter(
        quoted_order=quoted_order_id)
    if taxes_applied_temp:
        taxes_applied_obj = QuotedTaxesApplied.objects.filter(
            quoted_order=quoted_order_id).aggregate(Sum("tax"))
        tax_total = taxes_applied_obj["tax__sum"]
    else:
        tax_total = 0
    grand_total = price_total + tax_total + delivery_charges
    amount_received = grand_total
    bill = QuotedBill(
        quoted_order=quoted_order,
        total_cost=price_total,
        total_tax=tax_total,
        grand_total=grand_total,
        delivery_charges=delivery_charges,
        amount_received=amount_received,
        totalplusdelivery=totalplusdelivery,
    )
    bill.save()
    request.session["old_post"] = old_post
    request.session["quoted_order_id"] = quoted_order_id
    return HttpResponseRedirect(reverse("bills:select_note"))