Esempio n. 1
0
def form(request, id=None):
    products = []

    if id:
        instance = get_object_or_404(Invoice, id=id)
        products.extend(instance.product_lines.all())
        invoice_number = instance.invoice_number

    else:
        instance = Invoice()
        invoice_number = Invoice.calculate_next_invoice_number()

    if request.method == "POST":
        form = InvoiceForm(request.POST, instance=instance)
        products = []

        i = 0
        for p in request.POST.getlist('product_number'):
            p = ProductLine()
            p.description = request.POST.getlist('product_description')[i]
            p.price = request.POST.getlist('product_unit_cost')[i]
            p.count = request.POST.getlist('product_qty')[i]

            try:
                product = Product.objects.get(
                    id=int(request.POST.getlist('product_number')[i]))
                p.product = product
            except:
                p.product = None

            products.append(p)
            i += 1

        if form.is_valid():
            o = form.save(commit=False)
            o.save()
            o.update_products(products)

            request.message_success(_("Successfully saved offer"))

            return redirect(view, o.id)
    else:
        form = InvoiceForm(instance=instance,
                           initial={'invoice_number': invoice_number})

    return render(request, "invoices/form.html", {
        'form': form,
        'invoice': instance,
        'products': products
    })
Esempio n. 2
0
def form(request, id=None):
    products = []

    if id:
        instance = get_object_or_404(Invoice, id=id)
        products.extend(instance.product_lines.all())
        invoice_number = instance.invoice_number

    else:
        instance = Invoice()
        invoice_number = Invoice.calculate_next_invoice_number()

    if request.method == "POST":
        form = InvoiceForm(request.POST, instance=instance)
        products = []

        i = 0
        for p in request.POST.getlist("product_number"):
            p = ProductLine()
            p.description = request.POST.getlist("product_description")[i]
            p.price = request.POST.getlist("product_unit_cost")[i]
            p.count = request.POST.getlist("product_qty")[i]

            try:
                product = Product.objects.get(id=int(request.POST.getlist("product_number")[i]))
                p.product = product
            except:
                p.product = None

            products.append(p)
            i += 1

        if form.is_valid():
            o = form.save(commit=False)
            o.save()
            o.update_products(products)

            request.message_success(_("Successfully saved offer"))

            return redirect(view, o.id)
    else:
        form = InvoiceForm(instance=instance, initial={"invoice_number": invoice_number})

    return render(request, "invoices/form.html", {"form": form, "invoice": instance, "products": products})
Esempio n. 3
0
def form(request, id=None):
    products = []

    if id:
        instance = get_object_or_404(Order, id=id)
        products.extend(instance.product_lines.all())
        order_number = instance.order_number
    else:
        instance = Order()
        order_number = Order.calculate_next_order_number()

    if request.method == "POST":
        form = OrderForm(request.POST, instance=instance)
        products = []

        i = 0
        for p in request.POST.getlist('product_number'):
            p = ProductLine()
            p.description = request.POST.getlist('product_description')[i]
            p.price = request.POST.getlist('product_unit_cost')[i]
            p.count = request.POST.getlist('product_qty')[i]
            p.tax = request.POST.getlist('product_tax')[i]

            try:
                p.product = Product.objects.get(
                    id=int(request.POST.getlist('product_number')[i]))
            except Exception, e:
                p.product = None

            products.append(p)

            i += 1

        if form.is_valid():
            o = form.save(commit=False)
            o.save(no_allemployee_group_permissions=True)
            o.update_products(products)

            request.message_success(_("Successfully saved order"))

            return redirect(view, o.id)
Esempio n. 4
0
def form(request, id=None):
    products = []

    if id:
        instance = get_object_or_404(Order, id=id)
        products.extend(instance.product_lines.all())
        order_number = instance.order_number
    else:
        instance = Order()
        order_number = Order.calculate_next_order_number()

    if request.method == "POST":
        form = OrderForm(request.POST, instance=instance)
        products = []

        i = 0
        for p in request.POST.getlist('product_number'):
            p = ProductLine()
            p.description = request.POST.getlist('product_description')[i]
            p.price = request.POST.getlist('product_unit_cost')[i]
            p.count = request.POST.getlist('product_qty')[i]
            p.tax = request.POST.getlist('product_tax')[i]

            try:
                p.product = Product.objects.get(id=int(request.POST.getlist('product_number')[i]))
            except Exception, e:
                p.product = None

            products.append(p)

            i += 1

        if form.is_valid():
            o = form.save(commit=False)
            o.save(no_allemployee_group_permissions=True)
            o.update_products(products)

            request.message_success(_("Successfully saved order"))

            return redirect(view, o.id)