コード例 #1
0
ファイル: rent.py プロジェクト: chrisblythe812/gamemine
    def do_fix_rental_plans(self):
        today = datetime.datetime.now().date()
        def calc_next_payment_date(start_date, period):
            d = start_date.date() if isinstance(start_date, datetime.datetime) else start_date
            while d < today:
                d = inc_months(d, period, start_date)
            return d

        debug("Fixing rental plans...")
        qs = MemberRentalPlan.objects.filter(status=RentalPlanStatus.Active)
        debug("Going to fix %d of plans...", qs.count())
        for p, i in itertools.izip(qs, itertools.count(1)):
            if i % 100 == 0:
                debug(i)
            expire_in = RentalPlan.get_expire_in(p.plan)
            if expire_in:
                p.expiration_date = inc_months(p.start_date, expire_in, p.start_date)
                p.next_payment_amount = None
                p.next_payment_date = None
                if p.status == RentalPlanStatus.Active and p.expiration_date < today:
                    p.set_status(RentalPlanStatus.CanceledP, save=False)
            else:
                p.expiration_date = None
                _pd, amount = RentalPlan.get_next_payment(p.plan, p.start_date, datetime.datetime.now())
                reccuring_period = RentalPlan.get_reccuring_period(p.plan)
                p.next_payment_amount = amount
                p.next_payment_date = calc_next_payment_date(p.start_date, reccuring_period)
            p.save()
コード例 #2
0
ファイル: rent.py プロジェクト: chrisblythe812/gamemine
 def do_fix_next_payment_none(self):
     logger = logging.getLogger()
     hdlr = logging.FileHandler("d://planissue.log" )
     formatter = logging.Formatter('[%(asctime)s]%(levelname)-8s"%(message)s"','%Y-%m-%d %a %H:%M:%S') 
     hdlr.setFormatter(formatter)        
     logger.addHandler(hdlr)
     logger.setLevel(logging.INFO)
     date_x = datetime.now().date()
     qs = MemberRentalPlan.objects.filter(user__email__in=self.plan_with_billing_problem,status=RentalPlanStatus.Active)
     logger.info('total plans %d ' % qs.count())
     for member_plan in qs:
         try:
             if member_plan.start_date is None:
                 member_plan.start_date = date_x
                 member_plan.save()
             if member_plan.next_payment_date is None:
                 np = RentalPlan.get_next_payment(member_plan.plan, member_plan.start_date, member_plan.start_date)               
                 member_plan.next_payment_date, member_plan.next_payment_amount = np
                 member_plan.save()
             if member_plan.next_payment_date <= date_x:
                 if member_plan.scheduled_plan is not None:
                     member_plan.activate_scheduled_plan(fix_next_payment_none=member_plan.next_payment_date)
                 else:
                    if member_plan.take_recurring_billing(force_future_date=False):
                        logger.info('%s charged' % member_plan.user.id )
                    else:
                        logger.info('%s failed' % member_plan.user.email )
                    
         except Exception, _e:
             print _e
             pass
コード例 #3
0
ファイル: olddata.py プロジェクト: chrisblythe812/gamemine
 def do_fix_next_payments(self):
     today = datetime.now().date()
     for p in MemberRentalPlan.objects.filter(status=RentalPlanStatus.Active):
         nd = p.next_payment_date
         b = None
         for b in BillingHistory.objects.filter(user=p.user, type=TransactionType.RentPayment, status=TransactionStatus.Passed):
             break
         if not b:
             continue
         if b.timestamp >= datetime(2010, 11, 04):
             continue
         nnp = RentalPlan.get_next_payment(p.plan, p.start_date, b.timestamp.date())
         if not nnp:
             continue
         date, _amount = nnp
         if nd == date:
             continue
         if date <= today:
             continue
         p.next_payment_date = date
         p.save()