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()