Exemplo 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
    })
Exemplo n.º 2
0
def create_invoice(request, id):
    order = Order.objects.filter_current_company().get(id=id)

    if request.method == "POST":
        form = CreateInvoiceForm(request.POST)

        if form.is_valid():
            #Create order based on offer
            invoice_number = request.POST['invoice_number']
            invoice = Invoice()
            invoice.invoice_number = invoice_number
            invoice.order_id = order.id
            invoice.copy_from(order)

            #Archive the offer
            order.archived = True
            order.save()

            return redirect('app.invoices.views.view', invoice.id)

    else:
        form = CreateInvoiceForm()

    return render(
        request, "orders/create_invoice.html", {
            'title': order.title,
            'order': order,
            'next_invoice_number': Invoice.calculate_next_invoice_number(),
            'form': form
        })
Exemplo n.º 3
0
def invoice(app):
    with app.app_context():
        invoice = Invoice(number=0,
                          order_id=1,
                          invoice_status_code="IS2",
                          invoice_details="Factura pagada por Crédito")
        db.session.add(invoice)
        db.session.commit()
        return invoice
Exemplo n.º 4
0
def create_invoice(request, id):
    order = Order.objects.filter_current_company().get(id=id)

    if request.method == "POST":
        form = CreateInvoiceForm(request.POST)

        if form.is_valid():
            #Create order based on offer
            invoice_number = request.POST['invoice_number']
            invoice = Invoice()
            invoice.invoice_number = invoice_number
            invoice.order_id = order.id
            invoice.copy_from(order)

            #Archive the offer
            order.archived = True
            order.save()

            return redirect('app.invoices.views.view', invoice.id)

    else:
        form = CreateInvoiceForm()

    return render(request, "orders/create_invoice.html", {'title': order.title,
                                                          'order': order,
                                                          'next_invoice_number': Invoice.calculate_next_invoice_number()
        ,
                                                          'form': form})
Exemplo n.º 5
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})
Exemplo n.º 6
0
    def seed_orders(self):
        print "orders"
        for i in range(1, 12):
            order, created = Order.objects.get_or_create(
                title="Order %s" % i,
                delivery_date=datetime.now() + timedelta(days=i),
                customer=self.customers[int(random.random() * 9)],
                project=self.projects[int(random.random() * 9)],
                status="%s" % int(random.random() * 3),
                company=self.company)

            if not i % 3:
                Invoice.objects.get_or_create(
                    title="Invoice %s" % i,
                    invoice_number=Invoice.calculate_next_invoice_number(),
                    company=self.company,
                    delivery_date=datetime.now() + timedelta(days=i),
                    customer=self.customers[int(random.random() * 9)],
                    project=self.projects[int(random.random() * 9)],
                    status="%s" % int(random.random() * 3),
                    order=order)
Exemplo n.º 7
0
Arquivo: seed.py Projeto: frecar/focus
    def seed_orders(self):
        print "orders"
        for i in range(1, 12):
            order, created = Order.objects.get_or_create(
                title="Order %s" % i,
                delivery_date=datetime.now() + timedelta(days=i),
                customer=self.customers[int(random.random() * 9)],
                project=self.projects[int(random.random() * 9)],
                status="%s" % int(random.random() * 3),
                company=self.company,
            )

            if not i % 3:
                Invoice.objects.get_or_create(
                    title="Invoice %s" % i,
                    invoice_number=Invoice.calculate_next_invoice_number(),
                    company=self.company,
                    delivery_date=datetime.now() + timedelta(days=i),
                    customer=self.customers[int(random.random() * 9)],
                    project=self.projects[int(random.random() * 9)],
                    status="%s" % int(random.random() * 3),
                    order=order,
                )