Esempio n. 1
0
    def savePayment(self, member_id, items):
        """ Save a new or edited payment """
        verified = False

        if self.is_finance_admin() and ParamChecker.checkInt(
                'verified', param=True, optional=True):
            verified = True

        if items['idPayment'] > 0:
            try:
                np = self.db.query(Payment).filter(
                    Payment.id == items['idPayment']).one()
                np.verified = verified
            except:
                self.session['flash'] = _('Invalid record')
                self.session.save()
                raise HTTPRedirect(
                    '/payments/listPayments/?member_id={0}'.format(member_id))
        else:
            np = Payment()
            np.verified = verified
            np.status = 0

        for key, value in items.iteritems():
            setattr(np, key, value)

        try:
            np.uid = member_id
        except:
            self.session['flash'] = _('Invalid member')
            self.session.save()
            raise HTTPRedirect(
                '/payments/listPayments/?member_id={0}'.format(member_id))

        # Cleanup session
        if 'reqparams' in self.session:
            del (self.session['reqparams'])
        self.session.save()
        ##########

        self.db.add(np)
        self.db.commit()

        self.session['flash'] = _('Payment saved successfully.')
        self.session['flash_class'] = 'success'
        self.session.save()

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Esempio n. 2
0
  def savePayment(self, member_id, items):
    """ Save a new or edited payment """
    verified = False

    if self.is_finance_admin() and ParamChecker.checkInt('verified', param=True, optional=True):
      verified = True

    if items['idPayment'] > 0:
      try:
        np = self.db.query(Payment).filter(Payment.id == items['idPayment']).one()
        np.verified = verified
      except:
        self.session['flash'] = _('Invalid record')
        self.session.save()
        raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
    else:
      np = Payment()
      np.verified = verified
      np.status = 0

    for key, value in items.iteritems():
      setattr(np, key, value)

    try:
      np.uid = member_id
    except:
      self.session['flash'] = _('Invalid member')
      self.session.save()
      raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))

    # Cleanup session
    if 'reqparams' in self.session:
      del(self.session['reqparams'])
    self.session.save()
    ##########

    self.db.add(np)
    self.db.commit()

    self.session['flash'] = _('Payment saved successfully.')
    self.session['flash_class'] = 'success'
    self.session.save()

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
Esempio n. 3
0
    def doBulkAdd(self, member_id, months, verified=None):
        try:
            ParamChecker.checkUsername('member_id', param=True)
            ParamChecker.checkInt('months', param=True, max_len=2)
        except:
            raise HTTPRedirect('/payments/index')

        lastDate = self._getLastPayment(member_id)
        months = int(months)

        if self.is_finance_admin():
            try:
                ParamChecker.checkInt('verified', param=True, max_len=1)
                verified = True
            except:
                verified = False

        try:
            for i in range(months):
                p = Payment()
                p.uid = member_id
                p.date = lastDate + relativedelta(months=i)
                p.status = 0
                p.verified = verified

                self.db.add(p)

            self.db.commit()

            self.session['flash'] = _('Payments added')
            self.session['flash_class'] = 'success'
        except Exception as e:
            self.session['flash'] = _('Operation failed')
            self.session['flash_class'] = 'error'

        self.session.save()

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Esempio n. 4
0
  def doBulkAdd(self, member_id, months, verified=None):
    try:
      ParamChecker.checkUsername('member_id', param=True)
      ParamChecker.checkInt('months', param=True, max_len=2)
    except:
      raise HTTPRedirect('/payments/index')

    lastDate = self._getLastPayment(member_id)
    months = int(months)

    if self.is_finance_admin():
      try:
        ParamChecker.checkInt('verified', param=True, max_len=1)
        verified = True
      except:
        verified = False

    try:
      for i in range(months):
        p = Payment()
        p.uid = member_id
        p.date = lastDate + relativedelta(months=i)
        p.status = 0
        p.verified = verified

        self.db.add(p)

      self.db.commit()

      self.session['flash'] = _('Payments added')
      self.session['flash_class'] = 'success'
    except Exception as e:
      self.session['flash'] = _('Operation failed')
      self.session['flash_class'] = 'error'

    self.session.save()

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))