MT#14653 Add required field billing_profile_id to billing zone api

And to billing fees;
And also go through uniquizer for the billing_plan cloning

Change-Id: Ia53519f28970c4c717fd011f119143a6323235e5
changes/39/2439/3
Irina Peshinskaya 10 years ago
parent ff75e75138
commit 0512e767b9

@ -238,6 +238,7 @@ sub POST :Allow {
c => $c,
resource => $resource,
form => $form,
exceptions => ['billing_profile_id'],
);

@ -167,13 +167,12 @@ sub POST :Allow {
}
my $form = $self->get_form($c);
my $billing_profile_id = $resource->{billing_profile_id} // undef;
last unless $self->validate_form(
c => $c,
resource => $resource,
form => $form,
exceptions => ['billing_profile_id'],
);
$resource->{billing_profile_id} = $billing_profile_id;
my $profile = $schema->resultset('billing_profiles')->find($resource->{billing_profile_id});
unless($profile) {

@ -4,6 +4,15 @@ use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::BillingFee';
use Moose::Util::TypeConstraints;
has_field 'billing_profile_id' => (
type => 'PosInteger',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The billing profile this billing fee belongs to.']
},
);
has_field 'purge_existing' => (
type => 'Boolean',
element_attr => {
@ -13,6 +22,7 @@ has_field 'purge_existing' => (
default => 0,
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],

@ -44,7 +44,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/id zone detail /],
render_list => [qw/id zone detail/],
);
has_block 'actions' => (

@ -0,0 +1,23 @@
package NGCP::Panel::Form::BillingZone::API;
use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::BillingZone';
use Moose::Util::TypeConstraints;
has_field 'billing_profile_id' => (
type => 'PosInteger',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The billing profile this billing zone belongs to.']
},
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/billing_profile_id zone detail/],
);
1;
# vim: set tabstop=4 expandtab:

@ -69,6 +69,7 @@ sub hal_from_fee {
form => $form,
resource => \%resource,
run => 0,
exceptions => ['billing_profile_id'],
);
$resource{id} = int($fee->id);

@ -13,7 +13,7 @@ use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Form::BillingZone qw();
use NGCP::Panel::Form::BillingZone::API qw();
sub item_rs {
my ($self, $c) = @_;
@ -38,7 +38,7 @@ sub item_rs {
sub get_form {
my ($self, $c) = @_;
return NGCP::Panel::Form::BillingZone->new;
return NGCP::Panel::Form::BillingZone::API->new;
}
sub hal_from_zone {
@ -70,6 +70,7 @@ sub hal_from_zone {
form => $form,
resource => \%resource,
run => 0,
exceptions => ['billing_profile_id'],
);
$resource{id} = int($zone->id);
@ -97,13 +98,12 @@ sub update_zone {
}
$form //= $self->get_form($c);
# TODO: for some reason, formhandler lets missing profile id
my $billing_profile_id = $resource->{billing_profile_id} // undef;
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
exceptions => ['billing_profile_id'],
);
$resource->{billing_profile_id} = $billing_profile_id;
if($old_resource->{billing_profile_id} != $resource->{billing_profile_id}) {
my $profile = $c->model('DB')->resultset('billing_profiles')

@ -179,7 +179,11 @@ sub clone_billing_profile_tackles{
$fees_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
my @records = $fees_rs->all;
$profile_new->billing_fees->populate(\@records) if @records;
$profile_new->billing_fees_raw->populate(\@records);
$schema->storage->dbh_do(sub{
my ($storage, $dbh) = @_;
$dbh->do("call billing.fill_billing_fees(?)", undef, $profile_new->id );
});
}
sub get_contract_count_stmt {

Loading…
Cancel
Save