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

(-)a/Koha/Item.pm (-6 / +2 lines)
Lines 964-975 sub columns_to_str { Link Here
964
964
965
        next if $column eq 'more_subfields_xml';
965
        next if $column eq 'more_subfields_xml';
966
966
967
        my $value;
967
        my $value = $self->$column;
968
        if ( Koha::Object::_datetime_column_type( $columns_info->{$column}->{data_type} ) ) {
968
        # Maybe we need to deal with datetime columns here, but so far we have damaged_on, itemlost_on and withdrawn_on, and they are not linked with kohafield
969
            $value = output_pref({ dateformat => 'rfc3339', dt => dt_from_string($value, 'sql')});
970
        } else {
971
            $value = $self->$column;
972
        }
973
969
974
        if ( not defined $value or $value eq "" ) {
970
        if ( not defined $value or $value eq "" ) {
975
            $values->{$column} = $value;
971
            $values->{$column} = $value;
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +41 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 14;
20
use Test::More tests => 15;
21
21
22
use C4::Biblio qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
23
use Koha::Database;
23
use Koha::Database;
Lines 637-639 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
637
637
638
    $schema->storage->txn_rollback;
638
    $schema->storage->txn_rollback;
639
};
639
};
640
641
subtest 'host_items' => sub {
642
    plan tests => 6;
643
644
    $schema->storage->txn_begin;
645
646
    my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } );
647
648
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
649
    my $host_items = $biblio->host_items;
650
    is( ref($host_items),   'Koha::Items' );
651
    is( $host_items->count, 0 );
652
653
    my $item_1 =
654
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
655
    my $host_item_1 = $builder->build_sample_item;
656
    my $host_item_2 = $builder->build_sample_item;
657
658
    my $record = $biblio->metadata->record;
659
    $record->append_fields(
660
        MARC::Field->new(
661
            '773', '', '',
662
            9 => $host_item_1->itemnumber,
663
            9 => $host_item_2->itemnumber
664
        ),
665
    );
666
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
667
    $biblio = $biblio->get_from_storage;
668
    $host_items = $biblio->host_items;
669
    is( $host_items->count, 2 );
670
    is_deeply( [ $host_items->get_column('itemnumber') ],
671
        [ $host_item_1->itemnumber, $host_item_2->itemnumber ] );
672
673
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
674
    $host_items = $biblio->host_items;
675
    is( ref($host_items),   'Koha::Items' );
676
    is( $host_items->count, 0 );
677
678
    $schema->storage->txn_rollback;
679
};
(-)a/t/db_dependent/Koha/Item.t (-2 / +99 lines)
Lines 18-30 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
22
22
use Test::More tests => 9;
23
use Test::More tests => 10;
23
use Test::Exception;
24
use Test::Exception;
24
25
25
use C4::Biblio qw( GetMarcSubfieldStructure );
26
use C4::Biblio qw( GetMarcSubfieldStructure );
26
use C4::Circulation qw( AddIssue AddReturn );
27
use C4::Circulation qw( AddIssue AddReturn );
27
28
29
use Koha::Caches;
28
use Koha::Items;
30
use Koha::Items;
29
use Koha::Database;
31
use Koha::Database;
30
use Koha::DateUtils;
32
use Koha::DateUtils;
Lines 816-818 subtest 'get_transfers' => sub { Link Here
816
818
817
    $schema->storage->txn_rollback;
819
    $schema->storage->txn_rollback;
818
};
820
};
819
- 
821
822
subtest 'columns_to_str' => sub {
823
    plan tests => 4;
824
825
    $schema->storage->txn_begin;
826
827
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
828
829
    my $cache = Koha::Caches->get_instance();
830
    $cache->clear_from_cache("MarcStructure-0-");
831
    $cache->clear_from_cache("MarcStructure-1-");
832
    $cache->clear_from_cache("default_value_for_mod_marc-");
833
    $cache->clear_from_cache("MarcSubfieldStructure-");
834
835
    # Creating subfields 'é', 'è' that are not linked with a kohafield
836
    Koha::MarcSubfieldStructures->search(
837
        {
838
            frameworkcode => '',
839
            tagfield => $itemtag,
840
            tagsubfield => ['é', 'è'],
841
        }
842
    )->delete;    # In case it exist already
843
844
    # é is not linked with a AV
845
    # è is linked with AV branches
846
    Koha::MarcSubfieldStructure->new(
847
        {
848
            frameworkcode => '',
849
            tagfield      => $itemtag,
850
            tagsubfield   => 'é',
851
            kohafield     => undef,
852
            repeatable    => 1,
853
            defaultvalue  => 'ééé',
854
            tab           => 10,
855
        }
856
    )->store;
857
    Koha::MarcSubfieldStructure->new(
858
        {
859
            frameworkcode    => '',
860
            tagfield         => $itemtag,
861
            tagsubfield      => 'è',
862
            kohafield        => undef,
863
            repeatable       => 1,
864
            defaultvalue     => 'èèè',
865
            tab              => 10,
866
            authorised_value => 'branches',
867
        }
868
    )->store;
869
870
    my $biblio = $builder->build_sample_biblio({ frameworkcode => '' });
871
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
872
    my $itemlost = Koha::AuthorisedValues->search({ category => 'LOST' })->next->authorised_value;
873
    my $dateaccessioned = '2020-12-15';
874
    my $library = Koha::Libraries->search->next;
875
    my $branchcode = $library->branchcode;
876
877
    my $some_marc_xml = qq{<?xml version="1.0" encoding="UTF-8"?>
878
<collection
879
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
880
  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
881
  xmlns="http://www.loc.gov/MARC21/slim">
882
883
<record>
884
  <leader>         a              </leader>
885
  <datafield tag="999" ind1=" " ind2=" ">
886
    <subfield code="é">value é</subfield>
887
    <subfield code="è">$branchcode</subfield>
888
  </datafield>
889
</record>
890
891
</collection>};
892
893
    $item->update(
894
        {
895
            itemlost           => $itemlost,
896
            dateaccessioned    => $dateaccessioned,
897
            more_subfields_xml => $some_marc_xml,
898
        }
899
    );
900
901
    $item = $item->get_from_storage;
902
903
    my $s = $item->columns_to_str;
904
    is( $s->{itemlost}, 'Lost' );
905
    is( $s->{dateaccessioned}, '2020-12-15');
906
    is( $s->{é}, 'value é');
907
    is( $s->{è}, $library->branchname );
908
909
    $cache->clear_from_cache("MarcStructure-0-");
910
    $cache->clear_from_cache("MarcStructure-1-");
911
    $cache->clear_from_cache("default_value_for_mod_marc-");
912
    $cache->clear_from_cache("MarcSubfieldStructure-");
913
914
    $schema->storage->txn_rollback;
915
916
};

Return to bug 27526