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

(-)a/C4/Items.pm (+6 lines)
Lines 1586-1591 sub PrepareItemrecordDisplay { Link Here
1586
    # its contents. See also GetMarcStructure.
1586
    # its contents. See also GetMarcStructure.
1587
    my $tagslib = GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
1587
    my $tagslib = GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
1588
1588
1589
    # Pick the default location from NewItemsDefaultLocation
1590
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
1591
        $defaultvalues //= {};
1592
        $defaultvalues->{location} //= C4::Context->preference('NewItemsDefaultLocation');
1593
    }
1594
1589
    # return nothing if we don't have found an existing framework.
1595
    # return nothing if we don't have found an existing framework.
1590
    return q{} unless $tagslib;
1596
    return q{} unless $tagslib;
1591
    my $itemrecord;
1597
    my $itemrecord;
(-)a/Koha/Item.pm (+8 lines)
Lines 93-101 sub store { Link Here
93
    my $action = 'create';
93
    my $action = 'create';
94
94
95
    unless ( $self->in_storage ) { #AddItem
95
    unless ( $self->in_storage ) { #AddItem
96
96
        unless ( $self->permanent_location ) {
97
        unless ( $self->permanent_location ) {
97
            $self->permanent_location($self->location);
98
            $self->permanent_location($self->location);
98
        }
99
        }
100
101
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
102
        if ( $default_location ) {
103
            $self->permanent_location( $self->location ); # FIXME To confirm - even if passed?
104
            $self->location($default_location);
105
        }
106
99
        unless ( $self->replacementpricedate ) {
107
        unless ( $self->replacementpricedate ) {
100
            $self->replacementpricedate($today);
108
            $self->replacementpricedate($today);
101
        }
109
        }
(-)a/cataloguing/additem.pl (-16 / +5 lines)
Lines 74-93 sub get_item_from_barcode { Link Here
74
    return($result);
74
    return($result);
75
}
75
}
76
76
77
sub set_item_default_location {
78
    my $itemnumber = shift;
79
    my $item       = Koha::Items->find($itemnumber);
80
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
81
        $item->permanent_location($item->location);
82
        $item->location(C4::Context->preference('NewItemsDefaultLocation'));
83
    }
84
    else {
85
        # It seems that we are dealing with that in too many places
86
        $item->permanent_location($item->location) unless defined $item->permanent_location;
87
    }
88
    $item->store;
89
}
90
91
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
77
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
92
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
78
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
93
sub _increment_barcode {
79
sub _increment_barcode {
Lines 165-170 sub generate_subfield_form { Link Here
165
            }
151
            }
166
        }
152
        }
167
153
154
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
155
        if ( !$value && $subfieldlib->{kohafield} eq 'items.location' && $default_location ) {
156
            $value = $default_location;
157
        }
158
168
        if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
159
        if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
169
	    my $input = CGI->new;
160
	    my $input = CGI->new;
170
	    $value = $input->param('barcode');
161
	    $value = $input->param('barcode');
Lines 527-533 if ($op eq "additem") { Link Here
527
        # if barcode exists, don't create, but report The problem.
518
        # if barcode exists, don't create, but report The problem.
528
        unless ($exist_itemnumber) {
519
        unless ($exist_itemnumber) {
529
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
520
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
530
            set_item_default_location($oldbibitemnum);
531
521
532
            # Pushing the last created item cookie back
522
            # Pushing the last created item cookie back
533
            if ($prefillitem && defined $record) {
523
            if ($prefillitem && defined $record) {
Lines 627-633 if ($op eq "additem") { Link Here
627
        if (!$exist_itemnumber) {
617
        if (!$exist_itemnumber) {
628
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) =
618
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) =
629
                AddItemFromMarc( $record, $biblionumber, { skip_record_index => 1 } );
619
                AddItemFromMarc( $record, $biblionumber, { skip_record_index => 1 } );
630
            set_item_default_location($oldbibitemnum);
631
620
632
            # We count the item only if it was really added
621
            # We count the item only if it was really added
633
            # That way, all items are added, even if there was some already existing barcodes
622
            # That way, all items are added, even if there was some already existing barcodes
(-)a/t/db_dependent/Koha/Items.t (-3 / +61 lines)
Lines 89-98 subtest 'store' => sub { Link Here
89
        $biblio->biblioitem->itemtype,
89
        $biblio->biblioitem->itemtype,
90
        'items.itype must have been set to biblioitem.itemtype is not given'
90
        'items.itype must have been set to biblioitem.itemtype is not given'
91
    );
91
    );
92
    is( $item->permanent_location, $item->location,
93
        'permanent_location must have been set to location if not given' );
94
    $item->delete;
92
    $item->delete;
95
93
94
    subtest 'permanent_location' => sub {
95
        plan tests => 7;
96
97
        my $location = 'my_loc';
98
        my $attributes = {
99
            homebranch    => $library->{branchcode},
100
            holdingbranch => $library->{branchcode},
101
            biblionumber  => $biblio->biblionumber,
102
            location      => $location,
103
        };
104
105
        {
106
            # NewItemsDefaultLocation not set
107
            t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', '' );
108
109
            # Not passing permanent_location on creating the item
110
            my $item = Koha::Item->new($attributes)->store->get_from_storage;
111
            is( $item->location, $location,
112
                'location must have been set to location if given' );
113
            is( $item->permanent_location, $item->location,
114
                'permanent_location must have been set to location if not given' );
115
            $item->delete;
116
117
            # Passing permanent_location on creating the item
118
            $item = Koha::Item->new(
119
                { %$attributes, permanent_location => 'perm_loc' } )
120
              ->store->get_from_storage;
121
            is( $item->permanent_location, 'perm_loc',
122
                'permanent_location must have been kept if given' );
123
            $item->delete;
124
        }
125
126
        {
127
            # NewItemsDefaultLocation set
128
            my $default_location = 'default_location';
129
            t::lib::Mocks::mock_preference( 'NewItemsDefaultLocation', $default_location );
130
131
            # Not passing permanent_location on creating the item
132
            my $item = Koha::Item->new($attributes)->store->get_from_storage;
133
            is( $item->location, $default_location,
134
                'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
135
            );
136
            is( $item->permanent_location, $location,
137
                'permanent_location must have been set to the location given' );
138
            $item->delete;
139
140
            # Passing permanent_location on creating the item
141
            $item = Koha::Item->new(
142
                { %$attributes, permanent_location => 'perm_loc' } )
143
              ->store->get_from_storage;
144
            is( $item->location, $default_location,
145
                'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
146
            );
147
            is( $item->permanent_location, $location,
148
                'permanent_location must have been set to the location given'
149
            );
150
            $item->delete;
151
        }
152
153
    };
154
96
    subtest '*_on updates' => sub {
155
    subtest '*_on updates' => sub {
97
        plan tests => 9;
156
        plan tests => 9;
98
157
99
- 

Return to bug 27545