Changeset 17016


Ignore:
Timestamp:
10 Jul 2022, 08:40:43 (2 years ago)
Author:
Henrik Bettermann
Message:

Add BalancePaymentAddFormPage which can only be opened by managers.
No button is provided in base package.

Location:
main/waeup.kofa/trunk
Files:
1 added
6 edited

Legend:

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

    r17009 r17016  
    441.7.2.dev0 (unreleased)
    55=======================
     6
     7* Add `BalancePaymentAddFormPage` which can only be opened by managers.
     8  No button is provided in base package.
    69
    710* Do not require session configuration object for application payments.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r16976 r17016  
    4141    IApplicantOnlinePayment, IApplicantsUtils,
    4242    IApplicantRegisterUpdate, ISpecialApplicant,
    43     IApplicantRefereeReport
     43    IApplicantRefereeReport,
     44    IApplicantBalancePayment
    4445    )
    4546from waeup.kofa.utils.helpers import (html2dict,
     
    831832    def render(self):
    832833        return
     834       
     835class BalancePaymentAddFormPage(KofaAddFormPage):
     836    """ Page to add an online payment which can balance s previous session
     837    payment.
     838    """
     839    grok.context(IApplicant)
     840    grok.name('addbp')
     841    grok.template('balancepaymentaddform')
     842    grok.require('waeup.manageApplication')
     843    form_fields = grok.AutoFields(IApplicantBalancePayment)
     844    label = _('Add balance')
     845    #pnav = 4
     846
     847    @property
     848    def selectable_payment_options(self):
     849        options = getUtility(
     850            IKofaUtils).selectable_payment_options(self.context)
     851        return sorted(options.items(), key=lambda value: value[1])
     852
     853    @action(_('Create ticket'), style='primary')
     854    def createTicket(self, **data):
     855        p_category = data['p_category']
     856        p_option = data.get('p_option', None)
     857        balance_amount = data.get('balance_amount', None)
     858        applicants_utils = getUtility(IApplicantsUtils)
     859        error, payment = applicants_utils.setBalanceDetails(
     860            self.context, p_category, balance_amount)
     861        if error is not None:
     862            self.flash(error, type="danger")
     863            return
     864        if p_option:
     865            payment.p_option = p_option
     866        self.context[payment.p_id] = payment
     867        self.flash(_('Payment ticket created.'))
     868        self.context.writeLogMessage(self,'added: %s' % payment.p_id)
     869        self.redirect(self.url(payment))
     870        return
     871
     872    @action(_('Cancel'), validator=NullValidator)
     873    def cancel(self, **data):
     874        self.redirect(self.url(self.context))
    833875
    834876
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r16976 r17016  
    3030from waeup.kofa.interfaces import (
    3131    IKofaObject, validate_email, validate_html,
    32     SimpleKofaVocabulary)
     32    SimpleKofaVocabulary, ContextualDictSourceFactoryBase)
    3333from waeup.kofa.interfaces import MessageFactory as _
    3434from waeup.kofa.payments.interfaces import IOnlinePayment
     
    4545    curr_year = datetime.now().year
    4646    return range(curr_year - 6, curr_year + 5)
     47
     48class ApplicantBalancePaymentCategorySource(ContextualDictSourceFactoryBase):
     49    """A source that delivers all selectable items of balance payments.
     50    """
     51    #: name of dict to deliver from kofa utils.
     52    DICT_NAME = 'APPLICANT_BALANCE_PAYMENT_CATEGORIES'
    4753
    4854class RegNumInSource(ValidationError):
     
    693699        """Approve payment and process applicant.
    694700        """
     701       
     702class IApplicantBalancePayment(IKofaObject):
     703    """An interface for adding balances.
     704    """
     705
     706    p_category = schema.Choice(
     707        title = _(u'Payment Category'),
     708        default = u'application',
     709        required = True,
     710        source = ApplicantBalancePaymentCategorySource(),
     711        )
     712
     713    balance_amount = schema.Float(
     714        title = _(u'Balance Amount'),
     715        default = None,
     716        required = True,
     717        readonly = False,
     718        description = _(
     719            u'Balance in Naira '),
     720        )
    695721
    696722class IApplicantRefereeReport(IKofaObject):
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r17009 r17016  
    10861086        return
    10871087
     1088    def test_pay_balance(self):
     1089        # Managers can make balance payment
     1090        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1091        self.browser.open(self.manage_path)
     1092        self.fill_correct_values()
     1093        self.browser.getControl("Save").click()
     1094        self.browser.open(self.view_path + '/addbp')
     1095        self.browser.getControl(name="form.p_category").value = ['donation']
     1096        self.browser.getControl(name="form.balance_amount").value = '10000'
     1097        self.browser.getControl("Create ticket").click()
     1098        self.assertTrue('Wrong state' in self.browser.contents)
     1099        IWorkflowState(self.applicant).setState('submitted')
     1100        self.browser.getControl("Create ticket").click()
     1101        self.assertTrue('Payment ticket created.' in self.browser.contents)
     1102        self.browser.getLink("Approve payment").click()
     1103        self.assertTrue('Payment approved' in self.browser.contents)
     1104        return
     1105
    10881106    def prepare_special_container(self):
    10891107        # Add special application container
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py

    r17009 r17016  
    2222from datetime import datetime
    2323import grok
    24 from zope.component import getUtility
     24from zope.component import getUtility, createObject
    2525from zope.catalog.interfaces import ICatalog
    2626from waeup.kofa.interfaces import MessageFactory as _
     
    8989        return
    9090
     91    def setBalanceDetails(self, applicant, category, balance_amount):
     92        """Create a balance payment ticket and set the payment data
     93        as selected by the applicant.
     94        """
     95        if applicant.state not in (PAID, ADMITTED, SUBMITTED, PROCESSED):
     96            return _('Wrong state.'), None
     97        p_item = u'Balance'
     98        amount = balance_amount
     99        if amount in (0.0, None) or amount < 0:
     100            return _('Amount must be greater than 0.'), None
     101        payment = createObject(u'waeup.ApplicantOnlinePayment')
     102        timestamp = ("%d" % int(time()*10000))[1:]
     103        payment.p_id = "p%s" % timestamp
     104        payment.p_category = category
     105        payment.p_item = p_item
     106        if applicant.__parent__.year:
     107            payment.p_session = applicant.__parent__.year
     108        else:
     109            payment.p_session = datetime.now().year
     110        payment.amount_auth = amount
     111        return None, payment
     112
    91113    def getApplicantsStatistics(self, container):
    92114        """Count applicants in applicants containers.
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r16976 r17016  
    194194        'late_registration': 'Late Course Registration Fee',
    195195        'combi': 'Combi Payment',
     196        'donation': 'Donation',
    196197        }
    197198
     
    219220    BALANCE_PAYMENT_CATEGORIES = {
    220221        'schoolfee': 'School Fee',
     222        }
     223
     224    APPLICANT_BALANCE_PAYMENT_CATEGORIES = {
     225        'donation': 'Donation',
    221226        }
    222227
Note: See TracChangeset for help on using the changeset viewer.