Пример #1
0
def create_order():
    print "creating order..."
    orders = [('Chair x 1000 Orders', 1, 1000),
              ('Round Table x 2000 Orders', 2, 2000)]
    for o in orders:
        order = Order()
        order.name = o[0]
        order.product_id = o[1]
        order.quantity = o[2]
        db.session.add(order)
Пример #2
0
    def mutate(self, info, bakery_id, items, card_number, card_cvv, card_expiration_date, card_holder_name, name, country, state, city, neighborhood, street, street_number, zipcode,):
        data = {
            "card_number":  card_number,
            "card_cvv":  card_cvv,
            "card_expiration_date":  card_expiration_date,
            "card_holder_name":  card_holder_name,
            "name":  name,
            "country":  country,
            "state":  state,
            "city":  city,
            "neighborhood":  neighborhood,
            "street":  street,
            "street_number":  street_number,
            "zipcode":  zipcode,
        }

        bakery = BakeryModel.query.get(bakery_id)

        product_list = [ProductModel.query.get(input_item.product_id) for input_item in items]

        order = OrderModel(bakery_id=bakery_id, bakery=bakery)

        items_list = [OrderDetailsModel(order_id=order.id, product_id=input_item.product_id, quantity=input_item.quantity) for input_item in items]
        
        payment_items = list()

        for product, item in zip(product_list, items_list):
            payment_items.append({
                "id": product.id,
                "title": product.name,
                "unit_price": product.price,
                "quantity": item.quantity,
                "tangible": True
            })

        total_price = sum(item["unit_price"] * item["quantity"] for item in payment_items) * 100 # total_price is in cents
        
        payment_response = create_transaction(bakery.recipient_id, total_price, payment_items, data)

        order.items.extend(items_list)
        order.total_price = total_price
        order.transaction_id = payment_response["id"]
        order.status = payment_response["status"]

        db.session.add(order)
        db.session.commit()

        return OrderMutation(order=order)
Пример #3
0
 def on_new_order(self, transaction_hash: str, token_address: str,
                  exchange_address: str, order_id: int,
                  account_address: str, counterpart_address: str,
                  is_buy: bool, price: int, amount: int, agent_address: str,
                  order_timestamp: datetime):
     order = self.__get_order(exchange_address, order_id)
     if order is None:
         LOG.debug(
             f"NewOrder: exchange_address={exchange_address}, order_id={order_id}"
         )
         order = Order()
         order.transaction_hash = transaction_hash
         order.token_address = token_address
         order.exchange_address = exchange_address
         order.order_id = order_id
         order.unique_order_id = exchange_address + "_" + str(order_id)
         order.account_address = account_address
         order.counterpart_address = counterpart_address
         order.is_buy = is_buy
         order.price = price
         order.amount = amount
         order.agent_address = agent_address
         order.is_cancelled = False
         order.order_timestamp = order_timestamp
         self.db.merge(order)
Пример #4
0
def order_process(id: str):
    """
    represents order processing url
    """

    pieces = request.form.get("pieces")
    address = request.form.get("address")

    try:
        order = Order(pieces, address)
        order.set_object_member(current_user.id)
        order.set_object_product(id)
        order.save()
    except Exception as Error:
        flash("error", Error.__str__())
    else:
        flash("success", "sukses order barang, silahkan edit info pembayaran")

    return redirect(url_for("order.order_unpaid"))
Пример #5
0
def order():
    # 接收参数
    dict = request.form
    house_id = int(dict.get('house_id'))
    start_date = datetime.strptime(dict.get('start_date'), '%Y-%m-%d')
    end_date = datetime.strptime(dict.get('end_date'), '%Y-%m-%d')

    # 验证有效性
    if not all([house_id, start_date, end_date]):
        return jsonify(status_code.PARAMS_ERROR)

    if start_date > end_date:
        return jsonify(status_code.ORDER_START_END_TIME_ERROR)

    # 查询房屋对象
    try:
        house = House.query.get(house_id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
    # 创建订单对象
    order = Order()
    order.user_id = session['user_id']
    order.house_id = house_id
    order.begin_date = start_date
    order.end_date = end_date
    order.days = (end_date - start_date).days + 1
    order.house_price = house.price
    order.amount = order.days * order.house_price

    try:
        order.add_update()
    except:
        return jsonify(status_code.DATABASE_ERROR)

    # 返回信息
    return jsonify(code='200')
Пример #6
0
    def _insert_test_data(self, session):
        self.session = session

        # Order Record
        o = Order()
        o.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 1
        o.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(1)
        o.counterpart_address = ''
        o.price = 70
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)

        o = Order()
        o.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 2
        o.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(2)
        o.counterpart_address = ''
        o.price = 80
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)

        # Agreement Record
        a = Agreement()
        a.order_id = 1
        a.agreement_id = 101
        a.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(1)
        a.buyer_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.seller_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.amount = 3
        a.status = 1
        a.settlement_timestamp = '2019-11-13 16:23:14.183706'
        a.created = '2019-11-13 16:26:14.183706'
        session.add(a)

        a = Agreement()
        a.order_id = 2
        a.agreement_id = 102
        a.exchange_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.unique_order_id = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb' + "_" + str(2)
        a.buyer_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.seller_address = '0x82b1c9374aB625380bd498a3d9dF4033B8A0E3Bb'
        a.amount = 3
        a.status = 1
        a.settlement_timestamp = '2019-11-13 16:24:14.183706'
        a.created = '2019-11-13 16:26:14.183706'
        session.add(a)

        # Order Record (other exchange)
        o = Order()
        o.exchange_address = '0x1234567890123456789012345678901234567890'
        o.token_address = '0xa4CEe3b909751204AA151860ebBE8E7A851c2A1a'
        o.order_id = 1
        o.unique_order_id = '0x1234567890123456789012345678901234567890' + "_" + str(1)
        o.counterpart_address = ''
        o.price = 70
        o.amount = 5
        o.is_buy = True
        o.is_cancelled = False
        session.add(o)