Exemplo n.º 1
0
 def post(self):
     try:
         data = request.get_json(force=True)
         order = Order(int(data["id_supplier"]),
                       int(data["id_client"]),
                       datetime.datetime.strptime(data["expected_delivery_date"], "%Y-%m-%d").date(),
                       str(data["payment_type"]),
                       str(data["l_dips"]),
                       str(data["appro_ship_sample"]),
                       str(data["appro_s_off"]),
                       str(data["ship_sample_2h"]))
         products = []
         total_amount = 0
         for p in data["products"]:
             product = Product(int(order.get_id_order()),
                               str(p["reference"]),
                               str(p["color"]),
                               float(p["meter"]),
                               float(p["price"]),
                               float(p["commission"]))
             products.append(product)
             self.product_db.add_product(product)
             total_amount += float(p["commission"]) * float(p["price"]) * float(p["meter"])
         order.set_total_amount(total_amount)
         self.order_db.add_order(order)
         return HttpResponse(HttpStatus.OK).get_response()
     except (ValueError, WritingDataBaseError, KeyError, werkzeug.exceptions.BadRequest) as e:
         return HttpResponse(HttpStatus.Bad_Request, message=str(e)).get_response()
Exemplo n.º 2
0
 def delete(self):
     try:
         id_shipment = request.args.get("id_shipment")
         self.shipment_db.delete_shipment(id_shipment)
         return HttpResponse(HttpStatus.OK).get_response()
     except (werkzeug.exceptions.BadRequest, ValueError) as e:
         return HttpResponse(HttpStatus.Bad_Request,
                             message=str(e)).get_response()
Exemplo n.º 3
0
 def delete(self):
     try:
         id_partner = request.args.get("id_partner")
         self.partner_db.delete_partner(id_partner)
         return HttpResponse(HttpStatus.OK).get_response()
     except (werkzeug.exceptions.BadRequest, ValueError) as e:
         return HttpResponse(HttpStatus.Bad_Request,
                             message=str(e)).get_response()
Exemplo n.º 4
0
 def delete(self):
     try:
         id_order = request.args.get("id_order")
         self.order_db.delete_order(id_order)
         products = self.product_db.get_products(id_order)
         for i in products:
             self.product_db.delete_product(i["id_product"])
         return HttpResponse(HttpStatus.OK).get_response()
     except (werkzeug.exceptions.BadRequest, ValueError) as e:
         return HttpResponse(HttpStatus.Bad_Request, message=str(e)).get_response()
Exemplo n.º 5
0
 def post(self):
     try:
         data = request.get_json(force=True)
         partner = Partner(str(data["partner_type"]), str(data["company"]))
         self.partner_db.add_partner(partner)
         return HttpResponse(HttpStatus.OK).get_response()
     except (ValueError, WritingDataBaseError, KeyError,
             werkzeug.exceptions.BadRequest) as e:
         return HttpResponse(HttpStatus.Bad_Request,
                             message=str(e)).get_response()
Exemplo n.º 6
0
 def post(self):
     try:
         data = request.get_json(force=True)
         shipment = Shipment(
             datetime.datetime.strptime(data["expedition_date"],
                                        "%d-%m-%Y").date(),
             str(data["transportation"]), str(data["departure_location"]),
             str(data["arrival_location"]))
         self.shipment_db.add_shipment(shipment)
         # for id_product in data["products"]:
         # ProductDataBase.indicate_shipment_date(id_product, shipment.get__id_shipment)
         return HttpResponse(HttpStatus.OK).get_response()
     except (ValueError, WritingDataBaseError, KeyError,
             werkzeug.exceptions.BadRequest) as e:
         return HttpResponse(HttpStatus.Bad_Request,
                             message=str(e)).get_response()
Exemplo n.º 7
0
 def get(self):
     try:
         if request.args.get("id_order"):
             id_order = request.args.get("id_order")
             order = self.order_db.get_order(id_order)
             if order is not None:
                 order["products"] = self.product_db.get_products(id_order)
             return HttpResponse(HttpStatus.OK,
                                 data=order).get_response()
         else:
             orders = self.order_db.get_all_orders()
             for order in orders:
                 order["products"] = self.product_db.get_products(order["id_order"])
             return HttpResponse(HttpStatus.OK,
                                 data=orders).get_response()
     except (werkzeug.exceptions.BadRequest) as e:
         return HttpResponse(HttpStatus.Bad_Request, message=str(e)).get_response()
Exemplo n.º 8
0
 def get(self):
     try:
         if request.args.get("id_partner"):
             id_partner = request.args.get("id_partner")
             partner = self.partner_db.get_partner(id_partner)
             return HttpResponse(HttpStatus.OK, data=partner).get_response()
         elif request.args.get("partner_type"):
             partner_type = request.args.get("partner_type")
             if partner_type == "supplier":
                 suppliers = self.partner_db.get_suppliers()
                 return HttpResponse(HttpStatus.OK,
                                     data=suppliers).get_response()
             elif partner_type == "client":
                 clients = self.partner_db.get_clients()
                 return HttpResponse(HttpStatus.OK,
                                     data=clients).get_response()
         else:
             return HttpResponse(
                 HttpStatus.OK,
                 data=self.partner_db.get_all_partners()).get_response()
     except (werkzeug.exceptions.BadRequest, ValueError) as e:
         return HttpResponse(HttpStatus.Bad_Request,
                             message=str(e)).get_response()