示例#1
0
def generate_monthly_billing():
    #print datetime.now()
    #print 'Monthly billing task is running. %s'%datetime.datetime.now()

    now = datetime.datetime.now()
    billing_month = '%s-%s'%(ck_utils.get_last_month(now).year, ck_utils.get_last_month(now).month)
    begin,end = ck_utils.get_billing_month_period(CONF.collect.billing_month_start, billing_month)
    storage.generate_monthly_billing(ck_utils.reformat_month_style(billing_month), ck_utils.local2utc(begin), ck_utils.local2utc(end),ck_utils.local2utc(end))
示例#2
0
def generate_daily_billing():
    #print datetime.now()
    #print 'Daily billing task is running. %s' % datetime.datetime.now()

    now = datetime.datetime.now()
    billing_day_dt = now - datetime.timedelta(days=1)
    last_count = datetime.datetime(now.year, now.month, now.day, 0, 0, 0)
    billing_month = '%s-%s' % (billing_day_dt.year, billing_day_dt.month)
    if billing_day_dt.day < CONF.collect.billing_month_start:
        billing_month = '%s-%s' % (
                        ck_utils.get_last_month(
                            billing_day_dt.now()).year,
                        ck_utils.get_last_month(
                            billing_day_dt.now()).month)

    begin, end = ck_utils.get_billing_month_period(
        CONF.collect.billing_month_start, billing_month)
    storage.generate_monthly_billing(ck_utils.reformat_month_style(
                                     billing_month),
                                     ck_utils.local2utc(begin),
                                     ck_utils.local2utc(end),
                                     ck_utils.local2utc(last_count))
示例#3
0
 def test_get_last_month_without_dt(self, patch_utcnow_mock):
     date = datetime.datetime(2013, 12, 1)
     trans_dt = ck_utils.get_last_month()
     self.assertEqual(date, trans_dt)
     patch_utcnow_mock.assert_called_once_with()
示例#4
0
 def test_get_last_month_leap(self):
     base_date = datetime.datetime(2016, 3, 31)
     date = datetime.datetime(2016, 2, 1)
     trans_dt = ck_utils.get_last_month(base_date)
     self.assertEqual(date, trans_dt)
示例#5
0
 def test_get_last_month_without_dt(self, patch_utcnow_mock):
     date = datetime.datetime(2013, 12, 1)
     trans_dt = ck_utils.get_last_month()
     self.assertEqual(date, trans_dt)
     patch_utcnow_mock.assert_called_once_with()
示例#6
0
 def test_get_last_month_leap(self):
     base_date = datetime.datetime(2016, 3, 31)
     date = datetime.datetime(2016, 2, 1)
     trans_dt = ck_utils.get_last_month(base_date)
     self.assertEqual(date, trans_dt)