コード例 #1
0
ファイル: models.py プロジェクト: shamanu4/biltv
    def fix_period_start(cls):
        from tv.models import Fee
        from tv.models import FeeType
        from tv.models import TariffPlan

        ss = cls.objects.filter(start__gte='2006-02-01').filter(start__lt='2011-03-01')
        ft = FeeType.objects.all()
        ft = ft[0]
        ft2 = FeeType.objects.all()
        ft2 = ft2[4]
        tp = TariffPlan.objects.all()
        tp = tp[0]

        for s in ss:
            m1 = ft.get_sum(date=s.start)['fee']
            m2 = ft2.get_sum(date=s.start)['fee']
            m = m2-m1
            try:
                bill = s.iac.bill
                card = s.iac.catv_card
                print "%s %s | %s | %s %s" % (card,bill,m,m1,m2)
                f = Fee(bill=bill,card=card,sum=-m,tp=tp,fee_type=ft,inner_descr=u'перенос бази. возврат подключение',timestamp=s.start)
                f.save()
                f.make()
            except:
                print "EXCEPTION CAUGHT!"
コード例 #2
0
    def fix_period_end(cls):
        from tv.models import Fee
        from tv.models import FeeType
        from tv.models import TariffPlan

        ss = cls.objects.filter(finish__lte='2011-03-01')
        ft = FeeType.objects.all()
        ft = ft[0]
        tp = TariffPlan.objects.all()
        tp = tp[0]

        for s in ss:
            if not s.finish:
                continue
            try:
                bill = s.iac.bill
                card = s.iac.catv_card
                m = ft.get_sum(date=s.finish)['ret']
                print "%s %s | %s |" % (card, bill, m)
                f = Fee(bill=bill,
                        card=card,
                        sum=-m,
                        tp=tp,
                        fee_type=ft,
                        inner_descr=u'перенос бази. возврат отключение',
                        timestamp=s.finish)
                f.save()
                f.make()
            except:
                print "EXCEPTION CAUGHT!"
コード例 #3
0
    def fix_period_start(cls):
        from tv.models import Fee
        from tv.models import FeeType
        from tv.models import TariffPlan

        ss = cls.objects.filter(start__gte='2006-02-01').filter(
            start__lt='2011-03-01')
        ft = FeeType.objects.all()
        ft = ft[0]
        ft2 = FeeType.objects.all()
        ft2 = ft2[4]
        tp = TariffPlan.objects.all()
        tp = tp[0]

        for s in ss:
            m1 = ft.get_sum(date=s.start)['fee']
            m2 = ft2.get_sum(date=s.start)['fee']
            m = m2 - m1
            try:
                bill = s.iac.bill
                card = s.iac.catv_card
                print "%s %s | %s | %s %s" % (card, bill, m, m1, m2)
                f = Fee(bill=bill,
                        card=card,
                        sum=-m,
                        tp=tp,
                        fee_type=ft,
                        inner_descr=u'перенос бази. возврат подключение',
                        timestamp=s.start)
                f.save()
                f.make()
            except:
                print "EXCEPTION CAUGHT!"
コード例 #4
0
ファイル: models.py プロジェクト: shamanu4/biltv
    def fix_period_end(cls):
        from tv.models import Fee
        from tv.models import FeeType
        from tv.models import TariffPlan

        ss = cls.objects.filter(finish__lte='2011-03-01')
        ft = FeeType.objects.all()
        ft = ft[0]
        tp = TariffPlan.objects.all()
        tp = tp[0]

        for s in ss:
            if not s.finish:
                continue                
            try:
                bill = s.iac.bill
                card = s.iac.catv_card
                m = ft.get_sum(date=s.finish)['ret']
                print "%s %s | %s |" % (card,bill,m)
                f = Fee(bill=bill,card=card,sum=-m,tp=tp,fee_type=ft,inner_descr=u'перенос бази. возврат отключение',timestamp=s.finish)
                f.save()
                f.make()
            except:
                print "EXCEPTION CAUGHT!"
コード例 #5
0
ファイル: rpc.py プロジェクト: shamanu4/biltv
    def make_transfer(self, rdata, request):
        from tv.models import Fee, Payment
        from abon.models import Abonent
        from datetime import datetime

        descr = rdata["descr"] or ""

        if "abonent_from" in rdata and rdata["abonent_from"] > 0:
            pass
        else:
            return dict(
                success=False,
                title="Сбой переносa средств",
                msg="Invalid option value: abonent_from",
                errors="",
                data={},
            )

        if "abonent_to" in rdata and rdata["abonent_to"] > 0:
            pass
        else:
            return dict(
                success=False, title="Сбой переносa средств", msg="Invalid option value: abonent_to", errors="", data={}
            )

        if "sum" in rdata and rdata["sum"] > 0:
            pass
        else:
            return dict(
                success=False, title="Сбой переносa средств", msg="Invalid option value: sum", errors="", data={}
            )

        if "date" in rdata and rdata["date"] > 0:
            date = rdata["date"]
            try:
                date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S").date()
            except ValueError:
                return dict(success=False, title="Сбой переносa средств", msg="invalid date", errors="", data={})
        else:
            return dict(success=False, title="Сбой переносa средств", msg="invalid date", errors="", data={})
        try:
            abon_from = Abonent.objects.get(pk=rdata["abonent_from"])
            abon_to = Abonent.objects.get(pk=rdata["abonent_to"])
        except Abonent.DoesNotExist:
            return dict(success=False, title="Сбой переносa средств", msg="Abonent not found", errors="", data={})
        else:
            f = Fee()
            f.bill = abon_from.bill
            f.sum = rdata["sum"]
            f.descr = "Трансфер средств. recipient client id = %s " % abon_to.pk
            f.inner_descr = descr
            f.admin = request.user
            f.bank_date = date
            f.save()
            f.make()

            p = Payment()
            p.bill = abon_to.bill
            p.sum = rdata["sum"]
            p.descr = "Трансфер средств. source client id = %s " % abon_from.pk
            p.inner_descr = descr
            p.admin = request.user
            p.bank_date = date
            p.save()
            p.make()

        print rdata
        return dict(success=True, title="Перенос средств успешен", msg="...", errors="", data={})
コード例 #6
0
ファイル: rpc.py プロジェクト: shamanu4/biltv
    def make_fee(self, rdata, request):
        from tv.models import FeeType, Fee, Payment
        from abon.models import Abonent
        from datetime import datetime

        print rdata

        ftype_id = int(rdata["type"])
        uid = int(rdata["abonent"])
        sum = float(rdata["sum"])
        tmpdate = rdata["bankdate"]
        descr = rdata["descr"] or ""
        autopay = rdata["autopay"] or False
        autoactivate = rdata["autoactivate"] or False

        try:
            ftype = FeeType.objects.get(pk=ftype_id)
        except FeeType.DoesNotExist:
            return dict(success=False, title="Сбой снятия денег", msg="register not found", errors="", data={})

        inner_descr = "%s [%s] (%s)" % (ftype.__unicode__(), rdata["sum"], rdata["descr"] or "")

        try:
            abonent = Abonent.objects.get(pk=uid)
        except Abonent.DoesNotExist:
            return dict(success=False, title="Сбой снятия денег", msg="abonent not found", errors="", data={})

        try:
            bank_date = datetime.strptime(tmpdate, "%Y-%m-%dT%H:%M:%S").date()
        except ValueError:
            return dict(success=False, title="Сбой снятия денег", msg="invalid date", errors="", data={})

        f = Fee()
        f.fee_type = ftype
        f.bill = abonent.bill
        f.sum = sum
        f.descr = descr
        f.inner_descr = inner_descr
        f.admin = request.user
        f.timestamp = bank_date
        f.save()
        f.make()

        if autopay:
            p = Payment()
            p.register = None
            p.source = None
            p.bill = abonent.bill
            p.sum = sum
            p.descr = descr
            p.inner_descr = inner_descr
            p.admin = request.user
            p.bank_date = bank_date
            p.save()
            p.make()

        if autoactivate:
            if abonent.disabled:
                rdata["date"] = rdata["bankdate"]
                rdata["descr"] = inner_descr
                return [
                    self.enable(rdata, request=request),
                    dict(success=True, title="Снятие проведено", msg="...", errors="", data={}),
                ]

        return dict(success=True, title="Снятие проведено", msg="...", errors="", data={})
コード例 #7
0
ファイル: models.py プロジェクト: shamanu4/biltv
 def launch_hamster(self,countdown=True,debug=True):
     from lib.functions import date_formatter, add_months
     from tv.models import FeeType, Fee, Payment, TariffPlan
     from django.db.models import Max
     from time import sleep
     import gc
     
     gc.enable()
     
     if debug:
         print "Abonent %s" % self
         if countdown:
             print "    hamster ready to be launched."
             print "    all finance log will be recalculated."
             print "    use only when neccecary."
             print "    -------------------------------------"        
             print "    you have 5 sec to cancel... (Ctrl+C)"
             try:
                 sleep(1)
                 print "    4..."
                 sleep(1)
                 print "    3..."
                 sleep(1)
                 print "    2..."
                 sleep(1)
                 print "    1..."
                 sleep(1)
                 print "    hamster launched..."
             except KeyboardInterrupt:
                 print "    hamster launching cancelled..."
                 print "    Bye..."
                 return False
     
         print "        resetting all finance log..."
         
     self.bill.balance=0
     self.bill.save()
     Fee.objects.filter(bill=self.bill).delete()
     self.catv_card.service_log.all().delete()
     
     pp = Payment.objects.filter(bill=self.bill)
     for p in pp:
         p.maked=False
         if not p.bank_date:
             p.bank_date=p.timestamp.date()
         p.save()
     if debug:
         print "            Done..."
     
     catv = FeeType.objects.get(pk=5)
     catv_part = FeeType.objects.get(pk=1)
     tp = TariffPlan.objects.all()
     tp = tp[0]
     
     thismonth = date_formatter(date.today())['month'].date()
     nextmonth = date_formatter(add_months(thismonth,1))['month'].date()
             
     new = True
     prev_closing_fee = 0
     prev_closing_month = date(1970,1,1)
             
     for i in self.intervals.all():
         if debug:
             print "        processing interval %s-%s" % (i.start,i.finish)
         if not i.finish:
             i.finish = thismonth
         d = i.start    
         
         for service in self.catv_card.services.all():
             service.active=True
             service.save(sdate=d,descr="%s/%s" % (i.s1,i.s2))
             self.catv_card.active = True
             self.catv_card.save()
             self.disabled= False
             self.save()
             
         dd = date_formatter(add_months(d,1))['month'].date()
         
         if debug:
             print "            starting date %s" % d
         pp = Payment.objects.filter(bill=self.bill,maked=False,bank_date__lte=d)
         for p in pp:
             p.save()
             p.make()
         if d > date(2006,2,1) or not new:
             full = catv.get_sum(date=i.start)['fee']
             sum = catv_part.get_sum(date=i.start)['fee']
             if debug:
                 print "                full fee: %s" % full
                 print "                current fee: %s" % sum
                 print "                closing fee: %s" % prev_closing_fee
                 print "                closing month: %s" % prev_closing_month
                 print "                currnet month: %s" % date_formatter(d)['month'].date()
                 print sum+prev_closing_fee>full
                 print date_formatter(d)['month'].date() == prev_closing_month
             if sum+prev_closing_fee>full and date_formatter(d)['month'].date() == prev_closing_month:
                 print "                overpowered fee catched! fixed..."
                 f = Fee(bill=self.bill,card=self.catv_card,sum=full-prev_closing_fee,tp=tp,fee_type=catv_part,timestamp=d, inner_descr=u'Кабельное ТВ | подключение (!)')
             else: 
                 f = Fee(bill=self.bill,card=self.catv_card,sum=sum,tp=tp,fee_type=catv_part,timestamp=d, inner_descr=u'Кабельное ТВ | подключение')
             f.save()
             maxid = Fee.objects.aggregate(Max('id'))['id__max']
             f = Fee.objects.get(pk=maxid) 
             f.make()
         else:
             if debug:
                 print "                ignored because before 2006-02-01"
             f = Fee(bill=self.bill,card=self.catv_card,sum=0,tp=tp,fee_type=catv_part,timestamp=d, inner_descr=u'Кабельное ТВ | подключение (оплачено на месте)')
             f.save()
             maxid = Fee.objects.aggregate(Max('id'))['id__max']
             f = Fee.objects.get(pk=maxid)                 
             f.make()
         new = False                
         d = dd
         dd = date_formatter(add_months(d,1))['month'].date()
         pp = Payment.objects.filter(bill=self.bill,maked=False,bank_date__lte=d)
         for p in pp:
             p.save()
             p.make()
         
         
         while dd < i.finish or dd == nextmonth or dd == thismonth:
             if debug:
                 print "            processing date %s" % d
             sum = catv.get_sum(date=d)['fee']              
             f = Fee(bill=self.bill,card=self.catv_card,sum=sum,tp=tp,fee_type=catv,timestamp=d, inner_descr=u'Кабельное ТВ | абонплата')
             f.save()
             maxid = Fee.objects.aggregate(Max('id'))['id__max']
             f = Fee.objects.get(pk=maxid)                 
             f.make()                
             d = dd
             dd = date_formatter(add_months(d,1))['month'].date()
             pp = Payment.objects.filter(bill=self.bill,maked=False,bank_date__lte=d)
             for p in pp:
                 p.save()
                 p.make()
         
         
         if d < thismonth:
             if debug:
                 print "            closing date %s" % d
             full = catv.get_sum(date=i.finish)['fee']
             sum = full - catv_part.get_sum(date=i.finish)['ret']                
             prev_closing_fee = sum
             prev_closing_month = date_formatter(i.finish)['month'].date()
             f = Fee(bill=self.bill,card=self.catv_card,sum=sum,tp=tp,fee_type=catv,timestamp=i.finish, inner_descr=u'Кабельное ТВ | отключение')
             f.save()
             maxid = Fee.objects.aggregate(Max('id'))['id__max']
             f = Fee.objects.get(pk=maxid)                 
             f.make()
             
             for service in self.catv_card.services.all():
                 service.active=False
                 service.save(sdate=d,descr="")
                 self.catv_card.active = False
                 self.catv_card.save()
                 self.disabled= True
                 self.save()
         
         pp = Payment.objects.filter(bill=self.bill,maked=False,bank_date__lte=d)
         for p in pp:
             p.save()
             p.make()
     
     pp = Payment.objects.filter(bill=self.bill,maked=False)
     for p in pp:
         p.save()
         p.make()
                                    
     if debug:
         print "    hamster finished his work and stopped"
         print "    dont forget donate to WWF ;)"
         print "    Bye..."
     
     gc.collect()
     return True
コード例 #8
0
    def launch_hamster(self, countdown=True, debug=True):
        from lib.functions import date_formatter, add_months
        from tv.models import FeeType, Fee, Payment, TariffPlan
        from django.db.models import Max
        from time import sleep
        import gc

        gc.enable()

        if debug:
            print "Abonent %s" % self
            if countdown:
                print "    hamster ready to be launched."
                print "    all finance log will be recalculated."
                print "    use only when neccecary."
                print "    -------------------------------------"
                print "    you have 5 sec to cancel... (Ctrl+C)"
                try:
                    sleep(1)
                    print "    4..."
                    sleep(1)
                    print "    3..."
                    sleep(1)
                    print "    2..."
                    sleep(1)
                    print "    1..."
                    sleep(1)
                    print "    hamster launched..."
                except KeyboardInterrupt:
                    print "    hamster launching cancelled..."
                    print "    Bye..."
                    return False

            print "        resetting all finance log..."

        self.bill.balance = 0
        self.bill.save()
        Fee.objects.filter(bill=self.bill).delete()
        self.catv_card.service_log.all().delete()

        pp = Payment.objects.filter(bill=self.bill)
        for p in pp:
            p.maked = False
            if not p.bank_date:
                p.bank_date = p.timestamp.date()
            p.save()
        if debug:
            print "            Done..."

        catv = FeeType.objects.get(pk=5)
        catv_part = FeeType.objects.get(pk=1)
        tp = TariffPlan.objects.all()
        tp = tp[0]

        thismonth = date_formatter(date.today())['month'].date()
        nextmonth = date_formatter(add_months(thismonth, 1))['month'].date()

        new = True
        prev_closing_fee = 0
        prev_closing_month = date(1970, 1, 1)

        for i in self.intervals.all():
            if debug:
                print "        processing interval %s-%s" % (i.start, i.finish)
            if not i.finish:
                i.finish = thismonth
            d = i.start

            for service in self.catv_card.services.all():
                service.active = True
                service.save(sdate=d, descr="%s/%s" % (i.s1, i.s2))
                self.catv_card.active = True
                self.catv_card.save()
                self.disabled = False
                self.save()

            dd = date_formatter(add_months(d, 1))['month'].date()

            if debug:
                print "            starting date %s" % d
            pp = Payment.objects.filter(bill=self.bill,
                                        maked=False,
                                        bank_date__lte=d)
            for p in pp:
                p.save()
                p.make()
            if d > date(2006, 2, 1) or not new:
                full = catv.get_sum(date=i.start)['fee']
                sum = catv_part.get_sum(date=i.start)['fee']
                if debug:
                    print "                full fee: %s" % full
                    print "                current fee: %s" % sum
                    print "                closing fee: %s" % prev_closing_fee
                    print "                closing month: %s" % prev_closing_month
                    print "                currnet month: %s" % date_formatter(
                        d)['month'].date()
                    print sum + prev_closing_fee > full
                    print date_formatter(
                        d)['month'].date() == prev_closing_month
                if sum + prev_closing_fee > full and date_formatter(
                        d)['month'].date() == prev_closing_month:
                    print "                overpowered fee catched! fixed..."
                    f = Fee(bill=self.bill,
                            card=self.catv_card,
                            sum=full - prev_closing_fee,
                            tp=tp,
                            fee_type=catv_part,
                            timestamp=d,
                            inner_descr=u'Кабельное ТВ | подключение (!)')
                else:
                    f = Fee(bill=self.bill,
                            card=self.catv_card,
                            sum=sum,
                            tp=tp,
                            fee_type=catv_part,
                            timestamp=d,
                            inner_descr=u'Кабельное ТВ | подключение')
                f.save()
                maxid = Fee.objects.aggregate(Max('id'))['id__max']
                f = Fee.objects.get(pk=maxid)
                f.make()
            else:
                if debug:
                    print "                ignored because before 2006-02-01"
                f = Fee(bill=self.bill,
                        card=self.catv_card,
                        sum=0,
                        tp=tp,
                        fee_type=catv_part,
                        timestamp=d,
                        inner_descr=
                        u'Кабельное ТВ | подключение (оплачено на месте)')
                f.save()
                maxid = Fee.objects.aggregate(Max('id'))['id__max']
                f = Fee.objects.get(pk=maxid)
                f.make()
            new = False
            d = dd
            dd = date_formatter(add_months(d, 1))['month'].date()
            pp = Payment.objects.filter(bill=self.bill,
                                        maked=False,
                                        bank_date__lte=d)
            for p in pp:
                p.save()
                p.make()

            while dd < i.finish or dd == nextmonth or dd == thismonth:
                if debug:
                    print "            processing date %s" % d
                sum = catv.get_sum(date=d)['fee']
                f = Fee(bill=self.bill,
                        card=self.catv_card,
                        sum=sum,
                        tp=tp,
                        fee_type=catv,
                        timestamp=d,
                        inner_descr=u'Кабельное ТВ | абонплата')
                f.save()
                maxid = Fee.objects.aggregate(Max('id'))['id__max']
                f = Fee.objects.get(pk=maxid)
                f.make()
                d = dd
                dd = date_formatter(add_months(d, 1))['month'].date()
                pp = Payment.objects.filter(bill=self.bill,
                                            maked=False,
                                            bank_date__lte=d)
                for p in pp:
                    p.save()
                    p.make()

            if d < thismonth:
                if debug:
                    print "            closing date %s" % d
                full = catv.get_sum(date=i.finish)['fee']
                sum = full - catv_part.get_sum(date=i.finish)['ret']
                prev_closing_fee = sum
                prev_closing_month = date_formatter(i.finish)['month'].date()
                f = Fee(bill=self.bill,
                        card=self.catv_card,
                        sum=sum,
                        tp=tp,
                        fee_type=catv,
                        timestamp=i.finish,
                        inner_descr=u'Кабельное ТВ | отключение')
                f.save()
                maxid = Fee.objects.aggregate(Max('id'))['id__max']
                f = Fee.objects.get(pk=maxid)
                f.make()

                for service in self.catv_card.services.all():
                    service.active = False
                    service.save(sdate=d, descr="")
                    self.catv_card.active = False
                    self.catv_card.save()
                    self.disabled = True
                    self.save()

            pp = Payment.objects.filter(bill=self.bill,
                                        maked=False,
                                        bank_date__lte=d)
            for p in pp:
                p.save()
                p.make()

        pp = Payment.objects.filter(bill=self.bill, maked=False)
        for p in pp:
            p.save()
            p.make()

        if debug:
            print "    hamster finished his work and stopped"
            print "    dont forget donate to WWF ;)"
            print "    Bye..."

        gc.collect()
        return True