예제 #1
0
파일: orders.py 프로젝트: Fantas-LeoTao/amc
    def get(self, id):
        order = OrderModel.query.get(id)
        if not order:
            abort(404, u'订单不存在')
        if order.user_id != current_user.id:
            # 非当前用户的订单
            abort(403, u'非当前用户订单')
        if order.status not in self.STATUS_ALLOW:
            # 订单处于不被允许取消的状态
            abort(403, u'订单不允许取消')

        # 修改库存
        for item in order.products:
            product = item.product
            product.quantity += item.product_quantity
            product.date_updated = now()
            product.save()
            # 这里不能delete,否则取消掉的订单为空订单
            # item.delete()

        # 更新状态,载入历史
        order.update(
            status=OrderModel.STATUS_CANCEL,
            date_updated=now())
        OrderHistoryModel.create(
            order_id=id,
            status=order.status,
            operator_id=current_user.id)

        return redirect(url_for('user.order'))
예제 #2
0
    def get(self, id):
        order = OrderModel.query.get(id)
        if not order:
            abort(404, u'订单不存在')
        if order.user_id != current_user.id:
            # 非当前用户的订单
            abort(403, u'非当前用户订单')
        if order.status not in self.STATUS_ALLOW:
            # 订单处于不被允许取消的状态
            abort(403, u'订单不允许取消')

        # 修改库存
        for item in order.products:
            product = item.product
            product.quantity += item.product_quantity
            product.date_updated = now()
            product.save()
            # 这里不能delete,否则取消掉的订单为空订单
            # item.delete()

        # 更新状态,载入历史
        order.update(status=OrderModel.STATUS_CANCEL, date_updated=now())
        OrderHistoryModel.create(order_id=id,
                                 status=order.status,
                                 operator_id=current_user.id)

        return redirect(url_for('user.order'))
예제 #3
0
 def get(self):
     timeline = now() - timedelta(days=30)
     pays = (PayModel.query.filter(
         PayModel.status == PayModel.STATUS_PENDING).filter(
             PayModel.date_created < timeline).order_by(
                 PayModel.date_created.desc()).all())
     return render_template(self.template, pays=pays)
예제 #4
0
파일: orders.py 프로젝트: Fantas-LeoTao/amc
    def get(self, id):
        order = OrderModel.query.get(id)
        if not order:
            abort(404, u'订单不存在')
        if order.user_id != current_user.id:
            # 非当前用户的订单
            abort(403, u'非当前用户订单')
        if order.status != OrderModel.STATUS_DISPATCH:
            # 订单处不处于货物发出状态
            abort(403, u'订单未发货')

        # 更新状态,载入历史
        order.update(
            status=OrderModel.STATUS_SUCCESS,
            date_updated=now())
        OrderHistoryModel.create(
            order_id=id,
            status=order.status,
            operator_id=current_user.id)

        # 生成收款单
        PayModel.create(
            order_id=id,
            amount=order.order_price)

        return redirect(url_for('user.order'))
예제 #5
0
 def get(self):
     timeline = now() - timedelta(days=30)
     pays = (PayModel.query
             .filter(PayModel.status == PayModel.STATUS_PENDING)
             .filter(PayModel.date_created < timeline)
             .order_by(PayModel.date_created.desc())
             .all())
     return render_template(self.template, pays=pays)
예제 #6
0
파일: panel.py 프로젝트: Fantas-LeoTao/amc
    def put(self, id):
        schema = {
            'status': schema_dict['status'],
        }
        order_info = request.get_json()
        v = AmcValidator(schema)
        if not v(order_info):
            abort(422)

        order = OrderModel.query.get(id)
        if not order:
            abort(404)

        # 不被允许的情况,403
        status = order_info.get('status')
        if (status == OrderModel.STATUS_CONFIRM and
                order.status != OrderModel.STATUS_LAUNCH):
            abort(403)
        if (status == OrderModel.STATUS_DISPATCH and
                order.status != OrderModel.STATUS_CONFIRM):
            abort(403)
        if (status == OrderModel.STATUS_CANCEL and
                order.status in [OrderModel.STATUS_DISPATCH,
                                 OrderModel.STATUS_SUCCESS,
                                 OrderModel.STATUS_CANCEL]):
            abort(403)

        order_info['date_updated'] = now()
        order.update(**order_info)

        # 若管理员取消订单,则修改库存
        if (status == OrderModel.STATUS_CANCEL):
            for item in order.products:
                product = item.product
                product.quantity += item.product_quantity
                product.date_updated = now()
                product.save()

        # 添加到订单修改历史
        OrderHistoryModel.create(
            order_id=order.id,
            status=order.status,
            operator_id=current_user.id)

        return jsonify(order.as_dict()), 200
예제 #7
0
    def put(self, id):
        schema = {
            'status': schema_dict['status'],
        }
        order_info = request.get_json()
        v = AmcValidator(schema)
        if not v(order_info):
            abort(422)

        order = OrderModel.query.get(id)
        if not order:
            abort(404)

        # 不被允许的情况,403
        status = order_info.get('status')
        if (status == OrderModel.STATUS_CONFIRM
                and order.status != OrderModel.STATUS_LAUNCH):
            abort(403)
        if (status == OrderModel.STATUS_DISPATCH
                and order.status != OrderModel.STATUS_CONFIRM):
            abort(403)
        if (status == OrderModel.STATUS_CANCEL and order.status in [
                OrderModel.STATUS_DISPATCH, OrderModel.STATUS_SUCCESS,
                OrderModel.STATUS_CANCEL
        ]):
            abort(403)

        order_info['date_updated'] = now()
        order.update(**order_info)

        # 若管理员取消订单,则修改库存
        if (status == OrderModel.STATUS_CANCEL):
            for item in order.products:
                product = item.product
                product.quantity += item.product_quantity
                product.date_updated = now()
                product.save()

        # 添加到订单修改历史
        OrderHistoryModel.create(order_id=order.id,
                                 status=order.status,
                                 operator_id=current_user.id)

        return jsonify(order.as_dict()), 200
예제 #8
0
 def get(self, id):
     due = DueModel.query.get(id)
     if not due:
         abort(404, u'付款单未找到')
     if due.status == DueModel.STATUS_PAID:
         abort(422, u'付款单不被允许修改')
     due.status = DueModel.STATUS_PAID
     due.date_updated = now()
     due.save()
     return redirect(url_for('.due_list'))
예제 #9
0
 def get(self, id):
     due = DueModel.query.get(id)
     if not due:
         abort(404, u'付款单未找到')
     if due.status == DueModel.STATUS_PAID:
         abort(422, u'付款单不被允许修改')
     due.status = DueModel.STATUS_PAID
     due.date_updated = now()
     due.save()
     return redirect(url_for('.due_list'))
예제 #10
0
파일: orders.py 프로젝트: Fantas-LeoTao/amc
    def get(self):
        items = current_user.trolley.products
        if not items:
            abort(404, u'购物车为空')

        flag = False
        # 判断有没有库存不够
        for item in items:
            if item.lacked_quantity != 0:
                # 某件产品库存不足,添加缺件记录
                flag = True
                LackedProductHistoryModel.create(
                    product_id=item.product_id,
                    user_id=current_user.id,
                    quantity=item.lacked_quantity)

        if flag:
            abort(409, u'产品库存不足')

        # 创建订单,载入历史
        order = OrderModel.create(user_id=current_user.id)
        OrderHistoryModel.create(
            order_id=order.id,
            status=order.status,
            operator_id=current_user.id)

        # 填充订单信息,将购物车结账清算
        for item in items:
            product = item.product
            OrderProductModel.create(
                order_id=order.id,
                product_id=item.product_id,
                product_quantity=item.product_quantity,
                product_price=product.price)

            # 修改库存
            product.quantity -= item.product_quantity
            product.date_updated = now()
            product.save()

            # 修改库存低于安全库存自动新增采购
            # 但是采购成本不固定,需要管理员新建采购单
            if not product.is_safe:
                pass

            # 清空购物车
            item.delete()

        return redirect(url_for('user.order'))
예제 #11
0
    def get(self):
        results = dict()
        start_date = (now() - timedelta(days=29)).date()
        timeline = datetime(start_date.year, start_date.month, start_date.day)
        # 这里订单量销售额定义为交易成功订单
        orders = (OrderModel.query.filter(
            OrderModel.date_created >= timeline).filter(
                OrderModel.status == OrderModel.STATUS_SUCCESS).all())
        for order in orders:
            timestamp = order.date_created.strftime('%Y-%m-%d')
            if not results.get(timestamp):
                results[timestamp] = [0, 0]
            results[timestamp][0] += 1
            results[timestamp][1] += order.order_price

        return jsonify(results), 200
예제 #12
0
    def get(self):
        items = current_user.trolley.products
        if not items:
            abort(404, u'购物车为空')

        flag = False
        # 判断有没有库存不够
        for item in items:
            if item.lacked_quantity != 0:
                # 某件产品库存不足,添加缺件记录
                flag = True
                LackedProductHistoryModel.create(product_id=item.product_id,
                                                 user_id=current_user.id,
                                                 quantity=item.lacked_quantity)

        if flag:
            abort(409, u'产品库存不足')

        # 创建订单,载入历史
        order = OrderModel.create(user_id=current_user.id)
        OrderHistoryModel.create(order_id=order.id,
                                 status=order.status,
                                 operator_id=current_user.id)

        # 填充订单信息,将购物车结账清算
        for item in items:
            product = item.product
            OrderProductModel.create(order_id=order.id,
                                     product_id=item.product_id,
                                     product_quantity=item.product_quantity,
                                     product_price=product.price)

            # 修改库存
            product.quantity -= item.product_quantity
            product.date_updated = now()
            product.save()

            # 修改库存低于安全库存自动新增采购
            # 但是采购成本不固定,需要管理员新建采购单
            if not product.is_safe:
                pass

            # 清空购物车
            item.delete()

        return redirect(url_for('user.order'))
예제 #13
0
파일: panel.py 프로젝트: Fantas-LeoTao/amc
    def get(self):
        results = dict()
        start_date = (now() - timedelta(days=29)).date()
        timeline = datetime(start_date.year, start_date.month, start_date.day)
        # 这里订单量销售额定义为交易成功订单
        orders = (OrderModel.query
                  .filter(OrderModel.date_created >= timeline)
                  .filter(OrderModel.status == OrderModel.STATUS_SUCCESS)
                  .all())
        for order in orders:
            timestamp = order.date_created.strftime('%Y-%m-%d')
            if not results.get(timestamp):
                results[timestamp] = [0, 0]
            results[timestamp][0] += 1
            results[timestamp][1] += order.order_price

        return jsonify(results), 200
예제 #14
0
 def post(self, id):
     product = ProductModel.query.get(id)
     if not product:
         abort(404, u'产品未找到')
     form = ProductInfoForm()
     if not form.validate_on_submit():
         return render_template(self.template, form=form)
     product.name = form.name.data
     product.category = form.category.data
     product.img = form.img.data
     product.description = form.description.data
     product.price = form.price.data
     product.quantity = form.quantity.data
     product.safe_quantity = form.safe_quantity.data
     product.made_in = form.made_in.data
     product.date_updated = now()
     product.save()
     return redirect(url_for('.detail', id=product.id))
예제 #15
0
 def post(self, id):
     product = ProductModel.query.get(id)
     if not product:
         abort(404, u'产品未找到')
     form = ProductInfoForm()
     if not form.validate_on_submit():
         return render_template(self.template, form=form)
     product.name = form.name.data
     product.category = form.category.data
     product.img = form.img.data
     product.description = form.description.data
     product.price = form.price.data
     product.quantity = form.quantity.data
     product.safe_quantity = form.safe_quantity.data
     product.made_in = form.made_in.data
     product.date_updated = now()
     product.save()
     return redirect(url_for('.detail', id=product.id))
예제 #16
0
    def get(self, id):
        order = OrderModel.query.get(id)
        if not order:
            abort(404, u'订单不存在')
        if order.user_id != current_user.id:
            # 非当前用户的订单
            abort(403, u'非当前用户订单')
        if order.status != OrderModel.STATUS_DISPATCH:
            # 订单处不处于货物发出状态
            abort(403, u'订单未发货')

        # 更新状态,载入历史
        order.update(status=OrderModel.STATUS_RETURN, date_updated=now())
        OrderHistoryModel.create(order_id=id,
                                 status=order.status,
                                 operator_id=current_user.id)

        return redirect(url_for('user.order'))
예제 #17
0
    def get(self, id):
        purchase = PurchaseModel.query.get(id)
        if not purchase:
            abort(404, u'采购单未找到')
        if purchase.status == PurchaseModel.STATUS_OVER:
            abort(403, u'采购已结束')
        product = ProductModel.query.get(purchase.product_id)
        if not product:
            abort(404, u'产品未找到')
        purchase.status = PurchaseModel.STATUS_OVER
        purchase.save()
        product.quantity += purchase.product_quantity
        product.date_updated = now()
        product.save()

        # 生成应付款账单
        DueModel.create(purchase_id=id, amount=purchase.total_cost)

        return redirect(url_for('.list'))
예제 #18
0
    def get(self):
        results = dict()
        start_date = (now() - timedelta(days=6)).date()
        timeline = datetime(start_date.year, start_date.month, start_date.day)
        orders = (OrderModel.query.filter(
            OrderModel.status == OrderModel.STATUS_SUCCESS).filter(
                OrderModel.date_created > timeline).all())
        for order in orders:
            products = order.products
            for item in products:
                product_id = item.product_id
                product_name = item.product.name
                product_quantity = item.product_quantity
                total_price = item.total_price
                if not results.get(product_id):
                    results[product_id] = [product_name, 0, 0]
                results[product_id][1] += product_quantity
                results[product_id][2] += total_price

        return jsonify(results), 200
예제 #19
0
    def get(self, id):
        purchase = PurchaseModel.query.get(id)
        if not purchase:
            abort(404, u'采购单未找到')
        if purchase.status == PurchaseModel.STATUS_OVER:
            abort(403, u'采购已结束')
        product = ProductModel.query.get(purchase.product_id)
        if not product:
            abort(404, u'产品未找到')
        purchase.status = PurchaseModel.STATUS_OVER
        purchase.save()
        product.quantity += purchase.product_quantity
        product.date_updated = now()
        product.save()

        # 生成应付款账单
        DueModel.create(
            purchase_id=id,
            amount=purchase.total_cost)

        return redirect(url_for('.list'))
예제 #20
0
파일: panel.py 프로젝트: Fantas-LeoTao/amc
    def get(self):
        results = dict()
        start_date = (now() - timedelta(days=6)).date()
        timeline = datetime(start_date.year, start_date.month, start_date.day)
        orders = (OrderModel.query
                  .filter(OrderModel.status == OrderModel.STATUS_SUCCESS)
                  .filter(OrderModel.date_created > timeline)
                  .all())
        for order in orders:
            products = order.products
            for item in products:
                product_id = item.product_id
                product_name = item.product.name
                product_quantity = item.product_quantity
                total_price = item.total_price
                if not results.get(product_id):
                    results[product_id] = [product_name, 0, 0]
                results[product_id][1] += product_quantity
                results[product_id][2] += total_price

        return jsonify(results), 200
예제 #21
0
    def get(self, id):
        pay = PayModel.query.get(id)
        if not pay:
            abort(404, u'收款单未找到')
        if pay.status == PayModel.STATUS_RECEIVED:
            abort(422, u'收款单不被允许修改')
        pay.status = PayModel.STATUS_RECEIVED
        pay.date_updated = now()
        pay.save()

        # 处理客户信誉,目前只有下降
        if (pay.date_updated - timedelta(days=30) > pay.date_created):
            user = pay.order.user
            credit = user.credit
            if not credit:
                # never happen
                pass
            index = UserModel.CREDIT.index(credit)
            index = index - 1 if index != 0 else 0
            user.update(credit=UserModel.CREDIT[index])

        return redirect(url_for('.pay_list'))
예제 #22
0
    def get(self, id):
        pay = PayModel.query.get(id)
        if not pay:
            abort(404, u'收款单未找到')
        if pay.status == PayModel.STATUS_RECEIVED:
            abort(422, u'收款单不被允许修改')
        pay.status = PayModel.STATUS_RECEIVED
        pay.date_updated = now()
        pay.save()

        # 处理客户信誉,目前只有下降
        if (pay.date_updated - timedelta(days=30)
                > pay.date_created):
            user = pay.order.user
            credit = user.credit
            if not credit:
                # never happen
                pass
            index = UserModel.CREDIT.index(credit)
            index = index - 1 if index != 0 else 0
            user.update(credit=UserModel.CREDIT[index])

        return redirect(url_for('.pay_list'))