def post(self):
        args = parser.parse_args()
        name = args['name']
        items_id = args['items']
        destination = args['address']
        creation_date = datetime.datetime.now()

        bill = 0

        # Update items availability in inventory
        for item_id in items_id:
            resp_get_item = requests.get("http://inventory:5000/items/" +
                                         item_id)
            data = resp_get_item.json()
            curr_availability = data['availability']
            resp_update_item = requests.put("http://inventory:5000/items/"+\
            item_id, json={'availability': curr_availability - 1})

            bill += data['price']

        # TODO: add id and delivery at saving Order

        order = Order( name=name, bill=bill, items=items_id, \
         creation_date=creation_date, destination=destination)
        order.save()

        resp_create_delivery = requests.post("http://tracking:5000/tracking", \
         json={'destination': destination, 'order_id': str(order._id)})
        print(resp_create_delivery.text, '\n\n')
        order.delivery_id = resp_create_delivery.json()['_id']
        order.save()
        return jsonify(pretty(order))
def create_order(json):
    # Rating an SDR file
    customer_data = json['customer']

    total  = json['total']
    amount = json['subtotal']
    vat    = json['taxes']

    currency = 'EUR'

    account_id  = customer_data['tef_account']
    country     = customer_data['country']
    order_code  = compute_uuid()

    account = Account.objects.get(account_id=account_id)

    order = Order(account=account, total=total, currency=currency, country=country, order_code=order_code, payment_method=None, amount=amount, vat=vat)
    order.save()

    json['order'] = order.to_dict()

    return (json, None)
Exemplo n.º 3
0
def create_selenium_dummy_order(from_raw, to_raw):
    order = Order(passenger=SELENIUM_PASSENGER,
                  station=SELENIUM_STATION,
                  status=ACCEPTED,
                  from_city=City.objects.get(name="תל אביב יפו"),
                  from_country=Country.objects.get(code="IL"),
                  from_geohash=u'swnvcbdruxgz',
                  from_lat=u'32',
                  from_lon=u'34',
                  from_raw=from_raw,
                  from_street_address=u'street1',
                  to_city=City.objects.get(name="תל אביב יפו"),
                  to_country=Country.objects.get(code="IL"),
                  to_geohash=u'swnvcbdruxgz',
                  to_lat=u'32',
                  to_lon=u'34',
                  to_raw=to_raw,
                  to_street_address=u'street2',
                  create_date=datetime.datetime.now() -
                  datetime.timedelta(hours=1))
    order.save()

    return order
Exemplo n.º 4
0
def create_selenium_dummy_order(from_raw, to_raw):
    order = Order(
        passenger=SELENIUM_PASSENGER,
        station=SELENIUM_STATION,
        status=ACCEPTED,
        from_city=City.objects.get(name="תל אביב יפו"),
        from_country=Country.objects.get(code="IL"),
        from_geohash=u"swnvcbdruxgz",
        from_lat=u"32",
        from_lon=u"34",
        from_raw=from_raw,
        from_street_address=u"street1",
        to_city=City.objects.get(name="תל אביב יפו"),
        to_country=Country.objects.get(code="IL"),
        to_geohash=u"swnvcbdruxgz",
        to_lat=u"32",
        to_lon=u"34",
        to_raw=to_raw,
        to_street_address=u"street2",
        create_date=datetime.datetime.now() - datetime.timedelta(hours=1),
    )
    order.save()

    return order
Exemplo n.º 5
0
def order(request):
    cart = Cart(request)
    if cart.get_summary_quantity() == 0:
        return redirect('main-page')
    if request.method == 'GET':
        form = CustomerForm()
        return render(request, 'ordering/index.html', {'form': form, 'cart': cart})
    if request.method == 'POST':
        post = request.POST
        form = CustomerForm(request.POST)
        try:
            customer = Customer.objects.get(first_name=post.get('first_name'), last_name=post.get('last_name'),
                                            phone_number=post.get('phone_number'))
        except Customer.DoesNotExist as err:
            print(err)
            if {'first_name', 'last_name', 'phone_number'} < set(post.keys()):
                customer = Customer(first_name=post['first_name'], last_name=post['last_name'],
                                    phone_number=post['phone_number'])
                customer.save()
        if not customer:
            return JsonResponse({'message': 'error'})
        order = Order()
        order.status = 'made'
        order.address = post.get('address')
        order.customer = customer
        order.save()
        # print(customer)
        cart = Cart(request)
        for position in cart.get_products():
            order_position = OrderPosition()
            order_position.product = position['product']
            order_position.quantity = position['quantity']
            order_position.order = order
            order.save()
        print(order)
        return render(request, 'ordering/index.html', {'form': form, 'cart': cart})