Beispiel #1
0
def add_shippment():
    result_ship = Shippment.query.with_for_update().filter_by(ship_ID=request.json['ship_ID']).first()
    if result_ship is None: 
        new_shippment = Shippment(
            request.json['ship_ID'],
            request.json['order_ID'],  
            request.json['contact_info'],
            request.json['ship_orderStore'],
            request.json['ship_datetime'],
            request.json['ship_area'],
            request.json['ship_district'],
            request.json['driver'],
            request.json['car_type'],
            request.json['car_ID'],
            request.json['is_elevator'],
            request.json['floors_byhand'],
            request.json['paytype'],
            request.json['amount_collect'],
            request.json['ship_comment'],
            request.json['shipUnits']            
            )
        try:
            db.session.add(new_shippment)
            db.session.commit()
        except:
            db.session.rollback()
            raise
        finally:
            db.session.close()
            return '{}'.format(new_shippment)
    else:
        return 'this shippment is already exist'
Beispiel #2
0
def add_shippment():
    new_shippment = Shippment(
        request.json['ship_ID'], request.json['contact_info'],
        request.json['ship_area'], request.json['ship_district'],
        request.json['driver'], request.json['car_type'],
        request.json['car_ID'], request.json['is_elevator'],
        request.json['floors_byhand'], request.json['amount_collect'],
        request.json['comment'])

    db.session.add(new_shippment)
    db.session.commit()

    return '{}'.format(new_shippment)
Beispiel #3
0
def add_shippment():
    ship_ID = request.json['ship_ID']
    contact_info = request.json['contact_info']
    ship_area = request.json['ship_area']
    ship_district = request.json['ship_district']
    driver = request.json['driver']
    car_type = request.json['car_type']
    car_ID = request.json['car_ID']
    is_elevator = request.json['is_elevator']
    floors_byhand = request.json['floors_byhand']
    amount_collect = request.json['amount_collect']
    comment = request.json['comment']

    print(ship_ID, contact_info, ship_area, ship_district, driver, car_type, car_ID, is_elevator, floors_byhand, amount_collect, comment)
    new_shippment = Shippment(ship_ID, contact_info, ship_area, ship_district, driver, car_type, car_ID, is_elevator, floors_byhand, amount_collect, comment)

    db.session.add(new_shippment)
    db.session.commit()

    # return jsonify(new_delivery)
    return '{}'.format(new_shippment)
Beispiel #4
0
def add_order_new(rawdata):
    arrShippment = []
    if len(checkKey(rawdata, 'order_ID')) > 0:
        order_ID = checkKey(rawdata, 'order_ID')
    else:
        return 'Error: unfound key "order_ID"'
    clientname = checkKey(rawdata, 'clientname')
    business_type = checkKey(rawdata, 'business_type')
    delivery_date = checkKey(rawdata, 'delivery_date')
    delivery_fee = checkKey(rawdata, 'delivery_fee')
    car_type = checkKey(rawdata, 'car_type')
    car_ID = checkKey(rawdata, 'car_ID')
    good_size = checkKey(rawdata, 'good_size')
    comment = checkKey(rawdata, 'comment')
    ships = checkKey(rawdata, 'ships')
    # 建立Shippments
    for ship in ships:
        if len(checkKey(ship, 'ship_ID')) > 0:
            ship_ID = checkKey(ship, 'ship_ID')
        else:
            return 'Error: unfound key "ship_ID"'
        contact_info = checkKey(ship, 'contact_info')
        ship_orderStore = checkKey(ship, 'ship_orderStore')
        ship_datetime = checkKey(ship, 'ship_datetime')
        ship_area = checkKey(ship, 'ship_area')
        ship_district = checkKey(ship, 'ship_district')
        driver = checkKey(ship, 'ship_driver')
        is_elevator = checkKey(ship, 'is_elevator')
        floors_byhand = checkKey(ship, 'floors_byhand')
        amount_collect = checkKey(ship, 'amount_collect')
        ship_comment = checkKey(ship, 'comment')
        result_ship = Shippment.query.with_for_update().filter_by(
            ship_ID=ship_ID, driver=driver).first()
        # 取消檢查ship_ID是否重複,但是以下廠商在傳入時,須確保ship_ID是唯一的:
        #   1.郭元益
        if result_ship is None:
            arrShippment.append(
                Shippment(ship_ID, order_ID, contact_info, ship_orderStore,
                          ship_datetime, ship_area, ship_district, driver,
                          car_type, car_ID, is_elevator, floors_byhand,
                          amount_collect, ship_comment))

    # 查詢此Order是否已存在
    result_delivery = Delivery.query.with_for_update().filter_by(
        order_ID=order_ID).first()
    # 資料庫沒有此Order => 新增Order
    if result_delivery is None:
        new_delivery = Delivery(business_type, order_ID, clientname,
                                delivery_date, delivery_fee, good_size,
                                comment)
        try:
            db.session.add(new_delivery)
            db.session.commit()
        except:
            db.session.rollback()
            raise
        # 如果Ships超過一筆,逐筆加入
        if len(arrShippment) > 0:
            for oneShip in arrShippment:
                try:
                    db.session.add(oneShip)
                    db.session.commit()
                except:
                    db.session.rollback()
                    raise
        else:
            return 'Error: no shippment or shippment duplicated'
        return '新增成功'
    else:
        return 'Notice: This order already exists'
Beispiel #5
0
def add_order(rawdata):
    arrShippment = []
    if len(checkKey(rawdata,'order_ID')) > 0:
        order_ID = checkKey(rawdata,'order_ID')         #訂單編號
    else:
        return 'Error: unfound key "order_ID"'
    clientname = checkKey(rawdata,'clientname')         #客戶名稱
    business_type = checkKey(rawdata,'business_type')   #表單類型
    delivery_date = checkKey(rawdata,'delivery_date')   #配送日期
    delivery_fee = checkKey(rawdata,'delivery_fee')     #總運費
    delivery_fee_before_discount = checkKey(rawdata,'delivery_fee_before_discount')
    car_type = checkKey(rawdata,'car_type')             #車型
    car_ID = checkKey(rawdata,'car_ID')                 #車號
    good_size = checkKey(rawdata,'good_size')           #總材積數
    ship_units = checkKey(rawdata,'ship_units')         #配送件數
    comment = checkKey(rawdata,'comment')               #訂單備註
    ships = checkKey(rawdata,'ships')                   #訂單的配送紀錄
    updateduser = checkKey(rawdata, 'updateduser')      #使用者ID
    # 建立Shippments
    for ship in ships:
        if len(checkKey(ship,'ship_ID')) > 0 :
            ship_ID = checkKey(ship,'ship_ID')          #配送單編號
        else:
            return 'Error: unfound key "ship_ID"'
        contact_info = checkKey(ship,'contact_info')    #客戶姓名/地址/電話
        ship_orderStore = checkKey(ship,'ship_orderStore') #(郭元益)發單店面
        ship_datetime = checkKey(ship,'ship_datetime')  #配送時間
        ship_area = checkKey(ship,'ship_area')          #配送縣市
        ship_district = checkKey(ship,'ship_district')  #配送區域
        driver = checkKey(ship,'ship_driver')           #司機
        is_elevator = checkKey(ship,'is_elevator')      #(郭元益)是否電梯
        floors_byhand = checkKey(ship, 'floors_byhand') #(郭元益)手搬樓層數
        paytype = checkKey(ship, 'paytype')             #(郭元益)付款方式_現金/支票
        amount_collect = checkKey(ship,'amount_collect')#(郭元益)代收款 (旺家)手開單費用
        ship_comment = checkKey(ship,'comment')         #配送單備註
        shipUnits = checkKey(ship, 'shipUnits')         #(旺家)手開單數量
        result_ship = Shippment.query.with_for_update().filter_by(order_ID=order_ID,ship_ID=ship_ID, driver=driver).first()
            # 取消檢查ship_ID是否重複,但是以下廠商在傳入時,須確保ship_ID是唯一的:
            #   1.郭元益
        if result_ship is None: 
            arrShippment.append(Shippment(ship_ID,order_ID,contact_info,ship_orderStore,ship_datetime,ship_area,ship_district,driver,car_type,car_ID,is_elevator,floors_byhand,paytype,amount_collect,ship_comment,shipUnits))
        
    # 查詢此Order是否已存在
    result_delivery = Delivery.query.with_for_update().filter_by(order_ID=order_ID).first()
    # 資料庫沒有此Order => 新增Order
    if result_delivery is None:
        new_delivery = Delivery(business_type, order_ID, clientname, delivery_date,
                                delivery_fee, delivery_fee_before_discount, good_size, ship_units, comment, updateduser)
        try:
            db.session.add(new_delivery)
            db.session.commit()
        except:
            db.session.rollback()
            raise
        # 如果Ships超過一筆,逐筆加入
        if len(arrShippment) > 0:
            for oneShip in arrShippment:
                try:
                    db.session.add(oneShip)
                    db.session.commit()
                except:
                    db.session.rollback()
                    raise

                #add log
                new_log = OperateLog(business_type, "ADD", order_ID, oneShip.ship_ID, updateduser)
                try:
                    db.session.add(new_log)
                    db.session.commit()
                except:
                    db.session.rollback()
                    raise
        else:
            return 'Error: no shippment or shippment duplicated'

        return '新增成功'
    else: 
        return '訂單已經存在'