def handleNewBookingFromWalhebCalendar(msg):
    bookingInfo = msg.body
    print bookingInfo
    db = getUtility(IDatabase, 'postgres')
    session = db.session
    query = select([Hebergement.heb_pk])
    query.append_whereclause(Hebergement.heb_code_cgt == bookingInfo.get('cgt_id'))
    result = query.execute().fetchone()
    if result is not None:
        hebPk = result.heb_pk
        currentdate = bookingInfo['start_date']
        end = bookingInfo['end_date']
        removeSelection(session, hebPk, currentdate, end)
        updateLastUpdateDate(session, hebPk)
        while currentdate <= end:
            reservation = ReservationProprio()
            if bookingInfo['booking_type'] == 'unavailable':
                reservation.res_type = 'indisp'
            elif bookingInfo['booking_type'] == 'available':
                break
            else:
                reservation.res_type = 'loue'
            reservation.res_date = currentdate
            reservation.heb_fk = hebPk
            reservation.res_date_cre = datetime.now()
            session.add(reservation)
            currentdate += timedelta(days=1)
        session.flush()
        session.commit()
    msg.ack()
 def _fillDB(self):
     super(ExportCalendarActivityTest, self)._fillDB()
     # reservations
     session = self.pg.session()
     res = ReservationProprio()
     res.res_date = date(2001, 1, 1)
     res.res_type = 'loue'
     res.heb_fk = 1
     session.add(res)
     res = ReservationProprio()
     res.res_date = date(2020, 1, 1)
     res.res_type = 'loue'
     res.heb_fk = 1
     session.add(res)
     res = ReservationProprio()
     res.res_date = date(2020, 1, 2)
     res.res_type = 'loue'
     res.heb_fk = 1
     session.add(res)
     res = ReservationProprio()
     res.res_date = date(2015, 1, 1)
     res.res_type = 'loue'
     res.heb_fk = 2
     session.add(res)
     session.flush()
 def decorated(self):
     db = getUtility(IDatabase, name='postgres')
     session = db.session
     heb = Hebergement()
     heb.heb_pk = 1
     session.add(heb)
     session.flush()
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 1)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 5)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 1)
     resPro.res_type = 'indisp'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 4)
     resPro.res_type = 'loue'
     session.add(resPro)
     blck = BlockingHistory()
     blck.heb_pk = 1
     blck.block_start = datetime(2010, 1, 1)
     blck.block_end = datetime(2010, 10, 3)
     session.add(blck)
     blck = BlockingHistory()
     blck.heb_pk = 1
     blck.block_start = datetime(2010, 1, 1)
     blck.block_end = datetime(2010, 2, 3)
     session.add(blck)
     session.flush()
     session.commit()
     try:
         func(self)
     finally:
         db.refresh()