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

(-)a/Koha/BackgroundJob/BatchAddDisplayItems.pm (+4 lines)
Lines 64-69 sub process { Link Here
64
64
65
    my $display_id  = $args->{display_id};
65
    my $display_id  = $args->{display_id};
66
    my @barcodes    = @{ $args->{barcodes} };
66
    my @barcodes    = @{ $args->{barcodes} };
67
    my $date_added  = $args->{date_added};
67
    my $date_remove = $args->{date_remove};
68
    my $date_remove = $args->{date_remove};
68
69
69
    my $report = {
70
    my $report = {
Lines 140-145 sub process { Link Here
140
                            display_id   => $display_id,
141
                            display_id   => $display_id,
141
                            itemnumber   => $itemnumber,
142
                            itemnumber   => $itemnumber,
142
                            biblionumber => $item->biblionumber,
143
                            biblionumber => $item->biblionumber,
144
                            date_added   => $date_added,
143
                            date_remove  => $date_remove,
145
                            date_remove  => $date_remove,
144
                        }
146
                        }
145
                    )->store;
147
                    )->store;
Lines 190-195 sub enqueue { Link Here
190
192
191
    my @barcodes    = @{ $args->{barcodes} };
193
    my @barcodes    = @{ $args->{barcodes} };
192
    my $display_id  = $args->{display_id};
194
    my $display_id  = $args->{display_id};
195
    my $date_added  = $args->{date_added};
193
    my $date_remove = $args->{date_remove};
196
    my $date_remove = $args->{date_remove};
194
197
195
    $self->SUPER::enqueue(
198
    $self->SUPER::enqueue(
Lines 198-203 sub enqueue { Link Here
198
            job_args => {
201
            job_args => {
199
                display_id  => $display_id,
202
                display_id  => $display_id,
200
                barcodes    => \@barcodes,
203
                barcodes    => \@barcodes,
204
                date_added  => $date_added,
201
                date_remove => $date_remove,
205
                date_remove => $date_remove,
202
            },
206
            },
203
            job_queue => 'long_tasks',
207
            job_queue => 'long_tasks',
(-)a/Koha/Display.pm (-13 / +24 lines)
Lines 24-29 use Carp; Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Log qw( logaction );
25
use C4::Log qw( logaction );
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::Displays;
28
use Koha::Displays;
28
use Koha::DisplayItems;
29
use Koha::DisplayItems;
29
use Koha::Library;
30
use Koha::Library;
Lines 73-78 sub display_items { Link Here
73
                                display_id   => $self->display_id,
74
                                display_id   => $self->display_id,
74
                                itemnumber   => $new_item->{itemnumber},
75
                                itemnumber   => $new_item->{itemnumber},
75
                                biblionumber => $new_item->{biblionumber},
76
                                biblionumber => $new_item->{biblionumber},
77
                                date_added   => $new_item->{date_added},
76
                                date_remove  => $new_item->{date_remove},
78
                                date_remove  => $new_item->{date_remove},
77
                            }
79
                            }
78
                        )->store;
80
                        )->store;
Lines 141-168 Overloaded store method to add action logging. Link Here
141
143
142
sub store {
144
sub store {
143
    my ($self) = @_;
145
    my ($self) = @_;
146
    my $action = $self->in_storage ? 'update' : 'create';
144
147
145
    my $action   = $self->in_storage ? 'update'                                  : 'create';
148
    if ( $action eq 'create' ) {
146
    my $original = $self->in_storage ? Koha::Displays->find( $self->display_id ) : undef;
149
        if ( !$self->start_date ) {
147
150
            my $dt = dt_from_string();
148
    my $enabled_before = $original ? $original->enabled : undef;
151
            $self->start_date( $dt->ymd );
149
    my $enabled_after  = $self->enabled;
152
        }
150
153
151
    my $result = $self->SUPER::store;
154
        if ( !$self->end_date && $self->display_days ) {
155
            my $dt = dt_from_string();
156
            $dt->add( days => $self->display_days );
157
            $self->end_date( $dt->ymd );
158
        }
152
159
153
    if ( C4::Context->preference("DisplayItemsLog") ) {
160
        logaction( "DISPLAYS", "CREATE", $self->display_id, undef, undef, $self )
154
        if ( $action eq 'create' ) {
161
            if ( C4::Context->preference("DisplayItemsLog") );
155
            logaction( "DISPLAYS", "CREATE", $self->display_id, undef, undef, $self );
162
    } else {
156
        } else {
163
        if ( C4::Context->preference("DisplayItemsLog") ) {
157
            logaction( "DISPLAYS", "MODIFY", $self->display_id, $self, undef, $original );
164
            my $original       = $self->in_storage ? Koha::Displays->find( $self->display_id ) : undef;
165
            my $enabled_before = $original         ? $original->enabled                        : undef;
166
            my $enabled_after  = $self->enabled;
158
167
159
            if ( defined $enabled_before && defined $enabled_after && $enabled_before != $enabled_after ) {
168
            if ( defined $enabled_before && defined $enabled_after && $enabled_before != $enabled_after ) {
160
                my $enable_action = $enabled_after ? "ENABLE" : "DISABLE";
169
                my $enable_action = $enabled_after ? "ENABLE" : "DISABLE";
161
                logaction( "DISPLAYS", $enable_action, $self->display_id, undef, undef, $self );
170
                logaction( "DISPLAYS", $enable_action, $self->display_id, undef, undef, $self );
162
            }
171
            }
172
173
            logaction( "DISPLAYS", "MODIFY", $self->display_id, $self, undef, $original );
163
        }
174
        }
164
    }
175
    }
165
176
177
    my $result = $self->SUPER::store;
166
    return $result;
178
    return $result;
167
}
179
}
168
180
Lines 177-187 Overloaded delete method to add action logging. Link Here
177
sub delete {
189
sub delete {
178
    my ($self) = @_;
190
    my ($self) = @_;
179
191
180
    my $result = $self->SUPER::delete;
181
182
    logaction( "DISPLAYS", "DELETE", $self->display_id, undef, undef, $self )
192
    logaction( "DISPLAYS", "DELETE", $self->display_id, undef, undef, $self )
183
        if C4::Context->preference("DisplayItemsLog");
193
        if C4::Context->preference("DisplayItemsLog");
184
194
195
    my $result = $self->SUPER::delete;
185
    return $result;
196
    return $result;
186
}
197
}
187
198
(-)a/Koha/DisplayItem.pm (-14 / +16 lines)
Lines 95-118 Overloaded store method to add action logging. Link Here
95
95
96
sub store {
96
sub store {
97
    my ($self) = @_;
97
    my ($self) = @_;
98
99
    my $action = $self->in_storage ? 'update' : 'create';
98
    my $action = $self->in_storage ? 'update' : 'create';
100
99
101
    if ( $action eq 'create' && !$self->date_remove ) {
100
    if ( $action eq 'create' ) {
102
        my $display = $self->display;
101
        my $display = $self->display;
103
        if ( $display && $display->display_days ) {
102
        my $item    = $self->item;
103
104
        return if ( $item->active_display && !$self->date_added );
105
106
        if ( !$self->date_added ) {
107
            my $dt = dt_from_string();
108
            $self->date_added( $dt->ymd );
109
        }
110
111
        if ( !$self->date_remove && $display && $display->display_days ) {
104
            my $dt = dt_from_string();
112
            my $dt = dt_from_string();
105
            $dt->add( days => $display->display_days );
113
            $dt->add( days => $display->display_days );
106
            $self->date_remove( $dt->ymd );
114
            $self->date_remove( $dt->ymd );
107
        }
115
        }
108
    }
109
116
110
    my $result = $self->SUPER::store;
117
        logaction( "DISPLAYS", "ADD_ITEM", $self->display_id, "Item " . $self->itemnumber, undef, $self )
111
118
            if C4::Context->preference("DisplayItemsLog");
112
    if ( C4::Context->preference("DisplayItemsLog") && $action eq 'create' ) {
113
        logaction( "DISPLAYS", "ADD_ITEM", $self->display_id, "Item " . $self->itemnumber, undef, $self );
114
    }
119
    }
115
120
121
    my $result = $self->SUPER::store;
116
    return $result;
122
    return $result;
117
}
123
}
118
124
Lines 127-140 Overloaded delete method to add action logging. Link Here
127
sub delete {
133
sub delete {
128
    my ($self) = @_;
134
    my ($self) = @_;
129
135
130
    my $display_id = $self->display_id;
136
    logaction( "DISPLAYS", "REMOVE_ITEM", $self->display_id, "Item " . $self->itemnumber, undef, $self )
131
    my $itemnumber = $self->itemnumber;
132
133
    my $result = $self->SUPER::delete;
134
135
    logaction( "DISPLAYS", "REMOVE_ITEM", $display_id, "Item " . $itemnumber, undef, $self )
136
        if C4::Context->preference("DisplayItemsLog");
137
        if C4::Context->preference("DisplayItemsLog");
137
138
139
    my $result = $self->SUPER::delete;
138
    return $result;
140
    return $result;
139
}
141
}
140
142
(-)a/Koha/Item.pm (-12 / +19 lines)
Lines 420-426 sub effective_itemtype { Link Here
420
    my ($self) = @_;
420
    my ($self) = @_;
421
421
422
    if ( my $display = $self->active_display ) {
422
    if ( my $display = $self->active_display ) {
423
        return $display->get_column('display_itype') || $self->_result()->effective_itemtype();
423
        return $display->display_itype || $self->_result()->effective_itemtype();
424
    }
424
    }
425
425
426
    return $self->_result()->effective_itemtype();
426
    return $self->_result()->effective_itemtype();
Lines 806-812 sub active_display_item { Link Here
806
    my $dtf   = Koha::Database->new->schema->storage->datetime_parser;
806
    my $dtf   = Koha::Database->new->schema->storage->datetime_parser;
807
    my $today = dt_from_string();
807
    my $today = dt_from_string();
808
808
809
    my $display_item = Koha::DisplayItems->search(
809
    my $display_items = Koha::DisplayItems->search(
810
        {
810
        {
811
            itemnumber        => $self->itemnumber,
811
            itemnumber        => $self->itemnumber,
812
            'display.enabled' => 1,
812
            'display.enabled' => 1,
Lines 826-834 sub active_display_item { Link Here
826
            ]
826
            ]
827
        },
827
        },
828
        { join => 'display' }
828
        { join => 'display' }
829
    )->next;
829
    );
830
830
831
    return $display_item;
831
    if ( my $display_item = $display_items->next ) {
832
        return $display_item;
833
    }
834
835
    return;
832
}
836
}
833
837
834
=head3 request_transfer
838
=head3 request_transfer
Lines 2300-2309 sub effective_homebranch { Link Here
2300
    my ($self) = @_;
2304
    my ($self) = @_;
2301
2305
2302
    if ( my $display = $self->active_display ) {
2306
    if ( my $display = $self->active_display ) {
2303
        return $display->get_column('display_branch') || $self->homebranch;
2307
        return $display->display_branch || $self->homebranch;
2304
    }
2308
    }
2305
2309
2306
    return $self->get_column('homebranch');
2310
    return $self->homebranch;
2307
}
2311
}
2308
2312
2309
=head3 effective_holding_library
2313
=head3 effective_holding_library
Lines 2337-2346 sub effective_holdingbranch { Link Here
2337
    my ($self) = @_;
2341
    my ($self) = @_;
2338
2342
2339
    if ( my $display = $self->active_display ) {
2343
    if ( my $display = $self->active_display ) {
2340
        return $display->get_column('display_holding_branch') || $self->holdingbranch;
2344
        return $display->display_holding_branch || $self->holdingbranch;
2341
    }
2345
    }
2342
2346
2343
    return $self->get_column('holdingbranch');
2347
    return $self->holdingbranch;
2344
}
2348
}
2345
2349
2346
=head3 active_display
2350
=head3 active_display
Lines 2363-2370 sub active_display { Link Here
2363
2367
2364
    return unless C4::Context->preference('UseDisplayModule');
2368
    return unless C4::Context->preference('UseDisplayModule');
2365
2369
2366
    my $display_item_rs = $self->_result->display_items(
2370
    my $display_item = Koha::DisplayItems->search(
2367
        {
2371
        {
2372
            itemnumber        => $self->itemnumber,
2368
            'display.enabled' => 1,
2373
            'display.enabled' => 1,
2369
            '-or'             => [
2374
            '-or'             => [
2370
                'display.start_date' => { '<=', \'CURDATE()' },
2375
                'display.start_date' => { '<=', \'CURDATE()' },
Lines 2385-2394 sub active_display { Link Here
2385
            join     => 'display',
2390
            join     => 'display',
2386
            order_by => { -desc => 'date_added' }
2391
            order_by => { -desc => 'date_added' }
2387
        }
2392
        }
2388
    );
2393
    )->next;
2394
2395
    return unless $display_item;
2389
2396
2390
    if ( my $display_item = $display_item_rs->first ) {
2397
    if ( my $display = $display_item->display ) {
2391
        return $display_item->display;
2398
        return $display;
2392
    }
2399
    }
2393
2400
2394
    return;
2401
    return;
(-)a/api/v1/swagger/definitions/item.yaml (+5 lines)
Lines 24-29 properties: Link Here
24
      - string
24
      - string
25
      - "null"
25
      - "null"
26
    description: Information about the acquisition source (it is not really a vendor id)
26
    description: Information about the acquisition source (it is not really a vendor id)
27
  active_display:
28
    type:
29
      - object
30
      - "null"
31
    description: The active display, if one is available
27
  bookable:
32
  bookable:
28
    type:
33
    type:
29
      - boolean
34
      - boolean
(-)a/api/v1/swagger/paths/items.yaml (+3 lines)
Lines 21-26 Link Here
21
          type: string
21
          type: string
22
          enum:
22
          enum:
23
            - +strings
23
            - +strings
24
            - active_display
24
            - biblio
25
            - biblio
25
            - effective_bookable
26
            - effective_bookable
26
        collectionFormat: csv
27
        collectionFormat: csv
Lines 89-94 Link Here
89
          type: string
90
          type: string
90
          enum:
91
          enum:
91
            - +strings
92
            - +strings
93
            - active_display
94
            - biblio
92
            - effective_bookable
95
            - effective_bookable
93
        collectionFormat: csv
96
        collectionFormat: csv
94
    consumes:
97
    consumes:
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/item-api-client.js (+8 lines)
Lines 17-22 export class ItemAPIClient { Link Here
17
            get: id =>
17
            get: id =>
18
                this.httpClient.get({
18
                this.httpClient.get({
19
                    endpoint: "items/" + id,
19
                    endpoint: "items/" + id,
20
                    headers: {
21
                        "x-koha-embed":
22
                            "+strings,active_display,biblio,effective_bookable",
23
                    },
20
                }),
24
                }),
21
            getByExternalId: external_id =>
25
            getByExternalId: external_id =>
22
                this.httpClient.get({
26
                this.httpClient.get({
Lines 26-31 export class ItemAPIClient { Link Here
26
                            _match: "starts_with",
30
                            _match: "starts_with",
27
                            external_id: external_id,
31
                            external_id: external_id,
28
                        }),
32
                        }),
33
                    headers: {
34
                        "x-koha-embed":
35
                            "+strings,active_display,biblio,effective_bookable",
36
                    },
29
                }),
37
                }),
30
        };
38
        };
31
    }
39
    }
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Display/DisplaysResource.vue (-15 / +16 lines)
Lines 422-431 export default { Link Here
422
                    item == undefined ||
422
                    item == undefined ||
423
                    item.item_id === undefined ||
423
                    item.item_id === undefined ||
424
                    item.external_id !== display_item.barcode
424
                    item.external_id !== display_item.barcode
425
                )
425
                ) {
426
                    errors.push(
426
                    errors.push(
427
                        $__("The barcode entered does not match an item")
427
                        $__("The barcode entered does not match an item")
428
                    );
428
                    );
429
                }
430
431
                if (
432
                    item.active_display &&
433
                    display_item.date_added == undefined
434
                ) {
435
                    errors.push(
436
                        $__(
437
                            "The item entered is already on another active display. Set a date added for this item, or remove the item from the other display."
438
                        )
439
                    );
440
                }
429
            }
441
            }
430
442
431
            baseResource.setWarning(errors.join("<br>"));
443
            baseResource.setWarning(errors.join("<br>"));
Lines 467-485 export default { Link Here
467
                await display.display_items.push(display_item);
479
                await display.display_items.push(display_item);
468
            }
480
            }
469
481
470
            if (display.start_date == null)
482
            Object.entries(display).forEach(([key, value]) => {
471
                display.start_date = epoch.toISOString().substr(0, 10);
483
                if (value == "") display[key] = null;
472
            if (display.end_date == null && display.display_days != undefined) {
484
            });
473
                let calculated_date = epoch;
474
                calculated_date.setDate(
475
                    epoch.getDate() + Number(display.display_days)
476
                );
477
478
                display.end_date = calculated_date.toISOString().substr(0, 10);
479
            }
480
            if (display.display_days == "") display.display_days = null;
481
            if (display.public_note == "") display.public_note = null;
482
            if (display.staff_note == "") display.staff_note = null;
483
485
484
            if (displayId) {
486
            if (displayId) {
485
                baseResource.apiClient.update(display, displayId).then(
487
                baseResource.apiClient.update(display, displayId).then(
486
- 

Return to bug 14962