Ejemplo n.º 1
0
    def __call__(self):
        session = DBSession()
        transaction = Transaction()
        params = self.request.params
        year = int(params['year'])
        month = int(params['month'])

        if params['ttype_id'] == '--':
            return self.redir_to_list(year, month, msg='Please select a type.')
        ttype = session.query(TransactionType).get(params['ttype_id'])
        transaction.ttype = ttype
        transaction.amount = float(params['amount'])
        if ttype.mem_sup == 'memb' and 'mem_id' in params:
            transaction.member = session.query(Member).get(params['mem_id'])
        if ttype.mem_sup == 'whol' and 'wh_id' in params:
            transaction.wholesaler = session.query(Wholesaler).get(
                params['wh_id'])
        if ttype.mem_sup == 'vers' and 'vers_id' in params:
            transaction.vers_supplier = session.query(VersSupplier).get(
                params['vers_id'])
        transaction.comment = params['comment']
        if 'ord_no' in params and not params['ord_no'] in ('', '--'):
            transaction.ord_no = int(params['ord_no'])
        if 'late' in params:
            transaction.late = bool(params['late'])

        day = int(params['day'])
        adate = datetime.date(year, month, day)
        transaction.date = adate
        transaction.validate()
        session.add(transaction)
        session.flush()
        return self.redir_to_list(year, month, msg='Transaction "{}" has been '\
                        'added to the list.'.format(str(transaction)))
Ejemplo n.º 2
0
 def __call__(self):
     session = DBSession()
     a_id = self.request.matchdict['a_id']
     applicant = get_applicant(session, a_id)
     session.delete(applicant)
     session.flush()
     return dict(applicants=get_applicants(session),
                 msg="Applicant has been removed from list.")
Ejemplo n.º 3
0
 def __call__(self):
     session = DBSession()
     t_id = self.request.matchdict['t_id']
     t = get_transaction(session, t_id)
     if t.locked():
         return self.redir_to_list(t.year, t.month,
                         msg='Cannot remove transaction "{}":'\
                              ' It is locked.'.format(t), show_list=True)
     else:
         session.delete(t)
         session.flush()
         return self.redir_to_list(t.date.year, t.date.month,
                          msg='Transaction "{}" has been deleted.'\
                              .format(t), show_list=True)
Ejemplo n.º 4
0
 def __call__(self):
     session = DBSession()
     tt_id = self.request.matchdict['tt_id']
     tt = get_transaction_type(session, tt_id)
     if not tt.locked:
         session.delete(tt)
         session.flush()
         return self.redirect('/transaction-types?msg='\
                              'Transaction type "{}" has been deleted.'\
                               .format(tt.name))
     else:
         return self.redirect('/transaction-types?msg=Cannot remove'\
                              ' transaction type "{}": transactions'\
                              ' refer to it.'.format(tt.name))
Ejemplo n.º 5
0
 def __call__(self):
     name = self.request.params['name']
     pos_neg = self.request.params['pos_neg']
     mem_sup = self.request.params['mem_sup']
     tt = TransactionType(None, name=name, pos_neg=pos_neg, mem_sup=mem_sup)
     tt.validate()
     session = DBSession()
     existing = session.query(TransactionType)\
                       .filter(TransactionType.name == tt.name).all()
     if len(existing) > 0: 
         return self.redirect('/transaction-types?msg=Transaction type '\
                              ' with name "{}" already exists'\
                              .format(tt.name))
     session.add(tt)
     session.flush()
     return self.redirect('/transaction-types?msg=Transaction type "{}"'\
                          ' has been added to the list.'.format(tt.name))
Ejemplo n.º 6
0
 def __call__(self):
     session = DBSession()
     member = get_member(session, self.request)
     self.user_may_edit_admin_settings = (
         self.user.mem_admin and not self.user.mem_id == member.mem_id)
     if 'action' in self.request.params:
         action = self.request.params['action']
         if action == "save":
             member = fill_member_from_request(
                 member, self.request, self.user_may_edit_admin_settings)
             member.validate()
             if not member.exists:
                 session.add(member)
                 session.flush()  # flush manually so the member gets an ID
                 send_pwdreset_request(member,
                                       self.request.application_url,
                                       first=True)
                 return self.redirect('/member/{0:d}?msg=Member has been'\
                                      ' created and got an email to set up'\
                                      ' a password. Note: no membership'\
                                      ' fee has been charged (we do not'\
                                      ' know the household size).'\
                                      .format(member.mem_id))
             return dict(m=member, msg='Member has been saved.')
         elif action == 'toggle-active':
             member = get_member(session, self.request)
             self.confirm_toggle_active = True
             return dict(m=member)
         elif action == 'toggle-active-confirmed':
             member.mem_active = not member.mem_active
             msg='Member {} is now {}active.'.\
                 format(member, {False:'in', True:''}[member.mem_active])
             if not member.mem_active and not running_sqlite():
                 query = "select remove_inactive_member_order({});"\
                         .format(member.mem_id)
                 try:
                     session.connection().engine.execute(query)
                 except:
                     msg += ' Warning: Their current order could not be removed,'\
                            ' (e.g. because it has already been sent to suppliers)'\
                            ' so the member will probably still need to pay.'
             return dict(m=member, msg=msg)
     return dict(m=member, msg='')
Ejemplo n.º 7
0
 def __call__(self):
     session = DBSession()
     a_id = self.request.matchdict['a_id']
     applicant = get_applicant(session, a_id)
     # copy over our knowledge of him/her
     member = Member(self.request, applicant.fname, '', applicant.lname)
     now = datetime.now()
     txt = "Joined orientation in {}, became member in {}/{}.".format(\
             applicant.month, now.month, now.year)
     member.mem_adm_comment = "{}\n{}".format(txt, applicant.comment)
     member.mem_email = applicant.email
     member.mem_home_tel = applicant.telnr
     member.mem_household_size = applicant.household_size
     member.validate()
     session.add(member)
     session.delete(applicant)
     session.flush()
     send_pwdreset_request(member, self.request.application_url, first=True)
     return self.redirect("/member/{}?msg=Applicant has been made "\
                         "into a new Member and got an email to set up a "\
                         "password."\
                         .format(member.mem_id))
Ejemplo n.º 8
0
 def __call__(self):
     fname = self.request.params['fname']
     lname = self.request.params['lname']
     now = datetime.now()
     month = "{}/{}".format(
         str(now.month).rjust(2, '0'),
         str(now.year)[-2:])
     comment = self.request.params['comment']
     email = self.request.params['email']
     telnr = self.request.params['telnr']
     if not self.request.params['household_size'].isdigit():
         raise VokoValidationError(
             "Please enter valid household size (number > 1), not: '%s'" %
             self.request.params['household_size'])
     hsize = int(self.request.params['household_size'])
     applicant = Applicant(None, fname, lname, month, comment, email, telnr,
                           hsize)
     applicant.validate()
     session = DBSession()
     session.add(applicant)
     session.flush()
     return dict(applicants=get_applicants(session),
                 msg="Applicant has been added to the list.")
Ejemplo n.º 9
0
    def __call__(self):
        session = DBSession()
        wg = get_wg(session, self.request)
        req = self.request

        self.possible_members = get_possible_members(session, wg)
        if 'action' in req.params:
            action = req.params['action']
            if action == "save":
                old_name = wg.name
                uwgs = [w.name for w in self.user.workgroups]
                wg = fill_wg_from_request(wg, req, session)
                if wg.exists and not wg.name == old_name\
                   and not 'Systems' in uwgs:
                    raise Exception('Only members of Systems can change the'\
                                    ' name of an existing workgroup, because'\
                                    ' it changes the email addresses of the'\
                                    ' group.')
                wg.validate()
                if not wg.exists:
                    session.add(wg)
                    session.flush()  # flushing manually so the wg gets an ID
                    return self.redirect('/workgroup/%d?msg='\
                                         'Workgroup was created.' % wg.id)
                return dict(wg=wg, msg='Workgrup has been saved.')

            elif action == 'toggle-active':
                wg = get_wg(session, self.request)
                self.confirm_toggle_active = True
                return dict(wg=wg)
            elif action == 'toggle-active-confirmed':
                wg.active = not wg.active
                msg='Workgroup {} is now {}active.'.\
                    format(wg.name, {False:'in', True:''}[wg.active])
                return dict(wg=wg, msg=msg)

        return dict(wg=wg, msg='')
Ejemplo n.º 10
0
    def __call__(self):
        session = DBSession()
        transaction = get_transaction(session, self.request.matchdict['t_id'])
        msg = ''
        if not transaction:
            raise Exception("No transaction with id %d"\
                            % self.request.matchdict['t_id'])

        action = self.request.matchdict['action']
        if action == "":
            raise Exception('No action given.')

        if action == "setttype":
            transaction.ttype = session.query(TransactionType)\
                                       .get(self.request.params['ttype_id'])
            msg = 'Transaction Type was updated.'
        if action == "setmember":
            if not 'mem_id' in self.request.params:
                msg = 'No member was selected.'
            else:
                transaction.member = get_member(session, self.request)
                msg = u'Transaction got a new member:{}'\
                        .format(transaction.member)
        if action == "setwholesaler":
            if not 'wh_id' in self.request.params:
                msg = 'No wholesaler was selected.'
            else:
                transaction.whol_id = self.request.params['wh_id']
                msg = u'Transaction got a new wholesaler.'
        if action == "setverssupplier":
            if not 'vers_id' in self.request.params:
                msg = 'No vers supplier was selected.'
            else:
                transaction.vers_id = self.request.params['vers_id']
                msg = u'Transaction got a new vers supplier.'
        if action == "setamount":
            amount = self.request.params['amount']
            try:
                amount = float(amount)
                msg = 'Amount was updated.'
            except:
                msg = 'Invalid amount: {}'.format(amount)
            transaction.amount = amount
        if action == "setcomment":
            transaction.comment = self.request.params['comment']
            msg = "Comment was updated."
        if action == "setdate":
            adate = datetime.datetime.now()
            adate.day = self.request.params['day']
            adate.month = self.request.params['month']
            adate.year = self.request.params['year']
            transaction.date = adate
            msg = "Date was updated."
        if action == "setlate":
            if 'late' in self.request.params:
                transaction.late = bool(self.request.params['late'])
            else:
                transaction.late = False
            msg = "Late-status of transaction was set to {}."\
                   .format(transaction.late)
        if action == 'setorder':
            transaction.ord_no = int(self.request.params['ord_no'])
            msg = "order was set."
        transaction.validate()
        session.flush()
        return self.redir_to_list(transaction.date.year, transaction.date.month,
                                  msg='Transaction has been saved. {}'\
                                      .format(msg), show_list=True,
                                  tid=transaction.id)