Changeset 17412


Ignore:
Timestamp:
17 May 2023, 18:21:10 (4 years ago)
Author:
Henrik Bettermann
Message:

Add ReleaseExpiredAllocationsPage2 which allows to release unpaid beds in single hostels.

Location:
main/waeup.kofa/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r17411 r17412  
    441.8.2.dev0 (unreleased)
    55=======================
     6
     7* Add `ReleaseExpiredAllocationsPage2` which allows to release unpaid beds
     8  in single hostels.
    69
    710* Show matric number on `TranscriptOfficerLandingPage`.
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser.py

    r17313 r17412  
    135135    @property
    136136    def target_url(self):
    137         if self.target and self.context.allocation_expiration:
     137        if self.target and grok.getSite()['hostels'].allocation_expiration:
    138138            return self.view.url(self.view.context, self.target)
    139139        return
    … …  
    146146              "booking if maintenance fee is not " + \
    147147              "paid.'")
    148         msg = _(msg, mapping={'a': self.context.allocation_expiration,})
     148        msg = _(msg, mapping={'a': grok.getSite()['hostels'].allocation_expiration,})
    149149        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    150150        return "return window.confirm(%s);" % translate(
    … …  
    218218
    219219    def update(self):
    220         n = self.context.allocation_expiration
     220        n = grok.getSite()['hostels'].allocation_expiration
    221221        if not n:
    222222            self.flash(
    … …  
    250250        return
    251251
     252class ReleaseExpiredAllocationsPage2(ReleaseExpiredAllocationsPage):
     253    """Release all expired allocated beds in a single hostel.
     254    """
     255    grok.context(IHostel)
     256    grok.name('releaseexpired2')
     257
    252258class HostelsStatisticsPage(KofaDisplayFormPage):
    253259    """Some statistics about beds in hostels.
    … …  
    300306    def label(self):
    301307        return self.context.hostel_name
     308
     309class ReleaseExpiredAllocationsActionButton2(ReleaseExpiredAllocationsActionButton):
     310    grok.order(2)
     311    grok.context(IHostel)
     312    grok.view(HostelDisplayFormPage)
     313    target = 'releaseexpired2'
     314    text = _('Release expired bed space allocations in this hostel')
    302315
    303316class HostelManageActionButton(ManageActionButton):
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py

    r17313 r17412  
    2121import grok
    2222from zope.event import notify
    23 from zope.component import getUtility, createObject
     23from zope.component import queryUtility, getUtility, createObject
    2424from zope.component.interfaces import IFactory, ComponentLookupError
    2525from zope.catalog.interfaces import ICatalog
    … …  
    138138        return removed_counter, added_counter, modified_counter, modified_beds
    139139
     140    def releaseExpiredAllocations(self, n=7):
     141        """Release bed in hostel if bed allocation has expired. Allocation expires
     142        after `n` days if maintenance fee has not been paid.
     143        """
     144        cat = queryUtility(ICatalog, name='beds_catalog')
     145        results = cat.searchResults(bed_type=(None,None))
     146        released = []
     147        for bed in results:
     148            if not bed.bed_id.startswith(self.hostel_id):
     149                continue
     150            student_id = bed.releaseBedIfMaintenanceNotPaid(n=n)
     151            if student_id:
     152                released.append('%s (%s)' % (bed.bed_id,student_id))
     153        return released
     154
    140155    def writeLogMessage(self, view, message):
    141156        ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r17313 r17412  
    164164        # Create a bed
    165165        bed = Bed()
    166         bed.bed_id = u'hall_block_room_bed'
     166        bed.bed_id = u'hall-x_block_room_bed'
    167167        bed.bed_number = 1
    168168        bed.bed_type = u'regular_male_fr'
    … …  
    191191    layer = FunctionalLayer
    192192
    193     def test_release_expired_allocations(self):
     193    def test_release_expired_allocations_portalwide(self):
    194194        self.app['hostels'].allocation_expiration = 7
    195195        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    … …  
    200200        self.student['accommodation'].addBedTicket(bedticket)
    201201        self.app[
    202             'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id
     202            'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id
    203203        notify(grok.ObjectModifiedEvent(
    204             self.app['hostels']['hall-x']['hall_block_room_bed']))
    205         self.assertEqual(
    206             self.app['hostels']['hall-x']['hall_block_room_bed'].bed_type,
     204            self.app['hostels']['hall-x']['hall-x_block_room_bed']))
     205        self.assertEqual(
     206            self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type,
    207207            'regular_male_fr')
    208208        results = cat.searchResults(owner=(self.student_id, self.student_id))
    … …  
    218218        self.browser.open(self.container_path + '/releaseexpired')
    219219        self.assertTrue(
    220             'Successfully released beds: hall_block_room_bed (K1000000)'
     220            'Successfully released beds: hall-x_block_room_bed (K1000000)'
    221221            in self.browser.contents)
    222222        results = cat.searchResults(owner=(self.student_id, self.student_id))
    … …  
    226226        # The owner has been removed and the bed reserved.
    227227        self.assertEqual(
    228             self.app['hostels']['hall-x']['hall_block_room_bed'].owner,
     228            self.app['hostels']['hall-x']['hall-x_block_room_bed'].owner,
    229229            NOT_OCCUPIED)
    230230        self.assertEqual(
    231             self.app['hostels']['hall-x']['hall_block_room_bed'].bed_type,
     231            self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type,
    232232            'regular_male_reserved')
    233233        # Accommodation session can't be changed if hostels are not empty.
    … …  
    242242        self.assertTrue(
    243243            'hostels.browser.ReleaseExpiredAllocationsPage - hostels - '
    244             'released: hall_block_room_bed (K1000000)'
     244            'released: hall-x_block_room_bed (K1000000)'
     245            in logcontent)
     246        return
     247
     248    def test_release_expired_allocations_in_hostel(self):
     249        self.app['hostels'].allocation_expiration = 7
     250        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     251        cat = queryUtility(ICatalog, name='beds_catalog')
     252        bedticket = BedTicket()
     253        bedticket.booking_session = 2004
     254        bedticket.bed_coordinates = u'anything'
     255        delta = timedelta(days=10)
     256        bedticket.booking_date = datetime.utcnow() - delta
     257        self.student['accommodation'].addBedTicket(bedticket)
     258        self.app[
     259            'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id
     260        notify(grok.ObjectModifiedEvent(
     261            self.app['hostels']['hall-x']['hall-x_block_room_bed']))
     262        self.assertEqual(
     263            self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type,
     264            'regular_male_fr')
     265        results = cat.searchResults(owner=(self.student_id, self.student_id))
     266        self.assertEqual(len(results), 1)
     267        grok.getSite()['configuration'].maintmode_enabled_by = u'any_id'
     268        self.browser.open(self.container_path + '/hall-x/releaseexpired2')
     269        self.assertTrue(
     270            'Successfully released beds: hall-x_block_room_bed (K1000000)'
     271            in self.browser.contents)
     272        results = cat.searchResults(owner=(self.student_id, self.student_id))
     273        self.assertEqual(len(results), 0)
     274        self.assertMatches(bedticket.display_coordinates,
     275            '-- booking expired (2015-10-14 08:35:38 UTC) --')
     276        # The owner has been removed and the bed reserved.
     277        self.assertEqual(
     278            self.app['hostels']['hall-x']['hall-x_block_room_bed'].owner,
     279            NOT_OCCUPIED)
     280        self.assertEqual(
     281            self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type,
     282            'regular_male_reserved')
     283        # Releasing is logged.
     284        logcontent = open(self.logfile).read()
     285        self.assertTrue(
     286            'hostels.browser.ReleaseExpiredAllocationsPage2 - hall-x - '
     287            'released: hall-x_block_room_bed (K1000000)'
    245288            in logcontent)
    246289        return
    … …  
    249292        utils = getUtility(IHostelsUtils)
    250293        self.app['hostels']['hall-x'][
    251             'hall_block_room_bed'].owner = NOT_OCCUPIED
     294            'hall-x_block_room_bed'].owner = NOT_OCCUPIED
    252295        notify(grok.ObjectModifiedEvent(
    253             self.app['hostels']['hall-x']['hall_block_room_bed']))
     296            self.app['hostels']['hall-x']['hall-x_block_room_bed']))
    254297        stats = utils.getBedStatistics()
    255298        self.assertEqual(stats,
    … …  
    266309             )
    267310        self.app[
    268             'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id
     311            'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id
    269312        notify(grok.ObjectModifiedEvent(
    270             self.app['hostels']['hall-x']['hall_block_room_bed']))
     313            self.app['hostels']['hall-x']['hall-x_block_room_bed']))
    271314        stats = utils.getBedStatistics()
    272315        self.assertEqual(stats,
    … …  
    299342        results = [x for x in results] # Turn results generator into list
    300343        assert len(results) == 1
    301         assert results[0] is self.app['hostels']['hall-x']['hall_block_room_bed']
     344        assert results[0] is self.app['hostels']['hall-x']['hall-x_block_room_bed']
    302345
    303346    def test_search_by_owner(self):
    304347        # We can find a certain bed
    305         myobj = self.app['hostels']['hall-x']['hall_block_room_bed']
     348        myobj = self.app['hostels']['hall-x']['hall-x_block_room_bed']
    306349        myobj.owner = u'abc'
    307350        notify(grok.ObjectModifiedEvent(myobj))
    … …  
    310353        results = [x for x in results] # Turn results generator into list
    311354        assert len(results) == 1
    312         assert results[0] is self.app['hostels']['hall-x']['hall_block_room_bed']
     355        assert results[0] is self.app['hostels']['hall-x']['hall-x_block_room_bed']
    313356
    314357class HostelsUITests(HostelsFullSetup):
    … …  
    622665            result,
    623666            'bed_id,bed_number,bed_type,owner,hall,block,room,bed,'
    624             'special_handling,sex,bt\r\nhall_block_room_bed,1,regular_male_fr,,'
    625             'hall,block,room,bed,regular,male,fr\r\n'
     667            'special_handling,sex,bt\r\nhall-x_block_room_bed,1,regular_male_fr,,'
     668            'hall-x,block,room,bed,regular,male,fr\r\n'
    626669            )
    627670        return
Note: See TracChangeset for help on using the changeset viewer.