MT#19015 correctly use notopup_interval for periodic balance intervals

+creation of profile packages with hour and minute
 intervals was disabled in api-balanceintervals.t

Change-Id: Idd18ced9704522bf5d919155d866c91b81526b92
changes/53/5753/4
Rene Krenn 10 years ago
parent 17e7e848e2
commit 9d5085a8ba

@ -143,7 +143,7 @@ has_field 'notopup_discard_intervals' => (
type => 'PosInteger', type => 'PosInteger',
element_attr => { element_attr => {
rel => ['tooltip'], rel => ['tooltip'],
title => ['The balance will be discarded if no top-up happened for the the given number of balance intervals.'] title => ['The balance will be discarded if no top-up happened for the the given number of balance interval units.']
}, },
); );

@ -147,7 +147,7 @@ has_field 'notopup_discard_intervals' => (
label => 'Discard balance after intervals', label => 'Discard balance after intervals',
element_attr => { element_attr => {
rel => ['tooltip'], rel => ['tooltip'],
title => ['The balance will be discarded if no top-up happened for the the given number of balance intervals.'] title => ['The balance will be discarded if no top-up happened for the the given number of balance interval units.']
}, },
); );

@ -834,19 +834,27 @@ sub _get_notopup_expiration {
my $notopup_expiration = undef; my $notopup_expiration = undef;
if ($notopup_discard_intervals) { if ($notopup_discard_intervals) {
#take the start of the latest interval where a topup occured, #take the start of the latest interval where a topup occured,
#add the allowed number+1 of the current package' intervals. #add the allowed number+1 of the current package' interval units.
#the balance is discarded if the start of the next package #the balance is discarded if the start of the next package
#exceed this calculated expiration date. #exceed this calculated expiration date.
my $last_balance_w_topup; my $start = undef;
if ($last_balance) { if ($last_balance) { #infinite end means its a topup interval
$last_balance_w_topup = $last_balance; $start = $last_balance->start;
} else { } else { #find last interval with topup
$last_balance_w_topup = $contract->contract_balances->search({ topup_count => { '>' => 0 } },{ order_by => { '-desc' => 'end'},})->first; my $last_balance_w_topup = $contract->contract_balances->search({ topup_count => { '>' => 0 } },{ order_by => { '-desc' => 'end'},})->first;
$last_balance_w_topup = $contract->contract_balances->search(undef,{ order_by => { '-asc' => 'start'},})->first unless $last_balance_w_topup; $last_balance_w_topup = $contract->contract_balances->search(undef,{ order_by => { '-asc' => 'start'},})->first unless $last_balance_w_topup;
$notopup_discard_intervals += 1; if ($last_balance_w_topup) {
if (NGCP::Panel::Utils::DateTime::is_infinite_future($last_balance_w_topup->end)) {
# if the above queries hit the most recent, open end interval:
$start = $last_balance_w_topup->start;
} else {
# count expiration from the start of the next interval:
$start = $last_balance_w_topup->end->clone->add(seconds => 1);
}
}
} }
$notopup_expiration = _add_interval(NGCP::Panel::Utils::DateTime::set_local_tz($last_balance_w_topup->start),$interval_unit,$notopup_discard_intervals, $notopup_expiration = _add_interval(NGCP::Panel::Utils::DateTime::set_local_tz($start),$interval_unit,$notopup_discard_intervals,
_START_MODE_PRESERVE_EOM->{$start_mode} ? NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp) : undef) if $last_balance_w_topup; _START_MODE_PRESERVE_EOM->{$start_mode} ? NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp) : undef) if $start;
} }
return $notopup_expiration; return $notopup_expiration;
} }

@ -30,6 +30,7 @@ use NGCP::Panel::Utils::DateTime qw();
my $is_local_env = 0; my $is_local_env = 0;
my $disable_parallel_catchup = 1; my $disable_parallel_catchup = 1;
my $disable_hourly_intervals = 1;
#my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; #my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES;
#my $enable_profile_packages = 1; #my $enable_profile_packages = 1;
@ -150,6 +151,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
#goto SKIP; #goto SKIP;
#goto THREADED; #goto THREADED;
if ('Europe/Vienna' eq NGCP::Panel::Utils::DateTime::current_local()->time_zone->name) { if ('Europe/Vienna' eq NGCP::Panel::Utils::DateTime::current_local()->time_zone->name) {
if (!$disable_hourly_intervals) {
my $package = _create_profile_package('create','hour',1); my $package = _create_profile_package('create','hour',1);
{ {
@ -210,11 +212,12 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
_set_time(); _set_time();
} }
}
} else { } else {
diag("time zone '" . NGCP::Panel::Utils::DateTime::current_local()->time_zone->name . "', skipping DST test"); diag("time zone '" . NGCP::Panel::Utils::DateTime::current_local()->time_zone->name . "', skipping DST test");
} }
{ if (!$disable_hourly_intervals) {
my $package = _create_profile_package('create','hour',1); my $package = _create_profile_package('create','hour',1);
_set_time(NGCP::Panel::Utils::DateTime::from_string('2015-09-02 01:59:41')); _set_time(NGCP::Panel::Utils::DateTime::from_string('2015-09-02 01:59:41'));
@ -237,7 +240,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
_set_time(); _set_time();
} }
{ if (!$disable_hourly_intervals) {
my $package = _create_profile_package('create','minute',1); my $package = _create_profile_package('create','minute',1);
_set_time(NGCP::Panel::Utils::DateTime::from_string('2015-09-03 00:01:41')); _set_time(NGCP::Panel::Utils::DateTime::from_string('2015-09-03 00:01:41'));
@ -825,13 +828,14 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
undef $gantt_events; undef $gantt_events;
} }
#SKIP:
{ {
_set_time(NGCP::Panel::Utils::DateTime::from_string('2015-01-30 13:00:00')); _set_time(NGCP::Panel::Utils::DateTime::from_string('2015-01-30 13:00:00'));
my $profile_underrun = _create_billing_profile('UNDERRUN_NOTOPUP'); my $profile_underrun = _create_billing_profile('UNDERRUN_NOTOPUP');
my $profile_topup = _create_billing_profile('TOPUP_NOTOPUP'); my $profile_topup = _create_billing_profile('TOPUP_NOTOPUP');
my $package = _create_profile_package('create','month',1, notopup_discard_intervals => 3, my $package = _create_profile_package('create','month',1, notopup_discard_intervals => 2,
initial_balance => 0, carry_over_mode => 'carry_over', initial_balance => 0, carry_over_mode => 'carry_over',
topup_profiles => [{ profile_id => $profile_topup->{id}, }, ], topup_profiles => [{ profile_id => $profile_topup->{id}, }, ],
underrun_profile_threshold => 1, underrun_profiles => [{ profile_id => $profile_underrun->{id}, }, ],); underrun_profile_threshold => 1, underrun_profiles => [{ profile_id => $profile_underrun->{id}, }, ],);
@ -849,7 +853,7 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) {
{ start => '2015-01-30 00:00:00', stop => '2015-02-27 23:59:59', cash => 10, topups => 1, profile => $profile_underrun->{id} }, #topup { start => '2015-01-30 00:00:00', stop => '2015-02-27 23:59:59', cash => 10, topups => 1, profile => $profile_underrun->{id} }, #topup
{ start => '2015-02-28 00:00:00', stop => '2015-03-29 23:59:59', cash => 10, topups => 0, profile => $profile_topup->{id} }, { start => '2015-02-28 00:00:00', stop => '2015-03-29 23:59:59', cash => 10, topups => 0, profile => $profile_topup->{id} },
{ start => '2015-03-30 00:00:00', stop => '2015-04-29 23:59:59', cash => 10, topups => 0, profile => $profile_topup->{id} }, { start => '2015-03-30 00:00:00', stop => '2015-04-29 23:59:59', cash => 10, topups => 0, profile => $profile_topup->{id} },
{ start => '2015-04-30 00:00:00', stop => '2015-05-29 23:59:59', cash => 10, topups => 0, profile => $profile_topup->{id} }, { start => '2015-04-30 00:00:00', stop => '2015-05-29 23:59:59', cash => 0, topups => 0, profile => $profile_underrun->{id} }, #'notopup_discard_expiry' => '2015-04-30 00:00:00'
{ start => '2015-05-30 00:00:00', stop => '2015-06-29 23:59:59', cash => 0, topups => 0, profile => $profile_underrun->{id} }, { start => '2015-05-30 00:00:00', stop => '2015-06-29 23:59:59', cash => 0, topups => 0, profile => $profile_underrun->{id} },
#{ start => '2015-06-30 00:00:00', stop => '2015-07-29 23:59:59', cash => 0, topups => 0 }, #{ start => '2015-06-30 00:00:00', stop => '2015-07-29 23:59:59', cash => 0, topups => 0 },
]); ]);

Loading…
Cancel
Save