예제 #1
0
  def get(self, **kwargs):
    re          = db.get(self.get_realestate_key())
    invoices    = []
    
    invoices.extend( Invoice.all().filter('realestate', re.key()).filter('state', Invoice._INPROCESS).order('date') )
    invoices.extend( Invoice.all().filter('realestate', re.key()).filter('state', Invoice._NOT_PAID).filter('date <= ', datetime.now()).order('date') )
    
    total_debt  = reduce(lambda x,i: x + (i.amount if i.state == Invoice._NOT_PAID else 0), invoices, 0)

    
    params = {
      're'        :re,
      'invoices'  :invoices,
      'total_debt':total_debt,
      'mnutop'    :'cuenta',
      'plan'      :re.plan,
      'Invoice'   :Invoice,
    }
      
    return self.render_response('backend/account.html', **params)
예제 #2
0
    def get(self, **kwargs):
        re = get_or_404(kwargs['key'])

        blobs = []
        imgs = []
        props = []

        for img in ImageFile.all().filter('realestate', re.key()):
            blobs.append(img.file.key())
            imgs.append(img.key())

        blobstore.delete(blobs)
        db.delete(imgs)

        props = []
        for prop in Property.all().filter('realestate', re.key()):
            props.append(prop.key())

        db.delete(props)

        pis = []
        for pi in PropertyIndex.all().filter('realestate', re.key()):
            pis.append(pi.key())

        db.delete(pis)

        invs = []
        pays = []
        for inv in Invoice.all().filter('realestate', re.key()):
            invs.append(inv)
            if inv.payment:
                pays.append(inv.payment.key())

        db.delete(invs)
        db.delete(pays)

        usrs = []
        for usr in User.all().filter('realestate', re.key()):
            usrs.append(usr)

        db.delete(usrs)

        mRealEstateFriendship = []
        for fr in RealEstateFriendship.all().filter('realestates',
                                                    str(re.key())):
            mRealEstateFriendship.append(fr)

        db.delete(mRealEstateFriendship)

        re.delete()

        self.response.write('borrado %s' % kwargs['key'])
예제 #3
0
    def map(self, payment):

        # Traemos la factura que este pago cancela el pago (payment)
        invoice = Invoice.all().filter('Trx_id', payment.trx_id).get()
        if not invoice:
            logging.error('No encontre factura para el pago %s' %
                          str(payment.key()))
            return ([], [])

        # Obtenemos el realestate en funcion del trx_id
        id_or_name = payment.trx_id[7:]  #YYYYMM[NI]ddddddd

        re = None
        if payment.trx_id[6] == 'I':
            re = RealEstate.get_by_id(int(id_or_name))
        else:
            re = RealEstate.get_by_key_name(id_or_name)

        if re is None:
            logging.error('No encontre el realestate para %s' % payment.trx_id)
            return ([], [])

        invoice.realestate = re

        # Ponemos la factura en estado pagada
        invoice.state = Invoice._PAID
        invoice.payment = payment
        invoice.save()

        # Acabamos de asignar un pago, deberiamos automaticamente
        # poner en ENABLED a la inmo si es que no estaba en ese estado
        # Si esta volviendo a ENABLE desde NO_PAYMENT debemos comunicarle que 'las props estan publicadas nuevamente'

        oldst = re.status

        # payment_received
        if re.status == RealEstate._ENABLED:
            send_mail('payment_received', re)
        else:
            re.status = RealEstate._ENABLED
            re.save()

            if oldst == RealEstate._NO_PAYMENT:
                send_mail('enabled_again', re, invoice)

        payment.assigned = 1
        return ([payment], [])  # update/delete