MT#59478 /api/contracts address $now and hal_from_contract

* the following changes resolve an issue where $now in Role/Contracts
  resource_from_item appeared as an object and failed subsequent
  logic:
    - hal_from_contract is renamed to hal_from_item to match correctly
      the parent method
    - call hal_from_item and pass $now string there correctly as $params
      { now => $now }

Change-Id: I5c02d5f7df5d9000550505ad120b9531f87e8d65
(cherry picked from commit 9dbd6b0e88)
mr12.3.1
Kirill Solomko 1 year ago
parent faa8aa2c1f
commit 79e7ec692d

@ -101,7 +101,7 @@ sub GET :Allow {
my $form = $self->get_form($c);
for my $contract (@$contracts) {
#NGCP::Panel::Utils::ProfilePackages::get_contract_balance
push @embedded, $self->hal_from_contract($c, $contract, $form, $now);
push @embedded, $self->hal_from_item($c, $contract, $form, { now => $now });
push @links, Data::HAL::Link->new(
relation => 'ngcp:'.$self->resource_name,
href => sprintf('/%s%d', $c->request->path, $contract->id),

@ -56,7 +56,7 @@ sub GET :Allow {
my $contract = $self->contract_by_id($c, $id);
last unless $self->resource_exists($c, contract => $contract);
my $hal = $self->hal_from_contract($c, $contract, undef, NGCP::Panel::Utils::DateTime::current_local);
my $hal = $self->hal_from_item($c, $contract, undef);
$guard->commit; #potential db write ops in hal_from
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
@ -112,7 +112,7 @@ sub PATCH :Allow {
#$c->log->debug(Dumper($contract));
last unless $contract;
my $hal = $self->hal_from_contract($c, $contract, $form, $now);
my $hal = $self->hal_from_item($c, $contract, $form, { now => $now });
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -147,7 +147,7 @@ sub PUT :Allow {
$contract = $self->update_contract($c, $contract, $old_resource, $resource, $form, $now);
last unless $contract;
my $hal = $self->hal_from_contract($c, $contract, $form, $now);
my $hal = $self->hal_from_item($c, $contract, $form, { now => $now });
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;

@ -44,6 +44,7 @@ sub resource_from_item {
my %resource = $item->get_inflated_columns;
$now //= NGCP::Panel::Utils::DateTime::current_local;
my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $item, );
my $billing_profile_id = $billing_mapping->billing_profile->id;
my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($item);
@ -73,8 +74,12 @@ sub resource_from_item {
return \%resource;
}
sub hal_from_contract {
my ($self, $c, $contract, $form, $now) = @_;
sub hal_from_item {
my ($self, $c, $contract, $form, $params) = @_;
my $now = $params && $params->{now}
? $params->{now}
: NGCP::Panel::Utils::DateTime::current_local;
my $resource = $self->resource_from_item($c, $contract, $form, $now);

Loading…
Cancel
Save