MT#7227 Use procedure to make records unique on single fee insertion

Change-Id: Id55faa08bcb3513abc2afcd04a23f34e1d59628c
changes/62/3462/4
Irina Peshinskaya 10 years ago
parent 997bdc0085
commit 2685c45074

@ -226,7 +226,13 @@ sub POST :Allow {
my $fee;
try {
$fee = $profile->billing_fees->create($resource);
$fee = NGCP::Panel::Utils::Billing::insert_unique_billing_fees(
c => $c,
schema => $schema,
profile => $profile,
fees => [$resource],
return_created => 1,
)->[0];
} catch($e) {
$c->log->error("failed to create billing fee: $e"); # TODO: user, message, trace, ...
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create billing fee.");

@ -416,8 +416,16 @@ sub fees_create :Chained('fees_list') :PathPart('create') :Args(0) {
);
if($form->validated) {
$form->values->{source} ||= '.';
$c->stash->{'profile_result'}
->billing_fees->create($form->values);
my $schema = $c->model('DB');
$schema->txn_do(sub {
NGCP::Panel::Utils::Billing::insert_unique_billing_fees(
c => $c,
schema => $schema,
profile => $c->stash->{'profile_result'},
fees => [$form->values],
return_created => 1,
);
});
delete $c->session->{created_objects}->{billing_zone};
NGCP::Panel::Utils::Message::info(
c => $c,

@ -82,12 +82,13 @@ sub process_billing_fees{
push @fees, $row;
}
$profile->billing_fees_raw->populate(\@fees);
$schema->storage->dbh_do(sub{
my ($storage, $dbh) = @_;
$dbh->do("call billing.fill_billing_fees(?)", undef, $profile->id );
});
insert_unique_billing_fees(
c => $c,
schema => $schema,
profile => $profile,
fees => \@fees
);
my $text = $c->loc('Billing Fee successfully uploaded');
if(@fails) {
$text .= $c->loc(", but skipped the following line numbers: ") . (join ", ", @fails);
@ -96,6 +97,24 @@ sub process_billing_fees{
return ( \@fees, \@fails, \$text );
}
sub insert_unique_billing_fees{
my(%params) = @_;
my($c,$schema,$profile,$fees,$return_created) = @params{qw/c schema profile fees return_created/};
$return_created //= 0;
my $created_fees_raw = $profile->billing_fees_raw->populate($fees);
$schema->storage->dbh_do(sub{
my ($storage, $dbh) = @_;
$c->log->debug('call billing.fill_billing_fees('.$profile->id.')');
$dbh->do("call billing.fill_billing_fees(?)", undef, $profile->id );
});
#return section
if($return_created){
my @created_fees = $profile->billing_fees->search({ 'id' => { -in => [map { $_->id } @$created_fees_raw] } } )->all;
return \@created_fees;
}
return;
}
sub combine_billing_fees{
my(%params) = @_;
my($c,$profile,$schema) = @params{qw/c profile schema/};

Loading…
Cancel
Save