예제 #1
0
def purchase_create_ajax(request):
    if request.method == 'POST': # If the form has been submitted...    
        if request.is_ajax():           
            post_data = request.POST.copy()
            post_data = json.loads(post_data.keys()[0])  # need to fix that, now all inputs are as key
            
            print request.FILES
            
            purchaseRequestForm = PurchaseRequestForm(post_data['id_purchaseRequestForm'] or None)
            purchase_costForm = Purchase_costForm(post_data['id_purchase_costForm'] or None)
            purchaseDocForm = PurchaseDocForm(post_data['id_purchaseDocForm'] or None)
            #form4 = PurchaseDocForm(request.POST or None)
            
            if purchaseRequestForm.is_valid() and purchase_costForm.is_valid():
                if purchaseDocForm.is_valid():
                    filename = handle_uploaded_file(request.FILES['doc'])
                    purchaseDocForm.files = filename
            
                    purchaseDocForm_instance = purchaseDocForm.save()
                else:
                    purchaseDocForm_instance = None
                    
                purchase_cost_instance = purchase_costForm.save()
                asset_group_instance = purchaseRequestForm.save(cost=purchase_cost_instance,
                                                                person=request.user,
                                                                docs=purchaseDocForm_instance)
                


                json_ser = Serializer()
                availdata = json_ser.serialize([asset_group_instance])
                avail_json_data = JSONEncoder().encode(availdata)
                
                return HttpResponse(avail_json_data, mimetype='application/json')
                
            else:
                json_ser = Serializer()
                availdata = json_ser.serialize({'id_purchaseRequestForm':purchaseRequestForm.errors,
                                                'id_purchase_costForm':purchase_costForm.errors,
                                                'id_purchaseDocForm':purchaseDocForm.errors})
        
                avail_json_data = JSONEncoder().encode(availdata)
                return HttpResponseBadRequest(avail_json_data, mimetype='application/json',status=400)                
예제 #2
0
def Collect_feeds_action_back(request):

    obj_list = Messages.objects.process()
    #obj_list = Messages.objects.all()
    fields = ['title','updated','author','link']

    if request.is_ajax():
        json_ser = Serializer()
        availdata = json_ser.serialize(obj_list)
        
        avail_json_data = JSONEncoder().encode(availdata)
        return HttpResponse(avail_json_data, mimetype='application/json')
    else:    
        return render_to_response('generic_list_nodetails.html',{'item_list':obj_list,'fields':fields},context_instance=RequestContext(request))
예제 #3
0
def Supplies_add_view_search(request):
    if request.is_ajax():
        storename = request.GET.get('store')
        pid = request.GET.get('pid').strip()
        name = '%s_%s' % (storename,pid)
            
        # first check if the object exists
        inputdict = {'suppliers':{'name':storename},'suppliers_PID':pid}
        
        search_obj = ItemTemplate.objects.get_or_create(**inputdict)
        print 'lllll', search_obj
        json_ser = Serializer()
        availdata = json_ser.serialize(search_obj)
        #avail_json_data = json.dumps(availdata,use_decimal=True)
        avail_json_data = JSONEncoder().encode(availdata)
        return HttpResponse(avail_json_data, mimetype='application/json')
예제 #4
0
def sell_search(request):
    if request.is_ajax():
        # add purchase filter, get asset group nad
        if request.GET['sell'] != '':
            sellobj = SellRequest.objects.get(pk=request.GET['sell'])
            
            assetobj = sellobj.items.all()
            
            costobj = sell_cost.objects.get(sellingrequest=sellobj)
            
            res = {}
            res['shortname'] = assetobj[0].item.itemproduct.shortname
            res['imagepath'] = assetobj[0].item.itemproduct.mainimagepath
            res['quantity'] = len(list(assetobj))


            

            res['sellprice'] = costobj.sellprice
            res['tax_charged']  = costobj.tax_charged if costobj.tax_charged != None else 0.0
            res['shipping_handling']  = costobj.shipping_handling if costobj.shipping_handling != None else 0.0
            
            res['account_product_tax'] = costobj.account_product_tax.__unicode__()
            res['shipping'] = costobj.shipping if costobj.shipping != None else 0.0
            res['account_shipping'] = costobj.account_shipping.__unicode__() if costobj.account_shipping != None else res['account_product_tax']
            res['financialcharge'] = costobj.financialcharge if costobj.financialcharge != None else 0.0
            res['account_financial'] = costobj.account_financial.__unicode__() if costobj.account_financial != None else res['account_product_tax']
            res['commission'] = costobj.commission if costobj.commission != None else 0.0
            res['account_commission'] = costobj.account_commission.__unicode__() if costobj.account_commission != None else res['account_product_tax']
            
            json_ser = Serializer()
            availdata = json_ser.serialize([res])
            
            avail_json_data = JSONEncoder().encode(availdata)
            return HttpResponse(avail_json_data, mimetype='application/json')
            
        else:
                # filter sell by querydict
            cus_filter = {}
            
            if request.GET['year'] != '' and request.GET['month'] != '':
                
                dateend= datetime.datetime.strptime(str(int(request.GET['month'])+1)+'/01/'+request.GET['year'],"%m/%d/%Y")
                datestart = datetime.datetime.strptime(request.GET['month'] + '/01/'+request.GET['year'],"%m/%d/%Y")
                
                cus_filter['sellingplatformslot__orderon__range'] = [datestart,dateend]

            
            sellobj = SellRequest.objects.filter(**cus_filter).order_by('sellingplatformslot__orderon')
            
            res_list = []
            for obj in sellobj:
                assetobj = obj.items.all()
                res = {}
                res['id'] = obj.id
                res['shortname'] = assetobj[0].item.itemproduct.shortname
                res['imagepath'] = assetobj[0].item.itemproduct.mainimagepath
                res['quantity'] = len(list(assetobj))
                res['platform'] = obj.sale_platform().name
                res['customer'] = obj.custom.__unicode__()
                res['orderon'] = obj.order_on().date()
                res['tracking'] = obj.tracking_number()
                res['fullfilled'] = obj.fullfilled
                res['estimate'] = asset.objects.summarize_estimates(assetobj)
                res_list.append(res)
  
            # get sell summary
            summary = {}
            total_profit = 0
            for item in res_list:
                total_profit += item['estimate']['profit']
                
            summary['profit'] = total_profit
            summary['ntrans'] = len(res_list)
            
            
            json_ser = Serializer()
            availdata = json_ser.serialize([summary,res_list])
            
            avail_json_data = JSONEncoder().encode(availdata)
            return HttpResponse(avail_json_data, mimetype='application/json')               
    
    else:
       
        cus_filter = {}
        
        dateend= datetime.datetime.strptime(str(int(4)+1)+'/01/'+'2012',"%m/%d/%Y")
        datestart = datetime.datetime.strptime('4' + '/01/'+'2012',"%m/%d/%Y")
        
        cus_filter['sellingplatformslot__orderon__range'] = [datestart,dateend]

        
        sellobj = SellRequest.objects.filter(**cus_filter).order_by('sellingplatformslot__orderon')
        
        res_list = []
        for obj in sellobj:
            assetobj = obj.items.all()
            res = {}
            res['id'] = obj.id
            res['shortname'] = assetobj[0].item.itemproduct.shortname
            res['imagepath'] = assetobj[0].item.itemproduct.mainimagepath
            res['quantity'] = len(list(assetobj))
            res['platform'] = obj.sale_platform().name
            res['customer'] = obj.custom.__unicode__()
            res['orderon'] = obj.order_on().date()
            res['tracking'] = obj.tracking_number()
            res['fullfilled'] = obj.fullfilled
            res['estimate'] = asset.objects.summarize_estimates(assetobj)
            res_list.append(res)


        
        json_ser = Serializer()
        availdata = json_ser.serialize(res_list)
        
        avail_json_data = JSONEncoder().encode(availdata)
        return HttpResponse(avail_json_data, mimetype='application/json')        
예제 #5
0
def purchase_search(request):
    if request.is_ajax():
        # add purchase filter, get asset group nad
        if 'purchase' in request.GET.keys() and request.GET['purchase'] != '':
            purobj = PurchaseRequest.objects.get(pk=request.GET['purchase'])
            costobj = Purchase_cost.objects.get(request=purobj)
            
            res = {}
            res['shortname'] = purobj.item.itemproduct.shortname
            res['imagepath'] = purobj.item.itemproduct.mainimagepath
            res['quantity'] = purobj.quantity
            res['storage'] = purobj.storage.nickname
            res['person'] = purobj.person.username

            
            
            res['productcost'] = costobj.productcost
            res['tax']  = costobj.tax if costobj.tax != None else 0.0
            res['account_product_tax'] = costobj.account_product_tax.__unicode__()
            res['shipping'] = costobj.shipping if costobj.shipping != None else 0.0
            res['account_shipping'] = costobj.account_shipping.__unicode__() if costobj.account_shipping != None else res['account_product_tax']
            res['commission'] = costobj.commission if costobj.commission != None else 0.0
            res['account_commission'] = costobj.account_commission.__unicode__() if costobj.account_commission != None else res['account_product_tax']
            json_ser = Serializer()
            availdata = json_ser.serialize([res])

        else:  # querybase search
            cus_filter = {}
            
            if request.GET['year'] != '' and request.GET['month'] != '':
                
                dateend= datetime.datetime.strptime(str(int(request.GET['month'])+1)+'/01/'+request.GET['year'],"%m/%d/%Y")
                datestart = datetime.datetime.strptime(request.GET['month'] + '/01/'+request.GET['year'],"%m/%d/%Y")
                
                cus_filter['orderon__range'] = [datestart,dateend]
                
                purchaseobj = PurchaseRequest.objects.filter(**cus_filter).order_by('orderon')
                
                res_list = []
                for obj in purchaseobj:
                    assetobj = obj.assets.all()
                    res = {}
                    res['id'] = obj.id
                    res['shortname'] = assetobj[0].item.itemproduct.shortname
                    res['imagepath'] = assetobj[0].item.itemproduct.mainimagepath
                    res['quantity'] = len(list(assetobj))
                    res['orderon'] = obj.orderon.date()
                    res_list.append(res)
                
            json_ser = Serializer()
            availdata = json_ser.serialize(res_list)

        avail_json_data = JSONEncoder().encode(availdata)
        return HttpResponse(avail_json_data, mimetype='application/json')      
    
    else:
       
        purobj = PurchaseRequest.objects.get(pk=2)

        res = {}
        res['shortname'] = purobj.item.itemproduct.shortname
        res['imagepath'] = purobj.item.itemproduct.mainimagepath
        res['quantity'] = purobj.quantity
        res['storage'] = purobj.storage.nickname
        res['person'] = purobj.person.username
        json_ser = Serializer()
        availdata = json_ser.serialize([res])

        
        avail_json_data = JSONEncoder().encode(availdata)
        return HttpResponse(avail_json_data, mimetype='application/json')