View | Details | Raw Unified | Return to bug 33568
Collapse All | Expand All

(-)a/Koha/Items.pm (-4 lines)
Lines 466-478 sub search_ordered { Link Here
466
        return $self->search(
466
        return $self->search(
467
            {},
467
            {},
468
            {
468
            {
469
                '+select' => [{
470
                    lpad => ['copynumber', \8, \"'0'"], '-as' => 'lpad_copynumber',
471
                }],
472
                order_by => [
469
                order_by => [
473
                    'homebranch.branchname',
470
                    'homebranch.branchname',
474
                    'me.enumchron',
471
                    'me.enumchron',
475
                    'lpad_copynumber',
476
                    {-desc => 'me.dateaccessioned'}
472
                    {-desc => 'me.dateaccessioned'}
477
                ],
473
                ],
478
                join => ['homebranch']
474
                join => ['homebranch']
(-)a/Koha/REST/V1/Biblios.pm (-1 lines)
Lines 307-313 sub get_items { Link Here
307
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
307
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
308
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
308
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
309
        my $items = $c->objects->search($items_rs);
309
        my $items = $c->objects->search($items_rs);
310
        delete $_->{lpad_copynumber} for @$items;
311
310
312
        return $c->render(
311
        return $c->render(
313
            status  => 200,
312
            status  => 200,
(-)a/t/db_dependent/Koha/Items.t (-12 / +2 lines)
Lines 1792-1798 subtest 'move_to_biblio() tests' => sub { Link Here
1792
1792
1793
subtest 'search_ordered' => sub {
1793
subtest 'search_ordered' => sub {
1794
1794
1795
    plan tests => 9;
1795
    plan tests => 8;
1796
1796
1797
    $schema->storage->txn_begin;
1797
    $schema->storage->txn_begin;
1798
1798
Lines 1824-1840 subtest 'search_ordered' => sub { Link Here
1824
            [ $item3->itemnumber, $item2->itemnumber, $item1->itemnumber ],
1824
            [ $item3->itemnumber, $item2->itemnumber, $item1->itemnumber ],
1825
            "not a serial - order by enumchron" );
1825
            "not a serial - order by enumchron" );
1826
1826
1827
        # order_by LPAD( me.copynumber, 8, '0' )
1828
        $biblio->items->update( { enumchron => undef } );
1829
        $item1->discard_changes->update( { copynumber => '12345678' } );
1830
        $item2->discard_changes->update( { copynumber => '34567890' } );
1831
        $item3->discard_changes->update( { copynumber => '23456789' } );
1832
        is_deeply( [ map { $_->itemnumber } $biblio->items->search_ordered->as_list ],
1833
            [ $item1->itemnumber, $item3->itemnumber, $item2->itemnumber ],
1834
            "not a serial - order by LPAD( me.copynumber, 8, '0' )" );
1835
1836
        # order_by -desc => 'me.dateaccessioned'
1827
        # order_by -desc => 'me.dateaccessioned'
1837
        $biblio->items->update( { copynumber => undef } );
1828
        $biblio->items->update( { enumchron => undef } );
1838
        $item1->discard_changes->update( { dateaccessioned => '2022-08-19' } );
1829
        $item1->discard_changes->update( { dateaccessioned => '2022-08-19' } );
1839
        $item2->discard_changes->update( { dateaccessioned => '2022-07-19' } );
1830
        $item2->discard_changes->update( { dateaccessioned => '2022-07-19' } );
1840
        $item3->discard_changes->update( { dateaccessioned => '2022-09-19' } );
1831
        $item3->discard_changes->update( { dateaccessioned => '2022-09-19' } );
1841
- 

Return to bug 33568