def delete_booking_by_id(booking_id): b = Booking.get_by_id(booking_id) if b: db.delete(b.documents) db.delete(b.sectors) db.delete(b.passengers_rel) db.delete_async(db.Key.from_path('LastUse', str(b.key()))) b.delete()
def get_bookings_by_booking_ref(booking_ref, company=None, active_only=False): q = Booking.all() q.filter('booking_ref = ', booking_ref) if company: q.filter('company = ', company) if active_only: q.filter("last_date >= ", _current_date() - _active_period) return [b.to_dict() for b in q]
def add_sector(booking_id, date, from_loc, to_loc, service): res = None b = Booking.get_by_id(booking_id) if b: res = Sector(date=date, from_loc=from_loc, to_loc=to_loc, service=service, booking=b) res.put() if date > b.last_date: b.last_date = date b.put() _use(b.key()) return res.to_dict()
def get_bookings(active_only=True, states=['UNPAID', 'PAID', 'CREDIT']): res = {} now = _current_date() if not active_only and isinstance(states, list): states.append('CANCELLED') elif not isinstance(states, list): states = [states] for cat in states: q = Booking.all() q.filter("state = ", cat) if active_only: q.filter("last_date >= ", now - _active_period) res[cat] = [b.to_dict() for b in q] return res
def update_booking(booking_id, **kwds): b = Booking.get_by_id(booking_id) if b and len(kwds) > 0: if 'booking_ref' in kwds: b.booking_ref = kwds['booking_ref'] if 'company' in kwds: b.company = kwds['company'] if 'course' in kwds: b.course = kwds['course'] if 'fare' in kwds: b.fare = kwds['fare'] if 'paid_by' in kwds: b.paid_by = kwds['paid_by'] if b.paid_by > b.last_date: b.last_date = b.paid_by if 'state' in kwds: b.state = kwds['state'] if 'amound_in_credit' in kwds: b.amount_in_credit = kwds['amount_in_credit'] if 'credit_expiry' in kwds: b.credit_expiry = kwds['credit_expiry'] if b.credit_expiry > b.last_date: b.last_date = b.credit_expiry b.put() _use(b.key()) return b.to_dict()
def get_booking_by_id(booking_id): b = Booking.get_by_id(booking_id) if b: _use(b.key()) return b.to_dict() return None
def add_booking(company, booking_ref, course, **kwds): res = Booking(company=company, booking_ref=booking_ref, course=course) if 'fare' in kwds: res.fare = kwds['fare'] if 'paid_by' in kwds: res.paid_by = kwds['paid_by'] if res.last_date < kwds['paid_by']: res.last_date = kwds['paid_by'] if 'state' in kwds: res.state = kwds['state'] if 'amount_in_credit' in kwds: res.amount_in_credit = kwds['amount_in_credit'] if 'credit_expiry' in kwds: res.credit_expiry = kwds['credit_expiry'] if res.last_date < kwds['credit_expiry']: res.last_date = kwds['credit_expiry'] c = Company(key_name=company, company=company) db.put_async(c) res.put() _use(res.key()) return res.to_dict()
def get_current_courses(): now = _current_date() q = Booking.all() q.filter("last_date >= ", now - _active_period) return set([b.course for b in q])