Bug 4461: dbic schema update
[koha.git] / Koha / Schema / Result / Item.pm
blob58cddf45021ef1c527050c7d48b761d8c288c0c3
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 is_nullable: 1
164 =head2 renewals
166 data_type: 'smallint'
167 is_nullable: 1
169 =head2 reserves
171 data_type: 'smallint'
172 is_nullable: 1
174 =head2 restricted
176 data_type: 'tinyint'
177 is_nullable: 1
179 =head2 itemnotes
181 data_type: 'longtext'
182 is_nullable: 1
184 =head2 itemnotes_nonpublic
186 data_type: 'longtext'
187 is_nullable: 1
189 =head2 holdingbranch
191 data_type: 'varchar'
192 is_foreign_key: 1
193 is_nullable: 1
194 size: 10
196 =head2 paidfor
198 data_type: 'longtext'
199 is_nullable: 1
201 =head2 timestamp
203 data_type: 'timestamp'
204 datetime_undef_if_invalid: 1
205 default_value: current_timestamp
206 is_nullable: 0
208 =head2 location
210 data_type: 'varchar'
211 is_nullable: 1
212 size: 80
214 =head2 permanent_location
216 data_type: 'varchar'
217 is_nullable: 1
218 size: 80
220 =head2 onloan
222 data_type: 'date'
223 datetime_undef_if_invalid: 1
224 is_nullable: 1
226 =head2 cn_source
228 data_type: 'varchar'
229 is_nullable: 1
230 size: 10
232 =head2 cn_sort
234 data_type: 'varchar'
235 is_nullable: 1
236 size: 255
238 =head2 ccode
240 data_type: 'varchar'
241 is_nullable: 1
242 size: 80
244 =head2 materials
246 data_type: 'mediumtext'
247 is_nullable: 1
249 =head2 uri
251 data_type: 'mediumtext'
252 is_nullable: 1
254 =head2 itype
256 data_type: 'varchar'
257 is_nullable: 1
258 size: 10
260 =head2 more_subfields_xml
262 data_type: 'longtext'
263 is_nullable: 1
265 =head2 enumchron
267 data_type: 'mediumtext'
268 is_nullable: 1
270 =head2 copynumber
272 data_type: 'varchar'
273 is_nullable: 1
274 size: 32
276 =head2 stocknumber
278 data_type: 'varchar'
279 is_nullable: 1
280 size: 32
282 =head2 new_status
284 data_type: 'varchar'
285 is_nullable: 1
286 size: 32
288 =cut
290 __PACKAGE__->add_columns(
291 "itemnumber",
292 { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
293 "biblionumber",
295 data_type => "integer",
296 default_value => 0,
297 is_foreign_key => 1,
298 is_nullable => 0,
300 "biblioitemnumber",
302 data_type => "integer",
303 default_value => 0,
304 is_foreign_key => 1,
305 is_nullable => 0,
307 "barcode",
308 { data_type => "varchar", is_nullable => 1, size => 20 },
309 "dateaccessioned",
310 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
311 "booksellerid",
312 { data_type => "longtext", is_nullable => 1 },
313 "homebranch",
314 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
315 "price",
316 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
317 "replacementprice",
318 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
319 "replacementpricedate",
320 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
321 "datelastborrowed",
322 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
323 "datelastseen",
324 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
325 "stack",
326 { data_type => "tinyint", is_nullable => 1 },
327 "notforloan",
328 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
329 "damaged",
330 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
331 "damaged_on",
333 data_type => "datetime",
334 datetime_undef_if_invalid => 1,
335 is_nullable => 1,
337 "itemlost",
338 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
339 "itemlost_on",
341 data_type => "datetime",
342 datetime_undef_if_invalid => 1,
343 is_nullable => 1,
345 "withdrawn",
346 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
347 "withdrawn_on",
349 data_type => "datetime",
350 datetime_undef_if_invalid => 1,
351 is_nullable => 1,
353 "itemcallnumber",
354 { data_type => "varchar", is_nullable => 1, size => 255 },
355 "coded_location_qualifier",
356 { data_type => "varchar", is_nullable => 1, size => 10 },
357 "issues",
358 { data_type => "smallint", is_nullable => 1 },
359 "renewals",
360 { data_type => "smallint", is_nullable => 1 },
361 "reserves",
362 { data_type => "smallint", is_nullable => 1 },
363 "restricted",
364 { data_type => "tinyint", is_nullable => 1 },
365 "itemnotes",
366 { data_type => "longtext", is_nullable => 1 },
367 "itemnotes_nonpublic",
368 { data_type => "longtext", is_nullable => 1 },
369 "holdingbranch",
370 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
371 "paidfor",
372 { data_type => "longtext", is_nullable => 1 },
373 "timestamp",
375 data_type => "timestamp",
376 datetime_undef_if_invalid => 1,
377 default_value => \"current_timestamp",
378 is_nullable => 0,
380 "location",
381 { data_type => "varchar", is_nullable => 1, size => 80 },
382 "permanent_location",
383 { data_type => "varchar", is_nullable => 1, size => 80 },
384 "onloan",
385 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
386 "cn_source",
387 { data_type => "varchar", is_nullable => 1, size => 10 },
388 "cn_sort",
389 { data_type => "varchar", is_nullable => 1, size => 255 },
390 "ccode",
391 { data_type => "varchar", is_nullable => 1, size => 80 },
392 "materials",
393 { data_type => "mediumtext", is_nullable => 1 },
394 "uri",
395 { data_type => "mediumtext", is_nullable => 1 },
396 "itype",
397 { data_type => "varchar", is_nullable => 1, size => 10 },
398 "more_subfields_xml",
399 { data_type => "longtext", is_nullable => 1 },
400 "enumchron",
401 { data_type => "mediumtext", is_nullable => 1 },
402 "copynumber",
403 { data_type => "varchar", is_nullable => 1, size => 32 },
404 "stocknumber",
405 { data_type => "varchar", is_nullable => 1, size => 32 },
406 "new_status",
407 { data_type => "varchar", is_nullable => 1, size => 32 },
410 =head1 PRIMARY KEY
412 =over 4
414 =item * L</itemnumber>
416 =back
418 =cut
420 __PACKAGE__->set_primary_key("itemnumber");
422 =head1 UNIQUE CONSTRAINTS
424 =head2 C<itembarcodeidx>
426 =over 4
428 =item * L</barcode>
430 =back
432 =cut
434 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
436 =head1 RELATIONS
438 =head2 accountlines
440 Type: has_many
442 Related object: L<Koha::Schema::Result::Accountline>
444 =cut
446 __PACKAGE__->has_many(
447 "accountlines",
448 "Koha::Schema::Result::Accountline",
449 { "foreign.itemnumber" => "self.itemnumber" },
450 { cascade_copy => 0, cascade_delete => 0 },
453 =head2 article_requests
455 Type: has_many
457 Related object: L<Koha::Schema::Result::ArticleRequest>
459 =cut
461 __PACKAGE__->has_many(
462 "article_requests",
463 "Koha::Schema::Result::ArticleRequest",
464 { "foreign.itemnumber" => "self.itemnumber" },
465 { cascade_copy => 0, cascade_delete => 0 },
468 =head2 biblioitemnumber
470 Type: belongs_to
472 Related object: L<Koha::Schema::Result::Biblioitem>
474 =cut
476 __PACKAGE__->belongs_to(
477 "biblioitemnumber",
478 "Koha::Schema::Result::Biblioitem",
479 { biblioitemnumber => "biblioitemnumber" },
480 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
483 =head2 biblionumber
485 Type: belongs_to
487 Related object: L<Koha::Schema::Result::Biblio>
489 =cut
491 __PACKAGE__->belongs_to(
492 "biblionumber",
493 "Koha::Schema::Result::Biblio",
494 { biblionumber => "biblionumber" },
495 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
498 =head2 branchtransfers
500 Type: has_many
502 Related object: L<Koha::Schema::Result::Branchtransfer>
504 =cut
506 __PACKAGE__->has_many(
507 "branchtransfers",
508 "Koha::Schema::Result::Branchtransfer",
509 { "foreign.itemnumber" => "self.itemnumber" },
510 { cascade_copy => 0, cascade_delete => 0 },
513 =head2 club_holds
515 Type: has_many
517 Related object: L<Koha::Schema::Result::ClubHold>
519 =cut
521 __PACKAGE__->has_many(
522 "club_holds",
523 "Koha::Schema::Result::ClubHold",
524 { "foreign.item_id" => "self.itemnumber" },
525 { cascade_copy => 0, cascade_delete => 0 },
528 =head2 course_item
530 Type: might_have
532 Related object: L<Koha::Schema::Result::CourseItem>
534 =cut
536 __PACKAGE__->might_have(
537 "course_item",
538 "Koha::Schema::Result::CourseItem",
539 { "foreign.itemnumber" => "self.itemnumber" },
540 { cascade_copy => 0, cascade_delete => 0 },
543 =head2 creator_batches
545 Type: has_many
547 Related object: L<Koha::Schema::Result::CreatorBatch>
549 =cut
551 __PACKAGE__->has_many(
552 "creator_batches",
553 "Koha::Schema::Result::CreatorBatch",
554 { "foreign.item_number" => "self.itemnumber" },
555 { cascade_copy => 0, cascade_delete => 0 },
558 =head2 hold_fill_target
560 Type: might_have
562 Related object: L<Koha::Schema::Result::HoldFillTarget>
564 =cut
566 __PACKAGE__->might_have(
567 "hold_fill_target",
568 "Koha::Schema::Result::HoldFillTarget",
569 { "foreign.itemnumber" => "self.itemnumber" },
570 { cascade_copy => 0, cascade_delete => 0 },
573 =head2 holdingbranch
575 Type: belongs_to
577 Related object: L<Koha::Schema::Result::Branch>
579 =cut
581 __PACKAGE__->belongs_to(
582 "holdingbranch",
583 "Koha::Schema::Result::Branch",
584 { branchcode => "holdingbranch" },
586 is_deferrable => 1,
587 join_type => "LEFT",
588 on_delete => "RESTRICT",
589 on_update => "CASCADE",
593 =head2 homebranch
595 Type: belongs_to
597 Related object: L<Koha::Schema::Result::Branch>
599 =cut
601 __PACKAGE__->belongs_to(
602 "homebranch",
603 "Koha::Schema::Result::Branch",
604 { branchcode => "homebranch" },
606 is_deferrable => 1,
607 join_type => "LEFT",
608 on_delete => "RESTRICT",
609 on_update => "CASCADE",
613 =head2 issue
615 Type: might_have
617 Related object: L<Koha::Schema::Result::Issue>
619 =cut
621 __PACKAGE__->might_have(
622 "issue",
623 "Koha::Schema::Result::Issue",
624 { "foreign.itemnumber" => "self.itemnumber" },
625 { cascade_copy => 0, cascade_delete => 0 },
628 =head2 items_last_borrower
630 Type: might_have
632 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
634 =cut
636 __PACKAGE__->might_have(
637 "items_last_borrower",
638 "Koha::Schema::Result::ItemsLastBorrower",
639 { "foreign.itemnumber" => "self.itemnumber" },
640 { cascade_copy => 0, cascade_delete => 0 },
643 =head2 old_issues
645 Type: has_many
647 Related object: L<Koha::Schema::Result::OldIssue>
649 =cut
651 __PACKAGE__->has_many(
652 "old_issues",
653 "Koha::Schema::Result::OldIssue",
654 { "foreign.itemnumber" => "self.itemnumber" },
655 { cascade_copy => 0, cascade_delete => 0 },
658 =head2 old_reserves
660 Type: has_many
662 Related object: L<Koha::Schema::Result::OldReserve>
664 =cut
666 __PACKAGE__->has_many(
667 "old_reserves",
668 "Koha::Schema::Result::OldReserve",
669 { "foreign.itemnumber" => "self.itemnumber" },
670 { cascade_copy => 0, cascade_delete => 0 },
673 =head2 reserves
675 Type: has_many
677 Related object: L<Koha::Schema::Result::Reserve>
679 =cut
681 __PACKAGE__->has_many(
682 "reserves",
683 "Koha::Schema::Result::Reserve",
684 { "foreign.itemnumber" => "self.itemnumber" },
685 { cascade_copy => 0, cascade_delete => 0 },
688 =head2 return_claims
690 Type: has_many
692 Related object: L<Koha::Schema::Result::ReturnClaim>
694 =cut
696 __PACKAGE__->has_many(
697 "return_claims",
698 "Koha::Schema::Result::ReturnClaim",
699 { "foreign.itemnumber" => "self.itemnumber" },
700 { cascade_copy => 0, cascade_delete => 0 },
703 =head2 serialitem
705 Type: might_have
707 Related object: L<Koha::Schema::Result::Serialitem>
709 =cut
711 __PACKAGE__->might_have(
712 "serialitem",
713 "Koha::Schema::Result::Serialitem",
714 { "foreign.itemnumber" => "self.itemnumber" },
715 { cascade_copy => 0, cascade_delete => 0 },
718 =head2 stockrotationitem
720 Type: might_have
722 Related object: L<Koha::Schema::Result::Stockrotationitem>
724 =cut
726 __PACKAGE__->might_have(
727 "stockrotationitem",
728 "Koha::Schema::Result::Stockrotationitem",
729 { "foreign.itemnumber_id" => "self.itemnumber" },
730 { cascade_copy => 0, cascade_delete => 0 },
733 =head2 tmp_holdsqueues
735 Type: has_many
737 Related object: L<Koha::Schema::Result::TmpHoldsqueue>
739 =cut
741 __PACKAGE__->has_many(
742 "tmp_holdsqueues",
743 "Koha::Schema::Result::TmpHoldsqueue",
744 { "foreign.itemnumber" => "self.itemnumber" },
745 { cascade_copy => 0, cascade_delete => 0 },
749 # Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-02-17 10:42:24
750 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CcrMhgq+PQ1MHV6jZEN8wA
752 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
754 __PACKAGE__->belongs_to(
755 "biblio",
756 "Koha::Schema::Result::Biblio",
757 { biblionumber => "biblionumber" },
758 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
761 use C4::Context;
762 sub effective_itemtype {
763 my ( $self ) = @_;
765 my $pref = C4::Context->preference('item-level_itypes');
766 if ( $pref && $self->itype() ) {
767 return $self->itype();
768 } else {
769 warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
770 if $pref;
771 return $self->biblioitemnumber()->itemtype();