def salesinvoice_add(request, **kwargs): """Adds a new sales invoice. """ salesinvoice = SalesInvoice() doc = Document(author=request.user, content_object=salesinvoice) if request.method == 'POST': dform = DocumentForm(request.POST, instance=doc) form = SalesInvoiceForm(request.POST, instance=salesinvoice) formset = ProductEntryFormset(request.POST) if form.is_valid() and dform.is_valid() and formset.is_valid(): form.save() doc.content_object = salesinvoice dform.save() for e in formset.save(): salesinvoice.entries.add(e) messages.success(request, _("The sales invoice was created successfully.")) return redirect_to(request, url=doc.get_absolute_url()) else: dform = DocumentForm(instance=doc) form = SalesInvoiceForm(instance=salesinvoice) formset = ProductEntryFormset() return render_to_response( 'sales/salesinvoice_edit.html', RequestContext(request, { 'form': form, 'dform': dform, 'formset': formset, 'object': doc }))
def salesinvoice_edit(request, id, **kwargs): """Edits a sales invoice. """ doc = get_object_or_404(Document.objects.get_for_content(SalesInvoice), object_id=id) salesinvoice = doc.content_object if request.method == 'POST': dform = DocumentForm(request.POST, instance=doc) form = SalesInvoiceForm(request.POST, instance=salesinvoice) formset = ProductEntryFormset(request.POST, queryset=salesinvoice.entries.all()) if form.is_valid() and dform.is_valid() and formset.is_valid(): form.save() dform.save() for e in formset.save(): salesinvoice.entries.add(e) messages.success(request, _("The sales invoice was updated successfully.")) return redirect_to(request, url=doc.get_absolute_url()) else: dform = DocumentForm(instance=doc) form = SalesInvoiceForm(instance=salesinvoice) formset = ProductEntryFormset(queryset=salesinvoice.entries.all()) return render_to_response( 'sales/salesinvoice_edit.html', RequestContext(request, { 'form': form, 'dform': dform, 'formset': formset, 'object': doc }))
def deliverynote_edit(request, id, **kwargs): """Edits a delivery note. """ doc = get_object_or_404(Document.objects.get_for_content(DeliveryNote), object_id=id) deliverynote = doc.content_object if request.method == 'POST': dform = DocumentForm(request.POST, instance=doc) form = DeliveryNoteForm(request.POST, instance=deliverynote) formset = ProductEntryFormset(request.POST, queryset=deliverynote.entries.all()) if form.is_valid() and dform.is_valid() and formset.is_valid(): form.save() dform.save() for e in formset.save(): deliverynote.entries.add(e) messages.success(request, _("The delivery note was updated successfully.")) return redirect_to(request, url=doc.get_absolute_url()) else: dform = DocumentForm(instance=doc) form = DeliveryNoteForm(instance=deliverynote) formset = ProductEntryFormset(queryset=deliverynote.entries.all()) return render_to_response('stock/deliverynote_edit.html', RequestContext(request, {'form': form, 'dform': dform, 'formset': formset, 'object': doc}))
def deliverynote_add(request, **kwargs): """Adds a new delivery note. """ deliverynote = DeliveryNote() doc = Document(author=request.user, content_object=deliverynote) if request.method == 'POST': dform = DocumentForm(request.POST, instance=doc) form = DeliveryNoteForm(request.POST, instance=deliverynote) formset = ProductEntryFormset(request.POST) if form.is_valid() and dform.is_valid() and formset.is_valid(): form.save() doc.content_object = deliverynote dform.save() for e in formset.save(): deliverynote.entries.add(e) messages.success(request, _("The delivery note was created successfully.")) return redirect_to(request, url=doc.get_absolute_url()) else: dform = DocumentForm(instance=doc) form = DeliveryNoteForm(instance=deliverynote) formset = ProductEntryFormset() return render_to_response('stock/deliverynote_edit.html', RequestContext(request, {'form': form, 'dform': dform, 'formset': formset, 'object': doc}))