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

(-)a/C4/Items.pm (+6 lines)
Lines 1602-1607 sub PrepareItemrecordDisplay { Link Here
1602
    # its contents. See also GetMarcStructure.
1602
    # its contents. See also GetMarcStructure.
1603
    my $tagslib = GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
1603
    my $tagslib = GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
1604
1604
1605
    # Pick the default location from NewItemsDefaultLocation
1606
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
1607
        $defaultvalues //= {};
1608
        $defaultvalues->{location} //= C4::Context->preference('NewItemsDefaultLocation');
1609
    }
1610
1605
    # return nothing if we don't have found an existing framework.
1611
    # return nothing if we don't have found an existing framework.
1606
    return q{} unless $tagslib;
1612
    return q{} unless $tagslib;
1607
    my $itemrecord;
1613
    my $itemrecord;
(-)a/Koha/Item.pm (+8 lines)
Lines 94-102 sub store { Link Here
94
    my $action = 'create';
94
    my $action = 'create';
95
95
96
    unless ( $self->in_storage ) { #AddItem
96
    unless ( $self->in_storage ) { #AddItem
97
97
        unless ( $self->permanent_location ) {
98
        unless ( $self->permanent_location ) {
98
            $self->permanent_location($self->location);
99
            $self->permanent_location($self->location);
99
        }
100
        }
101
102
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
103
        if ( $default_location ) {
104
            $self->permanent_location( $self->location ); # FIXME To confirm - even if passed?
105
            $self->location($default_location);
106
        }
107
100
        unless ( $self->replacementpricedate ) {
108
        unless ( $self->replacementpricedate ) {
101
            $self->replacementpricedate($today);
109
            $self->replacementpricedate($today);
102
        }
110
        }
(-)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 166-171 sub generate_subfield_form { Link Here
166
            }
152
            }
167
        }
153
        }
168
154
155
        my $default_location = C4::Context->preference('NewItemsDefaultLocation');
156
        if ( !$value && $subfieldlib->{kohafield} eq 'items.location' && $default_location ) {
157
            $value = $default_location;
158
        }
159
169
        if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
160
        if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
170
	    my $input = CGI->new;
161
	    my $input = CGI->new;
171
	    $value = $input->param('barcode');
162
	    $value = $input->param('barcode');
Lines 528-534 if ($op eq "additem") { Link Here
528
        # if barcode exists, don't create, but report The problem.
519
        # if barcode exists, don't create, but report The problem.
529
        unless ($exist_itemnumber) {
520
        unless ($exist_itemnumber) {
530
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
521
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
531
            set_item_default_location($oldbibitemnum);
532
522
533
            # Pushing the last created item cookie back
523
            # Pushing the last created item cookie back
534
            if ($prefillitem && defined $record) {
524
            if ($prefillitem && defined $record) {
Lines 628-634 if ($op eq "additem") { Link Here
628
        if (!$exist_itemnumber) {
618
        if (!$exist_itemnumber) {
629
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) =
619
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) =
630
                AddItemFromMarc( $record, $biblionumber, { skip_record_index => 1 } );
620
                AddItemFromMarc( $record, $biblionumber, { skip_record_index => 1 } );
631
            set_item_default_location($oldbibitemnum);
632
621
633
            # We count the item only if it was really added
622
            # We count the item only if it was really added
634
            # That way, all items are added, even if there was some already existing barcodes
623
            # 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