Example #1
0
def SqlDatas2SellRecord(datas):
    rec = SellRecord()
    rec.uid = str(datas[0])
    rec.product_class = str(datas[1])
    rec.product_type = datas[2]
    rec.deal_unit_price = str(datas[3])
    rec.amount = str(datas[4])
    rec.buyer = str(datas[5])
    rec.deal_price = str(datas[6])
    rec.deal_date = datas[
        7]  # datetime.datetime.strptime(datas[7], "%Y-%m-%d").strftime("%Y-%m-%d")
    rec.paid = str(datas[8])
    rec.buyer_name = datas[9]

    rec.total_price = str(float(rec.deal_unit_price) * float(rec.amount))
    rec.unpaid = str(float(rec.deal_price) - float(rec.paid))
    return rec
Example #2
0
File: views.py Project: Panmax/xlhw
def api_remain(request):  # 进出库
    if request.method == 'GET':
        goods_id = request.GET.get('goods_id')
        shop_id = request.GET.get('shop_id')
        goodsshop = GoodsShop.objects.get(goods=Goods.objects.get(id=goods_id), shop=Shop.objects.get(id=shop_id))
        return render_to_response('meizu/modal_change.html', {'request': request, 'goodsshop': goodsshop})
    elif request.method == 'POST':
        user = request.user
        if not user:
            return HttpResponse("false")
        shop_id = request.POST['shop_id']
        goods_id = request.POST['goods_id']
        action = request.POST.get('action')
        number = request.POST.get('number')
        remark = request.POST.get('remark')
        if number is not None and (not user.is_superuser):
            return HttpResponse('stop')

        goodsshop = GoodsShop.objects.get(goods__id=goods_id, shop__id=shop_id)
        goods = Goods.objects.get(id=goods_id)
        shop = Shop.objects.get(id=shop_id)
        if action == 'sub':
            goodsshop.remain -= 1
            if goodsshop.remain < 0:
                return HttpResponse('chaoguo')
            goodsshop.save()

            # recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num -= 1

            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            goods_record = GoodsRecord(goods=goods, shop=shop, change_num=-1, updater=user)
            sell_record = SellRecord(shop=shop, goods=goods, amount=1, updater=user)
            sell_record.save()
            goods_record.sell_record = sell_record
            goods_record.save()
        elif action == 'add':
            goodsshop.remain += 1
            goodsshop.save()

            # recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num += 1
            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            goods_record = GoodsRecord(goods=goods, shop=shop, change_num=1, updater=user)
            goods_record.save()
        elif number:
            goodsshop.remain += int(number)
            if goodsshop.remain < 0:
                return HttpResponse('chaoguo')
            goodsshop.save()

            # recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num += int(number)
            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            if number < 0:
                sell_record = SellRecord(shop=shop, goods=goods, amount=number, updater=user)
                sell_record.save()
                goods_record = GoodsRecord(goods=goods, shop=shop, change_num=number, updater=user, remark=remark)
                goods_record.sell_record = sell_record
                goods_record.save()
            else:
                goods_record = GoodsRecord(goods=goods, shop=shop, change_num=number, updater=user, remark=remark)
                goods_record.save()

        goods.recent_sell = datetime.date.today()
        goods.save()

        return HttpResponse(goodsshop.remain)
Example #3
0
    def GetSellRecord(self):
        category_str = self.m_choice8.GetStringSelection()
        category_int = models.ALL_PRODUCT_TYPE[category_str]
        rec = SellRecord()
        rec.product_class = category_int
        rec.product_type = self.m_choice2.GetStringSelection()
        rec.deal_unit_price = self.m_textCtrl8.GetValue()
        rec.amount = self.m_textCtrl6.GetValue()
        rec.deal_price = self.m_textCtrl10.GetValue()
        rec.deal_date = str(self.m_datePicker3.GetValue().Format("%Y-%m-%d"))
        rec.paid = self.m_textCtrl11.GetValue()
        rec.buyer_name = self.m_choice3.GetStringSelection()

        buyer = db.GetBuyer(rec.buyer_name, self.all_buyers)
        rec.buyer = buyer.uid

        rec.total_price = str(float(rec.deal_unit_price) * float(rec.amount))
        rec.unpaid = str(float(rec.deal_price) - float(rec.paid))
        return rec
Example #4
0
	def GetSellRecord(self):
		category_str        = self.m_choice8.GetStringSelection()
		category_int        = models.ALL_PRODUCT_TYPE[category_str]
		rec                 = SellRecord()
		rec.product_class   = category_int
		rec.product_type    = self.m_choice2.GetStringSelection()
		rec.deal_unit_price = self.m_textCtrl8.GetValue()
		rec.amount          = self.m_textCtrl6.GetValue()
		rec.deal_price      = self.m_textCtrl10.GetValue()
		rec.deal_date       = str(self.m_datePicker3.GetValue().Format("%Y-%m-%d"))
		rec.paid            = self.m_textCtrl11.GetValue()
		rec.buyer_name      = self.m_choice3.GetStringSelection()
		
		buyer               = db.GetBuyer(rec.buyer_name, self.all_buyers)
		rec.buyer           = buyer.uid
		
		rec.total_price     = str(float(rec.deal_unit_price) * float(rec.amount))
		rec.unpaid          = str(float(rec.deal_price) - float(rec.paid))
		return rec
Example #5
0
File: views.py Project: qutlyk/xlhw
def api_remain(request):  # 进出库
    if request.method == 'GET':
        goods_id = request.GET.get('goods_id')
        shop_id = request.GET.get('shop_id')
        goodsshop = GoodsShop.objects.get(goods=Goods.objects.get(id=goods_id),
                                          shop=Shop.objects.get(id=shop_id))
        return render_to_response('modal_change.html', {
            'request': request,
            'goodsshop': goodsshop
        })
    elif request.method == 'POST':
        user = request.user
        if not user:
            return HttpResponse("false")
        shop_id = request.POST['shop_id']
        goods_id = request.POST['goods_id']
        action = request.POST.get('action')
        number = request.POST.get('number')
        remark = request.POST.get('remark')
        if number is not None and (not user.is_superuser):
            return HttpResponse('stop')

        goodsshop = GoodsShop.objects.get(goods__id=goods_id, shop__id=shop_id)
        goods = Goods.objects.get(id=goods_id)
        shop = Shop.objects.get(id=shop_id)
        if action == 'sub':
            goodsshop.remain -= 1
            if goodsshop.remain < 0:
                return HttpResponse('chaoguo')
            goodsshop.save()

            # recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num -= 1

            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            goods_record = GoodsRecord(goods=goods,
                                       shop=shop,
                                       change_num=-1,
                                       updater=user)
            sell_record = SellRecord(shop=shop,
                                     goods=goods,
                                     amount=1,
                                     updater=user)
            sell_record.save()
            goods_record.sell_record = sell_record
            goods_record.save()
        elif action == 'add':
            goodsshop.remain += 1
            goodsshop.save()

            # recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num += 1
            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            goods_record = GoodsRecord(goods=goods,
                                       shop=shop,
                                       change_num=1,
                                       updater=user)
            goods_record.save()
        elif number:
            goodsshop.remain += int(number)
            if goodsshop.remain < 0:
                return HttpResponse('chaoguo')
            goodsshop.save()

            recent_record = GoodsRecord.objects.order_by('-date')[0]
            # if recent_record.shop.id == int(shop_id) and recent_record.goods.id == int(
            # goods_id) and recent_record.updater == user:
            # recent_record.change_num += int(number)
            # recent_record.save()
            #
            # # 如果是0就删除
            # if recent_record.change_num == 0:
            # recent_record.delete()
            # else:
            if number < 0:
                sell_record = SellRecord(shop=shop,
                                         goods=goods,
                                         amount=number,
                                         updater=user)
                sell_record.save()
                goods_record = GoodsRecord(goods=goods,
                                           shop=shop,
                                           change_num=number,
                                           updater=user,
                                           remark=remark)
                goods_record.sell_record = sell_record
                goods_record.save()
            else:
                goods_record = GoodsRecord(goods=goods,
                                           shop=shop,
                                           change_num=number,
                                           updater=user,
                                           remark=remark)
                goods_record.save()

        goods.recent_sell = datetime.date.today()
        goods.save()

        return HttpResponse(goodsshop.remain)
Example #6
0
def SqlDatas2SellRecord(datas):
    rec = SellRecord()
    rec.uid = str(datas[0])
    rec.product_class = str(datas[1])
    rec.product_type = datas[2]
    rec.deal_unit_price = str(datas[3])
    rec.amount = str(datas[4])
    rec.buyer = str(datas[5])
    rec.deal_price = str(datas[6])
    rec.deal_date = datas[7]  # datetime.datetime.strptime(datas[7], "%Y-%m-%d").strftime("%Y-%m-%d")
    rec.paid = str(datas[8])
    rec.buyer_name = datas[9]

    rec.total_price = str(float(rec.deal_unit_price) * float(rec.amount))
    rec.unpaid = str(float(rec.deal_price) - float(rec.paid))
    return rec