billendpoints.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Restaurant-API-V2 作者: RobusGauli 项目源码 文件源码
def setBill():

    with SessionManager(Session) as session:
        try:
            total_price = request.json['total_price']
            on_site = request.json.get('on_site')
            customer_id = request.json['customer_id']
            dinetable_id = request.json['dinetable_id']
            employee_id = request.json['employee_id']
            payment_id = request.json['payment_id']
            vat_id = request.json['vat_id']
            service_charge_id = request.json['service_charge_id']
            bill_description = request.json.get('bill_description', 'NA')


            item_orders = request.json['item_orders']

            if len(item_orders) < 1:
                return jsonify(error_envelop(400, 'BillError', 'Please enter atleast one item!!'))
            #if there is more than one elements in bills then create a new bill object
            bill = Bill(total_price=total_price,
                        bill_description=bill_description,
                        on_site=on_site,
                        customer_id=customer_id,
                        dinetable_id=dinetable_id,
                        employee_id=employee_id,
                        payment_id=payment_id,
                        vat_id=vat_id,
                        service_charge_id=service_charge_id)
            session.add(bill)

            for item_order in item_orders:
                item_id = item_order['item_id']
                quantity = item_order['quantity']
                order_price = item_order['order_price']
                session.add(ItemOrder(item_id=item_id,
                                quantity=quantity,
                                order_price=order_price,
                                bill=bill))



            session.commit()
            return jsonify(post_envelop(200, data = request.json))

        except DataError: #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))
        except IntegrityError:
            return jsonify(error_envelop(400, 'IntegrityError','Foreign Key violations. Use the correct id'))


        except:
            return jsonify(error_envelop(400, 'UnknownError', 'Error need to be identified'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号