Esempio n. 1
0
def add_order(request):
    new_order = request.validated['order']
    new_order['product'] = DBRef('product', ObjectId(new_order['product']))
    new_order['orderMaster'] = DBRef('order_master', ObjectId(new_order['orderMaster']))
    db = request.db
    db['order'].insert(new_order)
    new_order['product'] = str(new_order['product'].id)
    new_order['orderMaster'] = str(new_order['orderMaster'].id)
    new_order['id'] = str(new_order['_id'])
    del new_order['_id']
    new_order['serverPrice'] = convert_price(new_order['serverPrice'])
    new_order['serverTotalPrice'] = convert_price(new_order['serverTotalPrice'])
    return {'order': new_order}
Esempio n. 2
0
def generate_product_item(db, _product):
    _product['productMaster'] = str(_product['productMaster'].id)

    _product['id'] = str(_product['_id'])
    del _product['_id']

    _product = convert_datetime(_product)
    _product['price'] = convert_price(_product['price'])

    return _product
Esempio n. 3
0
def add_product(request):
    new_product = request.validated['product']
    db = request.db
    new_product['productMaster'] = DBRef('product_master', ObjectId(new_product['productMaster']))
    new_product['pubDate'] = new_product['modifiedDate'] = datetime.now()
    db['product'].insert(new_product)
    new_product['productMaster'] = str(new_product['productMaster'].id)
    new_product['id'] = str(new_product['_id'])
    del new_product['_id']
    new_product = convert_datetime(new_product)
    new_product['price'] = convert_price(new_product['price'])
    return {'product': new_product}
Esempio n. 4
0
def update_product(request):
    product_id = ObjectId(request.matchdict['product_id'])
    new_product = request.validated['product']
    new_product['productMaster'] = DBRef('product_master', ObjectId(new_product['productMaster']))
    db = request.db
    new_product['modifiedDate'] = datetime.now()
    result = db['product'].find_and_modify(query={"_id": product_id}, update={'$set': new_product}, new=True)
    result['productMaster'] = str(result['productMaster'].id)
    result['id'] = str(result['_id'])
    del result['_id']
    result = convert_datetime(result)
    result['price'] = convert_price(result['price'])
    return {'product': result}