@treeio_login_required
@handle_response_format
def order_add(request, lead_id=None, opportunity_id=None, response_format='html'):
 lead = None
 opportunity = None
 if lead_id:
  lead = get_object_or_404(Lead, pk=lead_id)
 if opportunity_id:
  opportunity = get_object_or_404(Opportunity, pk=opportunity_id)
 if request.POST:
  if ('cancel' not in request.POST):
   order = SaleOrder()
   form = OrderForm(request.user.profile, lead, opportunity, request.POST, instance=order)
   if form.is_valid():
    order = form.save()
    order.set_user_from_request(request)
    return HttpResponseRedirect(reverse('sales_order_view', args=[order.id]))
  else:
   return HttpResponseRedirect(reverse('sales'))
 else:
  form = OrderForm(request.user.profile, lead, opportunity)
 all_products = Object.filter_by_request(request, Product.objects.filter(parent__isnull=True))
 return render_to_response('sales/order_add', {'form': form, 'products': all_products}, context_instance=RequestContext(request), response_format=response_format)

@ treeio_login_required @ handle_response_format def order_add ( request , lead_id = None , opportunity_id = None , response_format = 'html' ) : lead = None opportunity = None if lead_id : lead = get_object_or_404 ( Lead , pk = lead_id ) if opportunity_id : opportunity = get_object_or_404 ( Opportunity , pk = opportunity_id ) if request . POST : if ( 'cancel' not in request . POST ) : order = SaleOrder ( ) form = OrderForm ( request . user . profile , lead , opportunity , request . POST , instance = order ) if form . is_valid ( ) : order = form . save ( ) order . set_user_from_request ( request ) return HttpResponseRedirect ( reverse ( 'sales_order_view' , args = [ order . id ] ) ) else : return HttpResponseRedirect ( reverse ( 'sales' ) ) else : form = OrderForm ( request . user . profile , lead , opportunity ) all_products = Object . filter_by_request ( request , Product . objects . filter ( parent__isnull = True ) ) return render_to_response ( 'sales/order_add' , { 'form' : form , 'products' : all_products } , context_instance = RequestContext ( request ) , response_format = response_format )
order add .