Bug 20726: Add new method Acquisition::Order->invoice

Can be moved to a separate bug report.

Sponsored-by: BULAC - http://www.bulac.fr/

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2018-05-07 19:46:05 -03:00 committed by Nick Clemens
parent aa97f13411
commit 1756b874a3
4 changed files with 136 additions and 1 deletions

View file

@ -0,0 +1,40 @@
package Koha::Acquisition::Invoice;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Koha::Database;
use base qw(Koha::Object);
=head1 NAME
Koha::Acquisition::Invoice object class
=head1 API
=head2 Internal methods
=head3 _type
=cut
sub _type {
return 'Aqinvoice';
}
1;

View file

@ -0,0 +1,50 @@
package Koha::Acquisition::Invoices;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Koha::Database;
use Koha::Acquisition::Invoice;
use base qw(Koha::Objects);
=head1 NAME
Koha::Acquisition::Invoices object set class
=head1 API
=head2 Internal methods
=head3 _type (internal)
=cut
sub _type {
return 'Aqinvoice';
}
=head3 object_class (internal)
=cut
sub object_class {
return 'Koha::Acquisition::Invoice';
}
1;

View file

@ -21,6 +21,7 @@ use Carp qw( croak );
use Koha::Acquisition::Baskets;
use Koha::Acquisition::Funds;
use Koha::Acquisition::Invoices;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref );
@ -135,6 +136,21 @@ sub fund {
return Koha::Acquisition::Fund->_new_from_dbic( $fund_rs );
}
=head3 invoice
my $invoice = $order->invoice
Returns the invoice associated to the order.
=cut
sub invoice {
my ( $self ) = @_;
my $invoice_rs = $self->_result->invoiceid;
return unless $invoice_rs;
return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs );
}
=head2 Internal methods
=head3 _type

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 3;
use Test::More tests => 4;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -114,3 +114,32 @@ subtest 'fund' => sub {
'->fund should return a Koha::Acquisition::Fund object' );
$schema->storage->txn_rollback;
};
subtest 'invoice' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $o = $builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => { cancellationreason => 'XXXXXXXX', invoiceid => undef }, # not received yet
}
);
my $order = Koha::Acquisition::Orders->find( $o->ordernumber );
is( $order->invoice, undef,
'->invoice should return undef if no invoice defined yet');
my $invoice = $builder->build_object(
{
class => 'Koha::Acquisition::Invoices',
},
);
$o->invoiceid( $invoice->invoiceid )->store;
$order = Koha::Acquisition::Orders->find( $o->ordernumber );
is( ref( $order->invoice ), 'Koha::Acquisition::Invoice',
'->invoice should return a Koha::Acquisition::Invoice object if an invoice is defined');
$schema->storage->txn_rollback;
};