Bug 24986: DBIC Schema files + fix of bug 23081 backport
[koha.git] / Koha / Schema / Result / Item.pm
blobc4c63181f934f33c85b85c29af8cfa6ebe432e7f
1 use utf8;
2 package Koha::Schema::Result::Item;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
7 =head1 NAME
9 Koha::Schema::Result::Item
11 =cut
13 use strict;
14 use warnings;
16 use base 'DBIx::Class::Core';
18 =head1 TABLE: C<items>
20 =cut
22 __PACKAGE__->table("items");
24 =head1 ACCESSORS
26 =head2 itemnumber
28 data_type: 'integer'
29 is_auto_increment: 1
30 is_nullable: 0
32 =head2 biblionumber
34 data_type: 'integer'
35 default_value: 0
36 is_foreign_key: 1
37 is_nullable: 0
39 =head2 biblioitemnumber
41 data_type: 'integer'
42 default_value: 0
43 is_foreign_key: 1
44 is_nullable: 0
46 =head2 barcode
48 data_type: 'varchar'
49 is_nullable: 1
50 size: 20
52 =head2 dateaccessioned
54 data_type: 'date'
55 datetime_undef_if_invalid: 1
56 is_nullable: 1
58 =head2 booksellerid
60 data_type: 'longtext'
61 is_nullable: 1
63 =head2 homebranch
65 data_type: 'varchar'
66 is_foreign_key: 1
67 is_nullable: 1
68 size: 10
70 =head2 price
72 data_type: 'decimal'
73 is_nullable: 1
74 size: [8,2]
76 =head2 replacementprice
78 data_type: 'decimal'
79 is_nullable: 1
80 size: [8,2]
82 =head2 replacementpricedate
84 data_type: 'date'
85 datetime_undef_if_invalid: 1
86 is_nullable: 1
88 =head2 datelastborrowed
90 data_type: 'date'
91 datetime_undef_if_invalid: 1
92 is_nullable: 1
94 =head2 datelastseen
96 data_type: 'date'
97 datetime_undef_if_invalid: 1
98 is_nullable: 1
100 =head2 stack
102 data_type: 'tinyint'
103 is_nullable: 1
105 =head2 notforloan
107 data_type: 'tinyint'
108 default_value: 0
109 is_nullable: 0
111 =head2 damaged
113 data_type: 'tinyint'
114 default_value: 0
115 is_nullable: 0
117 =head2 damaged_on
119 data_type: 'datetime'
120 datetime_undef_if_invalid: 1
121 is_nullable: 1
123 =head2 itemlost
125 data_type: 'tinyint'
126 default_value: 0
127 is_nullable: 0
129 =head2 itemlost_on
131 data_type: 'datetime'
132 datetime_undef_if_invalid: 1
133 is_nullable: 1
135 =head2 withdrawn
137 data_type: 'tinyint'
138 default_value: 0
139 is_nullable: 0
141 =head2 withdrawn_on
143 data_type: 'datetime'
144 datetime_undef_if_invalid: 1
145 is_nullable: 1
147 =head2 itemcallnumber
149 data_type: 'varchar'
150 is_nullable: 1
151 size: 255
153 =head2 coded_location_qualifier
155 data_type: 'varchar'
156 is_nullable: 1
157 size: 10
159 =head2 issues
161 data_type: 'smallint'
162 default_value: 0
163 is_nullable: 1
165 =head2 renewals
167 data_type: 'smallint'
168 is_nullable: 1
170 =head2 reserves
172 data_type: 'smallint'
173 is_nullable: 1
175 =head2 restricted
177 data_type: 'tinyint'
178 is_nullable: 1
180 =head2 itemnotes
182 data_type: 'longtext'
183 is_nullable: 1
185 =head2 itemnotes_nonpublic
187 data_type: 'longtext'
188 is_nullable: 1
190 =head2 holdingbranch
192 data_type: 'varchar'
193 is_foreign_key: 1
194 is_nullable: 1
195 size: 10
197 =head2 paidfor
199 data_type: 'longtext'
200 is_nullable: 1
202 =head2 timestamp
204 data_type: 'timestamp'
205 datetime_undef_if_invalid: 1
206 default_value: current_timestamp
207 is_nullable: 0
209 =head2 location
211 data_type: 'varchar'
212 is_nullable: 1
213 size: 80
215 =head2 permanent_location
217 data_type: 'varchar'
218 is_nullable: 1
219 size: 80
221 =head2 onloan
223 data_type: 'date'
224 datetime_undef_if_invalid: 1
225 is_nullable: 1
227 =head2 cn_source
229 data_type: 'varchar'
230 is_nullable: 1
231 size: 10
233 =head2 cn_sort
235 data_type: 'varchar'
236 is_nullable: 1
237 size: 255
239 =head2 ccode
241 data_type: 'varchar'
242 is_nullable: 1
243 size: 80
245 =head2 materials
247 data_type: 'mediumtext'
248 is_nullable: 1
250 =head2 uri
252 data_type: 'mediumtext'
253 is_nullable: 1
255 =head2 itype
257 data_type: 'varchar'
258 is_nullable: 1
259 size: 10
261 =head2 more_subfields_xml
263 data_type: 'longtext'
264 is_nullable: 1
266 =head2 enumchron
268 data_type: 'mediumtext'
269 is_nullable: 1
271 =head2 copynumber
273 data_type: 'varchar'
274 is_nullable: 1
275 size: 32
277 =head2 stocknumber
279 data_type: 'varchar'
280 is_nullable: 1
281 size: 32
283 =head2 new_status
285 data_type: 'varchar'
286 is_nullable: 1
287 size: 32
289 =cut
291 __PACKAGE__->add_columns(
292 "itemnumber",
293 { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
294 "biblionumber",
296 data_type => "integer",
297 default_value => 0,
298 is_foreign_key => 1,
299 is_nullable => 0,
301 "biblioitemnumber",
303 data_type => "integer",
304 default_value => 0,
305 is_foreign_key => 1,
306 is_nullable => 0,
308 "barcode",
309 { data_type => "varchar", is_nullable => 1, size => 20 },
310 "dateaccessioned",
311 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
312 "booksellerid",
313 { data_type => "longtext", is_nullable => 1 },
314 "homebranch",
315 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
316 "price",
317 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
318 "replacementprice",
319 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
320 "replacementpricedate",
321 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
322 "datelastborrowed",
323 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
324 "datelastseen",
325 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
326 "stack",
327 { data_type => "tinyint", is_nullable => 1 },
328 "notforloan",
329 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
330 "damaged",
331 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
332 "damaged_on",
334 data_type => "datetime",
335 datetime_undef_if_invalid => 1,
336 is_nullable => 1,
338 "itemlost",
339 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
340 "itemlost_on",
342 data_type => "datetime",
343 datetime_undef_if_invalid => 1,
344 is_nullable => 1,
346 "withdrawn",
347 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
348 "withdrawn_on",
350 data_type => "datetime",
351 datetime_undef_if_invalid => 1,
352 is_nullable => 1,
354 "itemcallnumber",
355 { data_type => "varchar", is_nullable => 1, size => 255 },
356 "coded_location_qualifier",
357 { data_type => "varchar", is_nullable => 1, size => 10 },
358 "issues",
359 { data_type => "smallint", default_value => 0, is_nullable => 1 },
360 "renewals",
361 { data_type => "smallint", is_nullable => 1 },
362 "reserves",
363 { data_type => "smallint", is_nullable => 1 },
364 "restricted",
365 { data_type => "tinyint", is_nullable => 1 },
366 "itemnotes",
367 { data_type => "longtext", is_nullable => 1 },
368 "itemnotes_nonpublic",
369 { data_type => "longtext", is_nullable => 1 },
370 "holdingbranch",
371 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
372 "paidfor",
373 { data_type => "longtext", is_nullable => 1 },
374 "timestamp",
376 data_type => "timestamp",
377 datetime_undef_if_invalid => 1,
378 default_value => \"current_timestamp",
379 is_nullable => 0,
381 "location",
382 { data_type => "varchar", is_nullable => 1, size => 80 },
383 "permanent_location",
384 { data_type => "varchar", is_nullable => 1, size => 80 },
385 "onloan",
386 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
387 "cn_source",
388 { data_type => "varchar", is_nullable => 1, size => 10 },
389 "cn_sort",
390 { data_type => "varchar", is_nullable => 1, size => 255 },
391 "ccode",
392 { data_type => "varchar", is_nullable => 1, size => 80 },
393 "materials",
394 { data_type => "mediumtext", is_nullable => 1 },
395 "uri",
396 { data_type => "mediumtext", is_nullable => 1 },
397 "itype",
398 { data_type => "varchar", is_nullable => 1, size => 10 },
399 "more_subfields_xml",
400 { data_type => "longtext", is_nullable => 1 },
401 "enumchron",
402 { data_type => "mediumtext", is_nullable => 1 },
403 "copynumber",
404 { data_type => "varchar", is_nullable => 1, size => 32 },
405 "stocknumber",
406 { data_type => "varchar", is_nullable => 1, size => 32 },
407 "new_status",
408 { data_type => "varchar", is_nullable => 1, size => 32 },
411 =head1 PRIMARY KEY
413 =over 4
415 =item * L</itemnumber>
417 =back
419 =cut
421 __PACKAGE__->set_primary_key("itemnumber");
423 =head1 UNIQUE CONSTRAINTS
425 =head2 C<itembarcodeidx>
427 =over 4
429 =item * L</barcode>
431 =back
433 =cut
435 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
437 =head1 RELATIONS
439 =head2 accountlines
441 Type: has_many
443 Related object: L<Koha::Schema::Result::Accountline>
445 =cut
447 __PACKAGE__->has_many(
448 "accountlines",
449 "Koha::Schema::Result::Accountline",
450 { "foreign.itemnumber" => "self.itemnumber" },
451 { cascade_copy => 0, cascade_delete => 0 },
454 =head2 article_requests
456 Type: has_many
458 Related object: L<Koha::Schema::Result::ArticleRequest>
460 =cut
462 __PACKAGE__->has_many(
463 "article_requests",
464 "Koha::Schema::Result::ArticleRequest",
465 { "foreign.itemnumber" => "self.itemnumber" },
466 { cascade_copy => 0, cascade_delete => 0 },
469 =head2 biblioitemnumber
471 Type: belongs_to
473 Related object: L<Koha::Schema::Result::Biblioitem>
475 =cut
477 __PACKAGE__->belongs_to(
478 "biblioitemnumber",
479 "Koha::Schema::Result::Biblioitem",
480 { biblioitemnumber => "biblioitemnumber" },
481 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
484 =head2 biblionumber
486 Type: belongs_to
488 Related object: L<Koha::Schema::Result::Biblio>
490 =cut
492 __PACKAGE__->belongs_to(
493 "biblionumber",
494 "Koha::Schema::Result::Biblio",
495 { biblionumber => "biblionumber" },
496 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
499 =head2 branchtransfers
501 Type: has_many
503 Related object: L<Koha::Schema::Result::Branchtransfer>
505 =cut
507 __PACKAGE__->has_many(
508 "branchtransfers",
509 "Koha::Schema::Result::Branchtransfer",
510 { "foreign.itemnumber" => "self.itemnumber" },
511 { cascade_copy => 0, cascade_delete => 0 },
514 =head2 course_item
516 Type: might_have
518 Related object: L<Koha::Schema::Result::CourseItem>
520 =cut
522 __PACKAGE__->might_have(
523 "course_item",
524 "Koha::Schema::Result::CourseItem",
525 { "foreign.itemnumber" => "self.itemnumber" },
526 { cascade_copy => 0, cascade_delete => 0 },
529 =head2 creator_batches
531 Type: has_many
533 Related object: L<Koha::Schema::Result::CreatorBatch>
535 =cut
537 __PACKAGE__->has_many(
538 "creator_batches",
539 "Koha::Schema::Result::CreatorBatch",
540 { "foreign.item_number" => "self.itemnumber" },
541 { cascade_copy => 0, cascade_delete => 0 },
544 =head2 hold_fill_target
546 Type: might_have
548 Related object: L<Koha::Schema::Result::HoldFillTarget>
550 =cut
552 __PACKAGE__->might_have(
553 "hold_fill_target",
554 "Koha::Schema::Result::HoldFillTarget",
555 { "foreign.itemnumber" => "self.itemnumber" },
556 { cascade_copy => 0, cascade_delete => 0 },
559 =head2 holdingbranch
561 Type: belongs_to
563 Related object: L<Koha::Schema::Result::Branch>
565 =cut
567 __PACKAGE__->belongs_to(
568 "holdingbranch",
569 "Koha::Schema::Result::Branch",
570 { branchcode => "holdingbranch" },
572 is_deferrable => 1,
573 join_type => "LEFT",
574 on_delete => "RESTRICT",
575 on_update => "CASCADE",
579 =head2 homebranch
581 Type: belongs_to
583 Related object: L<Koha::Schema::Result::Branch>
585 =cut
587 __PACKAGE__->belongs_to(
588 "homebranch",
589 "Koha::Schema::Result::Branch",
590 { branchcode => "homebranch" },
592 is_deferrable => 1,
593 join_type => "LEFT",
594 on_delete => "RESTRICT",
595 on_update => "CASCADE",
599 =head2 issue
601 Type: might_have
603 Related object: L<Koha::Schema::Result::Issue>
605 =cut
607 __PACKAGE__->might_have(
608 "issue",
609 "Koha::Schema::Result::Issue",
610 { "foreign.itemnumber" => "self.itemnumber" },
611 { cascade_copy => 0, cascade_delete => 0 },
614 =head2 items_last_borrower
616 Type: might_have
618 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
620 =cut
622 __PACKAGE__->might_have(
623 "items_last_borrower",
624 "Koha::Schema::Result::ItemsLastBorrower",
625 { "foreign.itemnumber" => "self.itemnumber" },
626 { cascade_copy => 0, cascade_delete => 0 },
629 =head2 old_issues
631 Type: has_many
633 Related object: L<Koha::Schema::Result::OldIssue>
635 =cut
637 __PACKAGE__->has_many(
638 "old_issues",
639 "Koha::Schema::Result::OldIssue",
640 { "foreign.itemnumber" => "self.itemnumber" },
641 { cascade_copy => 0, cascade_delete => 0 },
644 =head2 old_reserves
646 Type: has_many
648 Related object: L<Koha::Schema::Result::OldReserve>
650 =cut
652 __PACKAGE__->has_many(
653 "old_reserves",
654 "Koha::Schema::Result::OldReserve",
655 { "foreign.itemnumber" => "self.itemnumber" },
656 { cascade_copy => 0, cascade_delete => 0 },
659 =head2 reserves
661 Type: has_many
663 Related object: L<Koha::Schema::Result::Reserve>
665 =cut
667 __PACKAGE__->has_many(
668 "reserves",
669 "Koha::Schema::Result::Reserve",
670 { "foreign.itemnumber" => "self.itemnumber" },
671 { cascade_copy => 0, cascade_delete => 0 },
674 =head2 serialitem
676 Type: might_have
678 Related object: L<Koha::Schema::Result::Serialitem>
680 =cut
682 __PACKAGE__->might_have(
683 "serialitem",
684 "Koha::Schema::Result::Serialitem",
685 { "foreign.itemnumber" => "self.itemnumber" },
686 { cascade_copy => 0, cascade_delete => 0 },
689 =head2 stockrotationitem
691 Type: might_have
693 Related object: L<Koha::Schema::Result::Stockrotationitem>
695 =cut
697 __PACKAGE__->might_have(
698 "stockrotationitem",
699 "Koha::Schema::Result::Stockrotationitem",
700 { "foreign.itemnumber_id" => "self.itemnumber" },
701 { cascade_copy => 0, cascade_delete => 0 },
704 =head2 tmp_holdsqueues
706 Type: has_many
708 Related object: L<Koha::Schema::Result::TmpHoldsqueue>
710 =cut
712 __PACKAGE__->has_many(
713 "tmp_holdsqueues",
714 "Koha::Schema::Result::TmpHoldsqueue",
715 { "foreign.itemnumber" => "self.itemnumber" },
716 { cascade_copy => 0, cascade_delete => 0 },
720 # Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-07-22 19:19:25
721 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gv53TABUmPU/oeRI88Eomg
723 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
725 __PACKAGE__->belongs_to(
726 "biblio",
727 "Koha::Schema::Result::Biblio",
728 { biblionumber => "biblionumber" },
729 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
732 use C4::Context;
733 sub effective_itemtype {
734 my ( $self ) = @_;
736 my $pref = C4::Context->preference('item-level_itypes');
737 if ( $pref && $self->itype() ) {
738 return $self->itype();
739 } else {
740 warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
741 if $pref;
742 return $self->biblioitemnumber()->itemtype();