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

(-)a/Koha/Item.pm (-6 / +2 lines)
Lines 965-976 sub columns_to_str { Link Here
965
965
966
        next if $column eq 'more_subfields_xml';
966
        next if $column eq 'more_subfields_xml';
967
967
968
        my $value;
968
        my $value = $self->$column;
969
        if ( Koha::Object::_datetime_column_type( $columns_info->{$column}->{data_type} ) ) {
969
        # 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
970
            $value = output_pref({ dateformat => 'rfc3339', dt => dt_from_string($value, 'sql')});
971
        } else {
972
            $value = $self->$column;
973
        }
974
970
975
        if ( not defined $value or $value eq "" ) {
971
        if ( not defined $value or $value eq "" ) {
976
            $values->{$column} = $value;
972
            $values->{$column} = $value;
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +38 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
    my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } );
645
646
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
647
    my $host_items = $biblio->host_items;
648
    is( ref($host_items),   'Koha::Items' );
649
    is( $host_items->count, 0 );
650
651
    my $item_1 =
652
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
653
    my $host_item_1 = $builder->build_sample_item;
654
    my $host_item_2 = $builder->build_sample_item;
655
656
    my $record = $biblio->metadata->record;
657
    $record->append_fields(
658
        MARC::Field->new(
659
            '773', '', '',
660
            9 => $host_item_1->itemnumber,
661
            9 => $host_item_2->itemnumber
662
        ),
663
    );
664
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
665
    $biblio = $biblio->get_from_storage;
666
    $host_items = $biblio->host_items;
667
    is( $host_items->count, 2 );
668
    is_deeply( [ $host_items->get_column('itemnumber') ],
669
        [ $host_item_1->itemnumber, $host_item_2->itemnumber ] );
670
671
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
672
    $host_items = $biblio->host_items;
673
    is( ref($host_items),   'Koha::Items' );
674
    is( $host_items->count, 0 );
675
676
};
(-)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 => 12;
23
use Test::More tests => 13;
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 1050-1052 subtest 'move_to_biblio() tests' => sub { Link Here
1050
1052
1051
    $schema->storage->txn_rollback;
1053
    $schema->storage->txn_rollback;
1052
};
1054
};
1053
- 
1055
1056
subtest 'columns_to_str' => sub {
1057
    plan tests => 4;
1058
1059
    $schema->storage->txn_begin;
1060
1061
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
1062
1063
    my $cache = Koha::Caches->get_instance();
1064
    $cache->clear_from_cache("MarcStructure-0-");
1065
    $cache->clear_from_cache("MarcStructure-1-");
1066
    $cache->clear_from_cache("default_value_for_mod_marc-");
1067
    $cache->clear_from_cache("MarcSubfieldStructure-");
1068
1069
    # Creating subfields 'é', 'è' that are not linked with a kohafield
1070
    Koha::MarcSubfieldStructures->search(
1071
        {
1072
            frameworkcode => '',
1073
            tagfield => $itemtag,
1074
            tagsubfield => ['é', 'è'],
1075
        }
1076
    )->delete;    # In case it exist already
1077
1078
    # é is not linked with a AV
1079
    # è is linked with AV branches
1080
    Koha::MarcSubfieldStructure->new(
1081
        {
1082
            frameworkcode => '',
1083
            tagfield      => $itemtag,
1084
            tagsubfield   => 'é',
1085
            kohafield     => undef,
1086
            repeatable    => 1,
1087
            defaultvalue  => 'ééé',
1088
            tab           => 10,
1089
        }
1090
    )->store;
1091
    Koha::MarcSubfieldStructure->new(
1092
        {
1093
            frameworkcode    => '',
1094
            tagfield         => $itemtag,
1095
            tagsubfield      => 'è',
1096
            kohafield        => undef,
1097
            repeatable       => 1,
1098
            defaultvalue     => 'èèè',
1099
            tab              => 10,
1100
            authorised_value => 'branches',
1101
        }
1102
    )->store;
1103
1104
    my $biblio = $builder->build_sample_biblio({ frameworkcode => '' });
1105
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
1106
    my $itemlost = Koha::AuthorisedValues->search({ category => 'LOST' })->next->authorised_value;
1107
    my $dateaccessioned = '2020-12-15';
1108
    my $library = Koha::Libraries->search->next;
1109
    my $branchcode = $library->branchcode;
1110
1111
    my $some_marc_xml = qq{<?xml version="1.0" encoding="UTF-8"?>
1112
<collection
1113
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1114
  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
1115
  xmlns="http://www.loc.gov/MARC21/slim">
1116
1117
<record>
1118
  <leader>         a              </leader>
1119
  <datafield tag="999" ind1=" " ind2=" ">
1120
    <subfield code="é">value é</subfield>
1121
    <subfield code="è">$branchcode</subfield>
1122
  </datafield>
1123
</record>
1124
1125
</collection>};
1126
1127
    $item->update(
1128
        {
1129
            itemlost           => $itemlost,
1130
            dateaccessioned    => $dateaccessioned,
1131
            more_subfields_xml => $some_marc_xml,
1132
        }
1133
    );
1134
1135
    $item = $item->get_from_storage;
1136
1137
    my $s = $item->columns_to_str;
1138
    is( $s->{itemlost}, 'Lost' );
1139
    is( $s->{dateaccessioned}, '2020-12-15');
1140
    is( $s->{é}, 'value é');
1141
    is( $s->{è}, $library->branchname );
1142
1143
    $cache->clear_from_cache("MarcStructure-0-");
1144
    $cache->clear_from_cache("MarcStructure-1-");
1145
    $cache->clear_from_cache("default_value_for_mod_marc-");
1146
    $cache->clear_from_cache("MarcSubfieldStructure-");
1147
1148
    $schema->storage->txn_rollback;
1149
1150
};

Return to bug 27526