From f3b711a050c782ca8efebfa2aa76d7f455c111a9 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Mon, 27 Jul 2015 18:42:36 +0200 Subject: [PATCH] MT#13903 disable applying profile package This is a patcht introducing a variable to disable setting profile_package_id's in in the contracts table. The code should therefore behave as before, as long rate-o-mat and libswrate are ready. Not once set to 1 and contract balances are written to a database once, disabling this constant will mess up contract_balances! Change-Id: I080460395627202f3f5a386022de643577f4f3c2 --- lib/NGCP/Panel/Controller/API/Customers.pm | 1 + lib/NGCP/Panel/Controller/Customer.pm | 2 ++ lib/NGCP/Panel/Role/API/Customers.pm | 1 + lib/NGCP/Panel/Utils/ProfilePackages.pm | 6 +++++- t/api-balanceintervals.t | 11 ++++++----- t/api-customers.t | 8 +++++++- t/api-profilepackages.t | 10 ++++++++-- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/Customers.pm b/lib/NGCP/Panel/Controller/API/Customers.pm index de0f8d610b..7b4b887321 100644 --- a/lib/NGCP/Panel/Controller/API/Customers.pm +++ b/lib/NGCP/Panel/Controller/API/Customers.pm @@ -218,6 +218,7 @@ sub POST :Allow { form => $form, exceptions => [ "contact_id", "billing_profile_id", "profile_package_id" ], ); + $resource->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; my $mappings_to_create = []; last unless NGCP::Panel::Utils::Contract::prepare_billing_mappings( diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 58d646ce62..6491c9732a 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -153,6 +153,7 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) { $form->values->{$_.'_id'} = $form->values->{$_}{id} || undef; delete $form->values->{$_}; } + $form->values->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; $form->values->{create_timestamp} = $form->values->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; $form->values->{external_id} = $form->field('external_id')->value; unless($form->values->{max_subscribers} && length($form->values->{max_subscribers})) { @@ -455,6 +456,7 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) { $form->values->{$_.'_id'} = $form->values->{$_}{id} || undef; delete $form->values->{$_}; } + $form->values->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; $form->values->{modify_timestamp} = $now; $form->values->{external_id} = $form->field('external_id')->value; unless($form->values->{max_subscribers} && length($form->values->{max_subscribers})) { diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index a5dfb229f3..30ea35260c 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -162,6 +162,7 @@ sub update_customer { resource => $resource, exceptions => [ "contact_id", "billing_profile_id", "profile_package_id" ], ); + $resource->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; #my $now = NGCP::Panel::Utils::DateTime::current_local; diff --git a/lib/NGCP/Panel/Utils/ProfilePackages.pm b/lib/NGCP/Panel/Utils/ProfilePackages.pm index 8a110d4ae3..6ddd98cd63 100644 --- a/lib/NGCP/Panel/Utils/ProfilePackages.pm +++ b/lib/NGCP/Panel/Utils/ProfilePackages.pm @@ -36,6 +36,7 @@ use constant _DEFAULT_PROFILE_FREE_TIME => 0; use constant _DEFAULT_PROFILE_FREE_CASH => 0.0; #use constant _DEFAULT_NOTOPUP_DISCARD_INTERVALS => undef; +use constant ENABLE_PROFILE_PACKAGES => 0; sub get_contract_balance { my %params = @_; @@ -256,7 +257,10 @@ sub topup_contract_balance { my $old_package = $contract->profile_package; $package = $voucher_package // $old_package; my $topup_amount = ($voucher ? $voucher->amount : $amount) // 0.0; - + + $voucher_package = undef unless ENABLE_PROFILE_PACKAGES; + $package = undef unless ENABLE_PROFILE_PACKAGES; + my $mappings_to_create = []; if ($package) { #always apply (old or new) topup profiles $topup_amount -= $package->service_charge; diff --git a/t/api-balanceintervals.t b/t/api-balanceintervals.t index db18d61fb5..c40565e2d9 100644 --- a/t/api-balanceintervals.t +++ b/t/api-balanceintervals.t @@ -26,9 +26,10 @@ BEGIN { unshift(@INC,'../lib'); } use NGCP::Panel::Utils::DateTime qw(); +use NGCP::Panel::Utils::ProfilePackages qw(); my $is_local_env = 0; - +my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; use Config::General; my $catalyst_config; @@ -166,7 +167,7 @@ my $billingprofile = _create_billing_profile("test_default"); my $tb; my $tb_cnt; -if (_get_allow_fake_client_time()) { +if (_get_allow_fake_client_time() && $enable_profile_packages) { { #_start_recording(); @@ -427,7 +428,7 @@ if (_get_allow_fake_client_time()) { _set_time(NGCP::Panel::Utils::DateTime::from_string($ts)); $customer = _switch_package($customer,$prof_package_topup); - + sleep(1); #sigh _check_interval_history($customer,[ { start => '2014-10-01 00:00:00', stop => '~2014-10-04 13:00:00'}, { start => '~2014-10-04 13:00:00', stop => $infinite_future}, @@ -517,7 +518,7 @@ if (_get_allow_fake_client_time()) { my $intervals_a = $t_a->join(); my $intervals_b = $t_b->join(); my $t2 = time; - is_deeply([ sort { $a->{id} cmp $b->{id} } @{ $intervals_b->{_embedded}->{'ngcp:balanceintervals'} } ],$intervals_a->{_embedded}->{'ngcp:balanceintervals'},'compare interval collection results of threaded requests deeply'); + is_deeply([ sort { $a->{id} <=> $b->{id} } @{ $intervals_b->{_embedded}->{'ngcp:balanceintervals'} } ],$intervals_a->{_embedded}->{'ngcp:balanceintervals'},'compare interval collection results of threaded requests deeply'); ok($t2 - $t1 > 2*$delay,'expected delay to assume requests were processed after another'); } else { @@ -528,7 +529,7 @@ if (_get_allow_fake_client_time()) { } { #test balanceintervals root collection and item - _create_customers_threaded(3) unless _get_allow_fake_client_time(); + _create_customers_threaded(3) unless _get_allow_fake_client_time() && $enable_profile_packages; my $total_count = (scalar keys %customer_map); my $nexturi = $uri.'/api/balanceintervals/?page=1&rows=' . ((not defined $total_count or $total_count <= 2) ? 2 : $total_count - 1) . '&contact_id='.$custcontact->{id}; diff --git a/t/api-customers.t b/t/api-customers.t index 996550a473..f461130ee9 100644 --- a/t/api-customers.t +++ b/t/api-customers.t @@ -10,7 +10,13 @@ use DateTime qw(); use DateTime::Format::Strptime qw(); use DateTime::Format::ISO8601 qw(); +BEGIN { + unshift(@INC,'../lib'); +} +use NGCP::Panel::Utils::ProfilePackages qw(); + my $is_local_env = 0; +my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443'); @@ -737,7 +743,7 @@ my @allcustomers = (); } -{ +if ($enable_profile_packages) { $req = HTTP::Request->new('POST', $uri.'/api/billingprofiles/'); $req->header('Content-Type' => 'application/json'); diff --git a/t/api-profilepackages.t b/t/api-profilepackages.t index 412a465b5f..0108c45c30 100644 --- a/t/api-profilepackages.t +++ b/t/api-profilepackages.t @@ -9,7 +9,13 @@ use URI::Escape qw(); use JSON::PP; use LWP::Debug; +BEGIN { + unshift(@INC,'../lib'); +} +use NGCP::Panel::Utils::ProfilePackages qw(); + my $is_local_env = 0; +my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443'); @@ -91,7 +97,7 @@ $res = $ua->request($req); is($res->code, 200, "fetch POSTed billingnetwork"); my $billingnetwork = JSON::from_json($res->decoded_content); -{ +if ($enable_profile_packages) { $req = HTTP::Request->new('POST', $uri.'/api/profilepackages/'); $req->header('Content-Type' => 'application/json'); $req->header('Prefer' => 'return=representation'); @@ -152,7 +158,7 @@ my $billingnetwork = JSON::from_json($res->decoded_content); } -{ +if ($enable_profile_packages) { my @profile_packages = ();