Bug 24161: Keep tracks of late orders claims
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 16 Dec 2019 17:35:08 +0000 (18:35 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 4 May 2020 08:44:44 +0000 (09:44 +0100)
So far we only record the number of claims and the date of the last
claim, in the aqorders table.
To keep track of the different claim dates, this patchset is going to
make the following DB changes:
  * Create a new table 'aqorders_claims' (id, ordernumber, claimed_on)
  * Remove the two columns from the aqorders table: claims_count and
  claimed_date

This will allow to display the different claim dates where needed: on
the late orders page, and the basket page.

To avoid additional fetches of Koha::Acquisition::Orders, GetLateOrders
has been moved to Koha::Acquisition::Orders->filter_by_late
That way we are going to add consistency, robustness, and cover the
feature with new tests.

Test plan:
0/ Create a bunch of new orders. Make sure they are from different
vendor (with different delivery time).
1/ Go to the late orders page and claim some orders
2/ Reclaim some of those orders
3/ Confirm that you can see the different claim dates for a given orders
(the history of the late orders claims is kept and displayed)

4/ Bonus point: Regression tests:

a. Modify the closedate of the basket in the database. That
will allow you to make sure the patch set did not introduce regressions.
It would be good to test the different filters on the late orders page:
 * delay
 * Estimated delivery date from/to
 * Vendor

b. Confirm that the subtotal and the total values from the late orders
page is correct.

c. Test the update database entry: do not apply these patches, claims
some orders against master. Apply the patch, execute the update DB entry
then confirm that the number of claims is correct (note that the dates
will not as it is not possible to guess them).

QA note: the branchcode parameter has been removed from filter_by_late.
At first glance it seems that it was not used.

Sponsored-by: Cork Institute of Technology
Signed-off-by: Angela O'Connor Desmond <angela.oconnordesmond@staff.ittralee.ie>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

14 files changed:
C4/Acquisition.pm
Koha/Acquisition/Basket.pm
Koha/Acquisition/Order.pm
Koha/Acquisition/Order/Claim.pm
Koha/Acquisition/Order/Claims.pm
Koha/Acquisition/Orders.pm
acqui/basket.pl
acqui/lateorders-export.pl
acqui/lateorders.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/showorder.tt
t/db_dependent/Acquisition.t

index da0a9b4..e9f288d 100644 (file)
@@ -1222,8 +1222,6 @@ sub GetOrder {
                 biblioitems.publishercode,
                 aqorders.rrp              AS unitpricesupplier,
                 aqorders.ecost            AS unitpricelib,
-                aqorders.claims_count     AS claims_count,
-                aqorders.claimed_date     AS claimed_date,
                 aqbudgets.budget_name     AS budget,
                 aqbooksellers.name        AS supplier,
                 aqbooksellers.id          AS supplierid,
index 39b2899..1aad128 100644 (file)
@@ -20,6 +20,7 @@ package Koha::Acquisition::Basket;
 use Modern::Perl;
 
 use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
 use Koha::Acquisition::BasketGroups;
 use Koha::Patrons;
 
@@ -88,6 +89,56 @@ sub effective_create_items {
     return $self->create_items || C4::Context->preference('AcqCreateItem');
 }
 
+=head3 estimated_delivery_date
+
+my $estimated_delivery_date = $basket->estimated_delivery_date;
+
+Return the estimated delivery date for this basket.
+
+It is calculated adding the delivery time of the vendor to the close date of this basket.
+
+Return implicit undef if the basket is not closed, or the vendor does not have a delivery time.
+
+=cut
+
+sub estimated_delivery_date {
+    my ( $self ) = @_;
+    return unless $self->closedate and $self->bookseller->deliverytime;
+    return dt_from_string($self->closedate)->add( days => $self->bookseller->deliverytime);
+}
+
+=head3 late_since_days
+
+my $number_of_days_late = $basket->late_since_days;
+
+Return the number of days the basket is late.
+
+Return implicit undef if the basket is not closed.
+
+=cut
+
+sub late_since_days {
+    my ( $self ) = @_;
+    return unless $self->closedate;
+    return dt_from_string->delta_days(dt_from_string($self->closedate))->delta_days();
+}
+
+=head3 authorizer
+
+my $authorizer = $basket->authorizer;
+
+Returns the patron who authorized/created this basket.
+
+=cut
+
+sub authorizer {
+    my ($self) = @_;
+    # FIXME We should use a DBIC rs, but the FK is missing
+    return unless $self->authorisedby;
+    return scalar Koha::Patrons->find($self->authorisedby);
+}
+
+
 =head3 to_api
 
     my $json = $basket->to_api;
index 5135a33..2747a78 100644 (file)
@@ -22,6 +22,7 @@ use Carp qw( croak );
 use Koha::Acquisition::Baskets;
 use Koha::Acquisition::Funds;
 use Koha::Acquisition::Invoices;
+use Koha::Acquisition::Order::Claims;
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Biblios;
@@ -239,6 +240,62 @@ sub biblio {
     return Koha::Biblio->_new_from_dbic( $biblio_rs );
 }
 
+=head3 claims
+
+    my $claims = $order->claims
+
+Return the claims history for this order
+
+=cut
+
+sub claims {
+    my ( $self ) = @_;
+    my $claims_rs = $self->_result->aqorders_claims;
+    return Koha::Acquisition::Order::Claims->_new_from_dbic( $claims_rs );
+}
+
+=head3 claim
+
+    my $claim = $order->claim
+
+Do claim for this order
+
+=cut
+
+sub claim {
+    my ( $self ) = @_;
+    my $claim_rs = $self->_result->create_related('aqorders_claims', {});
+    return Koha::Acquisition::Order::Claim->_new_from_dbic($claim_rs);
+}
+
+=head3 claims_count
+
+my $nb_of_claims = $order->claims_count;
+
+This is the equivalent of $order->claims->count. Keeping it for retrocompatibilty.
+
+=cut
+
+sub claims_count {
+    my ( $self ) = @_;
+    return $self->claims->count;
+}
+
+=head3 claimed_date
+
+my $last_claim_date = $order->claimed_date;
+
+This is the equivalent of $order->claims->last->claimed_on. Keeping it for retrocompatibilty.
+
+=cut
+
+sub claimed_date {
+    my ( $self ) = @_;
+    my $last_claim = $self->claims->last;
+    return unless $last_claim;
+    return $last_claim->claimed_on;
+}
+
 =head3 duplicate_to
 
     my $duplicated_order = $order->duplicate_to($basket, [$default_values]);
index 1fb7bc1..a2ce117 100644 (file)
@@ -31,6 +31,8 @@ Koha::Acquisition::Order::Claim - Koha Claim Object class
 
 =head2 Class methods
 
+=cut
+
 =head2 Internal methods
 
 =head3 _type
index 5423dba..7856f26 100644 (file)
@@ -35,7 +35,7 @@ Koha::Cities - Koha Claim Object set class
 
 =cut
 
-=head3 type
+=head3 _type
 
 =cut
 
@@ -43,6 +43,10 @@ sub _type {
     return 'AqordersClaim';
 }
 
+=head3 object_class
+
+=cut
+
 sub object_class {
     return 'Koha::Acquisition::Order::Claim';
 }
index 19fa24c..e504c58 100644 (file)
@@ -21,6 +21,7 @@ use Carp;
 
 use Koha::Database;
 
+use Koha::DateUtils qw( dt_from_string );
 use Koha::Acquisition::Order;
 
 use base qw(Koha::Objects);
@@ -31,6 +32,104 @@ Koha::Acquisition::Orders object set class
 
 =head1 API
 
+=head2 Class Methods
+
+=head3 filter_by_lates
+
+my $late_orders = $orders->filter_by_lates($params);
+
+Filter an order set given different parameters.
+
+This is the équivalent method of the former GetLateOrders C4 subroutine
+
+$params can be:
+
+=over
+
+=item C<delay> the number of days the basket has been closed
+
+=item C<bookseller_id> the bookseller id
+
+=item C<estimated_from> Beginning of the estimated delivery date
+
+=item C<estimated_to> End of the estimated delivery date
+
+=back
+
+=cut
+
+sub filter_by_lates {
+    my ( $self, $params ) = @_;
+    my $delay = $params->{delay};
+    my $bookseller_id = $params->{bookseller_id};
+    # my $branchcode = $params->{branchcode}; # FIXME do we really need this
+    my $estimated_from = $params->{estimated_from};
+    my $estimated_to = $params->{estimated_to};
+    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+
+    my @delivery_time_conditions;
+    my $date_add = "DATE_ADD(basketno.closedate, INTERVAL COALESCE(booksellerid.deliverytime, booksellerid.deliverytime, 0) day)";
+    if ( defined $estimated_from or defined $estimated_to ) {
+        push @delivery_time_conditions, \[ "$date_add IS NOT NULL" ];
+    }
+    if ( defined $estimated_from ) {
+        push @delivery_time_conditions, \[ "$date_add >= ?", $dtf->format_date($estimated_from) ];
+    }
+    if ( defined $estimated_to ) {
+        push @delivery_time_conditions, \[ "$date_add <= ?", $dtf->format_date($estimated_to) ];
+    }
+    if ( defined $estimated_from and not defined $estimated_to ) {
+        push @delivery_time_conditions, \[ "$date_add <= ?", $dtf->format_date(dt_from_string) ];
+    }
+
+    $self->search(
+        {
+            -or => [
+                { datereceived => undef },
+                quantityreceived => { '<' => \'quantity' }
+            ],
+            'basketno.closedate' => [
+                -and =>
+                { '!=' => undef },
+                {
+                    defined $delay
+                    ? (
+                        '<=' => $dtf->format_date(
+                            dt_from_string->subtract( days => $delay )
+                        )
+                      )
+                    : ()
+                }
+              ],
+            'datecancellationprinted' => undef,
+            (
+                $bookseller_id
+                ? ( 'basketno.booksellerid' => $bookseller_id )
+                : ()
+            ),
+
+            # ( $branchcode ? ('borrower.branchcode')) # FIXME branch is not a filter we may not need to implement this
+
+            ( @delivery_time_conditions ? ( -and => \@delivery_time_conditions ) : ()),
+            (
+                C4::Context->preference('IndependentBranches')
+                  && !C4::Context->IsSuperLibrarian
+                ? ( 'borrower.branchcode' => C4::Context->userenv->{branch} )
+                : ()
+            ),
+
+            ( orderstatus => { '!=' => 'cancelled' } ),
+
+        },
+        {
+            '+select' => [\"DATE_ADD(basketno.closedate, INTERVAL COALESCE(booksellerid.deliverytime, booksellerid.deliverytime, 0) day)"],
+            '+as' => ['estimated_delivery_date'],
+            join => { 'basketno' => 'booksellerid' },
+            prefetch => {'basketno' => 'booksellerid'},
+        }
+    );
+}
+
 =head2 Internal methods
 
 =head3 _type (internal)
index 459f295..92f3614 100755 (executable)
@@ -498,6 +498,7 @@ sub get_order_infos {
         $line{left_holds_on_order}  = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
         $line{holds}                = $holds_count;
         $line{holds_on_order}       = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order};
+        $line{order_object}         = $order;
     }
 
 
index cefe613..eb04ba7 100755 (executable)
@@ -36,6 +36,8 @@ my @ordernumbers = $input->multi_param('ordernumber');
 my @orders;
 for my $ordernumber ( @ordernumbers ) {
     my $order = GetOrder $ordernumber;
+    my $order_object = Koha::Acquisition::Orders->find($ordernumber);
+    my $claims = $order_object->claims;
     push @orders, {
             orderdate => $order->{orderdate},
             latesince => $order->{latesince},
@@ -51,8 +53,8 @@ for my $ordernumber ( @ordernumbers ) {
             budget => $order->{budget},
             basketname => $order->{basketname},
             basketno => $order->{basketno},
-            claims_count => $order->{claims_count},
-            claimed_date => $order->{claimed_date},
+            claims_count => $claims->count,
+            claimed_date => $claims->count ? $claims->last->claimed_on : undef,
             internalnote => $order->{order_internalnote},
             vendornote   => $order->{order_vendornote},
             isbn => $order->{isbn},
index 5dc9ea6..1367e17 100755 (executable)
@@ -108,7 +108,7 @@ if ($op and $op eq "send_alert"){
     eval {
         $err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") );
         if ( not ref $err or not exists $err->{error} ) {
-            AddClaim ( $_ ) for @ordernums;
+            Koha::Acquisition::Orders->find($_)->claim() for @ordernums;
         }
     };
 
@@ -145,34 +145,32 @@ $template->param(SUPPLIER_LOOP => \@sloopy);
 $template->param(Supplier=>$supplierlist{$booksellerid}) if ($booksellerid);
 $template->param(booksellerid=>$booksellerid) if ($booksellerid);
 
-@parameters =
-  ( $delay, $booksellerid, $branch );
-if ($estimateddeliverydatefrom_dt) {
-    push @parameters, $estimateddeliverydatefrom_dt->ymd();
-}
-else {
-    push @parameters, undef;
-}
-if ($estimateddeliverydateto_dt) {
-    push @parameters, $estimateddeliverydateto_dt->ymd();
-}
-my @lateorders = GetLateOrders( @parameters );
-
-my $total;
-foreach (@lateorders){
-       $total += $_->{subtotal};
-}
+my $lateorders = Koha::Acquisition::Orders->filter_by_lates(
+    {
+        delay        => $delay,
+        booksellerid => $booksellerid,
+        (
+            $estimateddeliverydatefrom_dt
+            ? ( estimated_from => $estimateddeliverydatefrom_dt )
+            : ()
+        ),
+        (
+            $estimateddeliverydateto_dt
+            ? ( estimated_to => $estimateddeliverydateto_dt )
+            : ()
+        )
+    }
+);
 
 my $letters = GetLetters({ module => "claimacquisition" });
 
 $template->param(ERROR_LOOP => \@errors) if (@errors);
 $template->param(
-       lateorders => \@lateorders,
+    lateorders => $lateorders,
        delay => $delay,
     letters => $letters,
     estimateddeliverydatefrom => $estimateddeliverydatefrom,
     estimateddeliverydateto   => $estimateddeliverydateto,
-       total => $total,
        intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
 );
 output_html_with_http_headers $input, $cookie, $template->output;
index 8673673..fedd90c 100644 (file)
                                 </span>
                               </p>
                             [% END %]
+                            [% SET claims = books_loo.order_object.claims %]
+                            [% IF claims.count %]
+                                <p>
+                                    This order has been claimed [% claims.count | html %] times. On [% FOR c IN claims %][% c.claimed_on | $KohaDates %][% UNLESS loop.last %], [% END %][% END %]
+                                </p>
+                            [% END %]
                         </td>
                         [% SET zero_regex = "^0{1,}\.?0{1,}[^1-9]" %] [%# 0 or 0.0 or 0.00 or 00 or 00.0 or 00.00 or 0.000 ... %]
                         [%# FIXME: use of a regexp is not ideal; bugs 9410 and 10929 suggest better way of handling this %]
index 1ce7d8c..95200db 100644 (file)
@@ -6,14 +6,14 @@
 [%- INCLUDE empty_line.inc -%]
 
 [%- FOREACH o IN orders -%]
-"[% o.orderdate | html %] ([% o.latesince | html %] days)"[%- delimiter | html -%]
+"[% o.orderdate | $KohaDates %] ([% o.latesince | html %] days)"[%- delimiter | html -%]
 "[% o.estimateddeliverydate | $KohaDates %]"[%- delimiter | html -%]
 "[% o.supplier (o.supplierid) | html %]"[%- delimiter | html -%]
 "[% o.title | html %] [% IF o.author %]Author: [% o.author | html %].[% END %][% IF o.publisher %]Published by: [% o.publisher | html %].[% END %]"[%- delimiter | html -%]
 "[% o.unitpricesupplier | html %] x [% o.quantity_to_receive | html %] = [% o.subtotal | html %] ([% o.budget | html %])"[%- delimiter | html -%]
 "[% o.basketname | html %] ([% o.basketno | html %])"[%- delimiter | html -%]
 "[% o.claims_count | html %]"[%- delimiter | html -%]
-"[% o.claimed_date | html %]"[%- delimiter | html -%]
+"[% o.claimed_date | $KohaDates %]"[%- delimiter | html -%]
 "[% o.internalnote | html %]"[%- delimiter | html -%]
 "[% o.vendornote | html %]"[%- delimiter | html -%]
 "[% o.isbn | html %]"
index 200cd1e..d29539b 100644 (file)
@@ -3,6 +3,7 @@
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE ColumnsSettings %]
+[% USE Price %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Late orders</title>
@@ -35,7 +36,7 @@
 [% IF info_claim %]
     <div class="dialog message">Email has been sent.</div>
 [% END %]
-[% IF ( lateorders ) %]
+[% IF lateorders.count %]
 <form action="lateorders.pl" name="claim" method="post">
   <input type="hidden" name="op" value="send_alert" />
   <input type="hidden" name="delay" value="[% delay | html %]" />
@@ -48,6 +49,7 @@
          </select>
        </p>
        [% END %]
+    [% SET total = 0 %]
     <table id="late_orders">
       <thead>
         <tr>
       [% FOREACH lateorder IN lateorders %]
         <tr>
             <td>
-                <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.supplierid | html %]" name="ordernumber">
+                <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.basket.booksellerid | html %]" name="ordernumber">
             </td>
             <td>
                 [% lateorder.ordernumber | $raw %]
             </td>
             <td>
-                <span title="[% lateorder.orderdate | html %]">[% lateorder.orderdate | $KohaDates %] ([% lateorder.latesince | html %] days)</span>
+                <span title="[% lateorder.basket.closedate | html %]">[% lateorder.basket.closedate | $KohaDates %] ([% lateorder.basket.late_since_days | html %] days)</span>
             </td>
             <td>
-                [% IF ( lateorder.estimateddeliverydate ) %]
-                    <span title="[% lateorder.estimateddeliverydate | html %]">[% lateorder.estimateddeliverydate | $KohaDates  %]</span>
-                [% ELSE %]
-                    <span title="0000-00-00"></span>
+                [% SET estimated_delivery_date = lateorder.get_column('estimated_delivery_date') %]
+                [% IF estimated_delivery_date %]
+                    <span title="[% estimated_delivery_date | html %]">[% estimated_delivery_date | $KohaDates  %]</span>
                 [% END %]
             </td>
             <td>
-                [% lateorder.supplier | html %]
-                ([% lateorder.supplierid | html %])
+                [% lateorder.basket.bookseller.name | html %]
+                ([% lateorder.basket.bookseller.id | html %])
             </td>
             <td>
-                <b>[% lateorder.title | html %]</b>
-                   [% IF ( lateorder.author ) %]<br/><i>Author:</i> [% lateorder.author | html %][% END %]
-                   [% IF ( lateorder.publisher ) %]
-                        <br/><i>Published by:</i> [% lateorder.publisher | html %]
-                        [% IF ( lateorder.publicationyear ) %]
-                            <i> in </i>[% lateorder.publicationyear | html %]
+                <b>[% lateorder.biblio.title | html %]</b>
+                   [% IF ( lateorder.biblio.author ) %]<br/><i>Author:</i> [% lateorder.biblio.author | html %][% END %]
+                   [% IF ( lateorder.biblio.biblioitem.publishercode ) %]
+                        <br/><i>Published by:</i> [% lateorder.biblio.biblioitem.publishercode | html %]
+                        [% IF ( lateorder.biblio.biblioitem.publicationyear ) %]
+                            <i> in </i>[% lateorder.biblio.biblioitem.publicationyear | html %]
                         [% END %]
                    [% END %]
             </td>
             <td>
-                   [% lateorder.unitpricesupplier | html %]x[% lateorder.quantity | html %] = 
-                   [% lateorder.subtotal | html %]
+                [% SET subtotal = (lateorder.quantity - lateorder.quantityreceived) * lateorder.rrp %]
+                [% SET total = total + subtotal %]
+                [% lateorder.rrp | html %]x[% lateorder.quantity - lateorder.quantityreceived | html %] = [% subtotal | $Price %]
             </td>
             <td>
                 [% IF ( CAN_user_acquisition_order_manage ) %]
-                    <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basketname | html %] ([% lateorder.basketno | html %])</a>
+                    <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])</a>
                 [% ELSE %]
-                    [% lateorder.basketname | html %] ([% lateorder.basketno | html %])
+                    [% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])
                 [% END %]
             </td>
             <td>
-                [% IF ( lateorder.basketgroupid ) %]
+                [% IF ( lateorder.basket.basketgroupid ) %]
                     [% IF ( CAN_user_acquisition_group_manage ) %]
-                        <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.supplierid | uri %]&basketgroupid=[% lateorder.basketgroupid | uri %]" title="basketgroup">[% lateorder.basketgroupname | html %] ([% lateorder.basketgroupid | html %])</a>
+                        <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.basket.booksellerid | uri %]&basketgroupid=[% lateorder.basket.basketgroupid | uri %]" title="basketgroup">[% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
                     [% ELSE %]
-                        [% lateorder.basketgroupname | html %] ([% lateorder.basketgroupid | html %])</a>
+                        [% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
                     [% END %]
                 [% END %]
             </td>
-            <td>[% Branches.GetName( lateorder.branch ) | html %]
+            <td>[% Branches.GetName( lateorder.basket.authorizer.branchcode ) | html %]
             </td>
-            <td>[% lateorder.budget | html %]
+            <td>[% lateorder.fund.budget_name | html %]
             </td>
-            <td>[% lateorder.claims_count | html %]</td>
+            <td>[% lateorder.claims.count | html %]</td>
             <td>
-                [% IF ( lateorder.claimed_date ) %]
-                    <span title="[% lateorder.claimed_date | html %]">[% lateorder.claimed_date | $KohaDates %]</span>
-                [% ELSE %]
-                    <span title="0000-00-00"></span>
+                [% FOR claim IN lateorder.claims %]
+                    <span title="[% lateorder.claims.last.claimed_on | html %]">[% claim.claimed_on | $KohaDates %]</span>
                 [% END %]
             </td>
             <td>
-                [% IF ( lateorder.internalnote ) %]
+                [% IF lateorder.order_internalnote %]
                     <p class="ordernote">
-                        <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.internalnote | html %]</span>
+                        <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.order_internalnote | html %]</span>
                         <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal" title="Edit internal note">
                             <i class="fa fa-pencil"></i> Edit internal note
                         </a>
                 [% END %]
             </td>
             <td>
-                [% IF ( lateorder.vendornote ) %]
+                [% IF lateorder.order_vendornote %]
                     <p class="ordernote">
-                        <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.vendornote | html %]</span>
+                        <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.order_vendornote | html %]</span>
                         <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="vendor" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor" title="Edit vendor note">
                             <i class="fa fa-pencil"></i> Edit vendor note
                         </a>
                     </a>
                 [% END %]
             </td>
-            <td>[% lateorder.isbn | $raw %]</td>
+            <td>[% lateorder.biblio.biblioitem.isbn | $raw %]</td>
         </tr>
       [% END %]
       </tbody>
       <tfoot>
         <tr>
             <th colspan="6">Total</th>
-            <th>[% total | html %]</th>
+            <th>[% total | $Price %]</th>
             <th colspan="9">&nbsp;</th>
         </tr>
       </tfoot>
index 9a4e538..8d026af 100644 (file)
                     </li>
                     <li>
                         <span class="label">Claims count: </span>
-                        [% order.claims_count | html %]
+                        [% order.claims.count | html %]
                     </li>
                     <li>
                         <span class="label">Last claim date: </span>
-                        [% order.claimed_date | html %]
+                        [% order.claims.last.claimed_on | html %]
                     </li>
             </ol>
           </fieldset>
index 4469dc9..912a451 100755 (executable)
@@ -391,16 +391,16 @@ is( scalar (@$search_orders), 0, "SearchOrders takes into account the biblionumb
 ok( GetBudgetByOrderNumber( $ordernumbers[0] )->{'budget_id'} eq $budgetid,
     "GetBudgetByOrderNumber returns expected budget" );
 
-my @lateorders = GetLateOrders(0);
-is( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
+my $lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
+is( $lateorders->search({ 'me.basketno' => $basketno })->count,
     0, "GetLateOrders does not get orders from opened baskets" );
 C4::Acquisition::CloseBasket($basketno);
-@lateorders = GetLateOrders(0);
-isnt( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
+$lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
+isnt( $lateorders->search({ 'me.basketno' => $basketno })->count,
     0, "GetLateOrders gets orders from closed baskets" );
-ok( !grep ( $_->{ordernumber} eq $ordernumbers[3], @lateorders ),
+is( $lateorders->search({ ordernumber => $ordernumbers[3] })->count, 0,
     "GetLateOrders does not get cancelled orders" );
-ok( !grep ( $_->{ordernumber} eq $ordernumbers[4], @lateorders ),
+is( $lateorders->search({ ordernumber => $ordernumbers[4] })->count, 0,
     "GetLateOrders does not get received orders" );
 
 $search_orders = SearchOrders({
@@ -415,13 +415,12 @@ is( scalar (@$search_orders), 4, "SearchOrders with pending and ordered params g
 # Test AddClaim
 #
 
-my $order = $lateorders[0];
-AddClaim( $order->{ordernumber} );
-my $neworder = GetOrder( $order->{ordernumber} );
+my $order = $lateorders->next;
+$order->claim();
 is(
-    $neworder->{claimed_date},
+    output_pref({ str => $order->claimed_date, dateformat => 'iso', dateonly => 1 }),
     strftime( "%Y-%m-%d", localtime(time) ),
-    "AddClaim : Check claimed_date"
+    "Koha::Acquisition::Order->claim: Check claimed_date"
 );
 
 my $order2 = Koha::Acquisition::Orders->find( $ordernumbers[1] )->unblessed;
@@ -449,7 +448,7 @@ is(
     "ModReceiveOrder only changes the supplied orders internal notes"
 );
 
-$neworder = GetOrder($new_ordernumber);
+my $neworder = GetOrder($new_ordernumber);
 is( $neworder->{'quantity'}, 2, '2 items on new order' );
 is( $neworder->{'quantityreceived'},
     2, 'Splitting up order received items on new order' );