예제 #1
0
    def put(self, id=""):
        req = request.form
        print(req)
        body = {'client': "", 'products': []}
        body['client'] = req['client']
        body['products'] = req['products'].split(',')
        if req['isPaid'] == "False":
            body["isPaid"] = False
        else:
            body["isPaid"] = True
        print(body)
        updated = Invoice.update(id, body)

        if updated["count"] == 0:
            result = {
                'message': f"data invoice {id} not update",
                'success': False,
            }
            return jsonify(result)

        result = {
            'message': f"data invoice {id} update",
            'path': {
                'path': f"/invoice/{id}",
                'name': "Invoice",
                'params': {
                    'id': id
                }
            },
            'success': True,
            'updated': updated
        }

        return jsonify(result)
예제 #2
0
파일: invoice.py 프로젝트: kooksee/tobari
def invoice_index():
    """发票列表
    
    不再编写模板,请参考 Person 相关的模板
    有必要掌握 Bootstrap3
    """
    """个人列表
    """

    rank = request.args.get("rank", "id")
    search = request.args.get("search", "")
    order = request.args.get("order", "asc")

    page, per_page, offset = get_page_items()
    invoices = Invoice.find(search=search, order=order, rank=rank)
    for inv in invoices:
        print inv.invoice_date
    pagination = get_pagination(page=page, total=invoices.count())
    return render_template(
        "/invoice/index.html",
        invoices=invoices.offset(offset).limit(per_page),
        pagination=pagination,
        search=search,
        order=order,
    )
예제 #3
0
    def delete(self, id=""):
        if str(request.url_rule) == '/api/product/<string:id>/delete':

            product = Product.deleteProduct(id)
            productIsDelete = Invoice.isProductDelete(product)
            result = {
                "message":
                "le produit ne peut pas être supprimer car il est dans un ou plusieurs invoice",
                "success": False,
                "inInvoice": False
            }

            if not product:
                result[
                    "message"] = "le produit n'existe pas, il ne peut pas y avoir de suppresion"
                result["success"] = False

            if productIsDelete:
                product.delete()
                result["message"] = "la suppression a bien été faites"
                result["success"] = True
                result["inInvoice"] = True

            return jsonify(result)

        return Response(status=404)
예제 #4
0
    def post(self):
        req = request.form
        body = {'client': "", 'products': []}
        body['client'] = req['client']
        body['products'] = req['products'].split(',')

        invoice = Invoice.create(body)

        return redirect('http://localhost:8080/invoices')
예제 #5
0
파일: invoice.py 프로젝트: kooksee/tobari
def invoice_new():
    """添加发票
     
        添加发票时会让用户选择关联帐目,若未选择则自动添加一条帐目
    """
    form = InvoiceForm(request.form)
    form.subject_id.choices = Subject.get_subjects()
    if request.method == "POST" and form.validate():
        inv = Invoice()
        form.populate_obj(inv)
        if request.files[form.picture.name]:
            try:
                pic = Picture(request.files[form.picture.name])
                db.session.add(pic)
                pic.save()
                inv.picture_id = pic.id
            except:
                flash(u"图片保存失败", "error")
        db.session.add(inv)
        inv.save()
        return redirect("/invoice/%d/chioce" % int(inv.id))
    return render_template("/invoice/edit.html", form=form, title=u"添加发票")
예제 #6
0
파일: approval.py 프로젝트: kooksee/tobari
def approval_new():
    """添加审批单
    
    使用 WTForm 来创建表单并验证和获取表单内容
    """
    print('nimei')
    form = ApprovalForm()
    list_subject = [(1, u'公务卡消费'), (2, u'非公务卡消费')]
    form.cost_type.choices = list_subject
    form.subject.choices = Subject.get_subjects()
    print 'nimeimei'
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()
        
        form_list = [form.cost_type, approval.agent_id, form.max_money, approval.id, form.subject]
        invoices = Invoice.find_relation(form_list)
        if invoices[1] == None:
            approval_index = Approval.query.get(approval.id)
            approval_index.invoice_count = invoices[0]
            approval_index.subject_list += (' '+dict(Subject.get_subjects())[form.subject])
            approval_index.status = 'Printed'
            approval.save()
            flash(u'组合成功')
            return redirect('/approval/%d' % int(approval.id))
        return redirect('/approval/%d/chioce' % int(approval.id), incoices) 
    
        
#     if request.method == 'POST' and form.validate():
#         approval = Approval()
#         approval.agent_id = Person.judge(form.agent.data)
#         approval.payee_id = Person.judge(form.payee.data)
#         form.populate_obj(approval)
#         if request.files[form.picture.name]:
#             try:
#                 pic = Picture(request.files[form.picture.name])
#                 db.session.add(pic)
#                 pic.save()
#                 approval.picture_id = pic.id
#             except:
#                 flash(u'图片保存失败', 'error')
#         db.session.add(approval)
#         approval.save()
#         print 'nimei',approval.id
#         flash(u'成功添加审批单')
#         return redirect('/approval/%d' % int(approval.id))
    return render_template('/approval/edit.html', form = form, title=u'添加审批单')
예제 #7
0
    def delete(self, id=""):
        if str(request.url_rule) == '/api/invoice/<string:id>/delete':

            invoice = Invoice.deleteInvoice(id)
            result = {
                "message": "la suppresion a bien été faites",
                "success": True
            }
            if not invoice:
                result[
                    "message"] = "le produit n'existe pas, il ne peut pas y avoir de suppresion"
                result["success"] = False
            return jsonify(result)

        return Response(status=404)
    def delete(self, id=""):
        client = Client.deleteClient(id)

        clientsIsDelete = Invoice.isClientDelete(client)
        result = {
            "message":
            f"data client {id} not delete, le client est dans un invoice",
            "success": False,
            "inInvoice": False
        }

        if clientsIsDelete:
            client.delete()
            result["message"] = "la suppression a bien été faites"
            result["success"] = True
            result["inInvoice"] = True

        return jsonify(result)
예제 #9
0
    def get(self, id=""):

        if str(request.url_rule) == '/api/invoices':

            invoices = Invoice.getAllInvoice()
            result = {
                "message": 'recuperation des factures',
                "success": True,
                "count": len(invoices),
                "results": invoices,
                "unitName": "Invoice"
            }

            return jsonify(result)

        elif str(request.url_rule) == '/api/invoice/<string:id>':
            invoice = Invoice.getInvoice(id)

            productsId = []
            for item in invoice["products"]:
                productsId.append(item['id'])

            result = {
                "message": 'recuperation de la facture ' + str(invoice["id"]),
                "success": True,
                "count": 1,
                "result": invoice,
                "form": {
                    "client": {
                        "type": "multiselect",
                        "placeholder": "Search client...",
                        "name": "clients",
                        "label": "Client",
                        "multiple": False,
                        "value": invoice["client"]["id"]
                    },
                    "products": {
                        "type": "multiselect",
                        "placeholder": "Search products...",
                        "name": "products",
                        "label": "Products",
                        "multiple": True,
                        "value": productsId
                    },
                    "isPaid": {
                        "type": "multiselect",
                        "placeholder": "IsPaid...",
                        "name": "isPaid",
                        "label": "IsPaid",
                        "multiple": False,
                        "value": str(invoice["isPaid"])
                    }
                }
            }

            return jsonify(result)

        if str(request.url_rule) == '/api/invoice/form':
            result = {
                "client": {
                    "type": "multiselect",
                    "placeholder": "Search client...",
                    "name": "clients",
                    "label": "Client",
                    "multiple": False
                },
                "products": {
                    "type": "multiselect",
                    "placeholder": "Search products...",
                    "name": "products",
                    "label": "Products",
                    "multiple": True
                }
            }
            return jsonify(result)

        return Response(status=404)
예제 #10
0
=======
    form = ApprovalForm(request.form)
    form.status.choices = Approval.get_status()
    form.approval_type.choices = Approval.get_approval_type()
>>>>>>> 797deb1d9a238a9098207cfc01bab6963414987f
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
<<<<<<< HEAD
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()
        
        form_list = [form.cost_type, approval.agent_id, form.max_money, approval.id, form.subject]
        invoices = Invoice.find_relation(form_list)
        if invoices[1] == None:
            approval_index = Approval.query.get(approval.id)
            approval_index.invoice_count = invoices[0]
            approval_index.subject_list += (' '+dict(Subject.get_subjects())[form.subject])
            approval_index.status = 'Printed'
            approval.save()
            flash(u'组合成功')
            return redirect('/approval/%d' % int(approval.id))
        return redirect('/approval/%d/chioce' % int(approval.id), incoices) 
    
        
#     if request.method == 'POST' and form.validate():
#         approval = Approval()
#         approval.agent_id = Person.judge(form.agent.data)
#         approval.payee_id = Person.judge(form.payee.data)