コード例 #1
0
ファイル: order_api.py プロジェクト: sungitly/isr
def create_order():
    data = request.json
    if data is None:
        abort(400, description=gettext('invalid json request'))

    validate_amounts_fields_in_orders(data)
    order = Order(**data)

    order.generate_order_no()

    order.save_and_flush()

    customer = Customer.find(order.customer_id)
    customer.status = 'ordered'

    Appointment.cancel_all_for_sales_customer(
        order.sales_id, order.customer_id,
        'Order: ' + str(order.id) + ' is created')

    Reception.complete_all_for_sales_customer(
        order.sales_id, order.customer_id,
        'Order: ' + str(order.id) + ' is created')

    return Order.find(order.id), 201, add_location_header(
        dict(), url_for('api.get_order', uid=order.id))
コード例 #2
0
ファイル: order_api.py プロジェクト: sungitly/isr
def get_order(uid):
    result = Order.find(uid)

    if result is None:
        return abort(404,
                     description=gettext(u'Order with id %(id)s is not found',
                                         id=uid))
    return result
コード例 #3
0
ファイル: order_api.py プロジェクト: sungitly/isr
def confirm_order(oid):
    order = Order.find(oid)

    if order is None:
        return abort(404,
                     description=gettext(u'Order with id %(id)s is not found',
                                         id=oid))

    order.is_confirmed = True
    return order
コード例 #4
0
ファイル: order_api.py プロジェクト: sungitly/isr
def update_order(oid):
    result = Order.find(oid)
    if result is None:
        return abort(404,
                     description=gettext(u'Order with id %(id)s is not found',
                                         id=id))

    if result.status in ('delivered', 'cancelled'):
        return abort(
            400,
            description=gettext(u'Cannot update delivered or cancelled order'))

    data = request.json
    new_status = data.get('status', 'new')

    result.status = new_status

    if result.status.lower() == 'cancelled':
        result.customer.reset_status()
    else:
        # FIXME use flask inputs to do validation
        validate_amounts_fields_in_orders(data)

        # update order data
        for key in Order.attributes_names(Order.excludes_attrs()):
            if data.get(key, None):
                setattr(result, key, data.get(key))

    # FIXME: disable delivered followup temporarily
    # if result.status.lower() == 'delivered':
    #     today = datetime.date.today()
    #     delivered_date = parse_date(result.delivered_date)
    #     if delivered_date >= today:
    #         # make two appointments
    #         Appointment.auto_make_delivered_followup_appointments(result)

    return result