From 620a46304ce8b291c90b2fa79981059d015ec63f Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 7 Jun 2017 16:59:17 +0200 Subject: [PATCH] Bug 18745: Serial claims: save supplier info on serial-level This allows to change the subscription's supplier while keeping the info of supplier for previous serials, which allows to claim late/missing serials to the right supplier Test plan: 1. Create 2 suppliers, S1 and S2 2. Create a new subscription with S1 3. Generate some late/missing serials 4. Change supplier to S2 5. Generate some more late/missing serials 6. Go to /cgi-bin/koha/serials/claims.pl and see you have late/missing issues for both suppliers 7. Check that you have the expected issues for each supplier 8. prove t/db_dependent/Serials/Claims.t --- C4/Serials.pm | 102 +++++++++++------- Koha/Schema/Result/AccountOffset.pm | 10 +- Koha/Schema/Result/AdditionalContent.pm | 28 ++--- Koha/Schema/Result/Aqbookseller.pm | 34 +++++- Koha/Schema/Result/Borrower.pm | 8 +- Koha/Schema/Result/BorrowerModification.pm | 6 +- Koha/Schema/Result/Branchtransfer.pm | 26 +++-- Koha/Schema/Result/CourseItem.pm | 8 +- Koha/Schema/Result/Deletedborrower.pm | 6 +- Koha/Schema/Result/LanguageDescription.pm | 22 +++- Koha/Schema/Result/LanguageRfc4646ToIso639.pm | 20 +++- Koha/Schema/Result/LanguageSubtagRegistry.pm | 20 +++- Koha/Schema/Result/Serial.pm | 32 +++++- Koha/Schema/Result/Subscription.pm | 30 ++++-- .../data/mysql/atomicupdate/bug_18745.perl | 29 +++++ installer/data/mysql/kohastructure.sql | 9 +- serials/subscription-add.pl | 4 +- t/db_dependent/Serials/Claims.t | 28 ++++- 18 files changed, 304 insertions(+), 118 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18745.perl diff --git a/C4/Serials.pm b/C4/Serials.pm index d840bf24b7..168fcd2efe 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -134,17 +134,17 @@ sub GetSuppliersWithLateIssues { my $dbh = C4::Context->dbh; my $statuses = join(',', ( LATE, MISSING_STATUSES, CLAIMED ) ); my $query = qq| - SELECT DISTINCT id, name - FROM subscription - LEFT JOIN serial ON serial.subscriptionid=subscription.subscriptionid - LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id - WHERE id > 0 - AND ( - (planneddate < now() AND serial.status=1) - OR serial.STATUS IN ( $statuses ) - ) - AND subscription.closed = 0 - ORDER BY name|; + SELECT DISTINCT aqbooksellers.id, aqbooksellers.name + FROM aqbooksellers + LEFT JOIN serial ON serial.aqbooksellerid = aqbooksellers.id + LEFT JOIN subscription ON serial.subscriptionid = subscription.subscriptionid + WHERE ( + (serial.planneddate < NOW() AND serial.status = 1) + OR serial.status IN ( $statuses ) + ) + AND subscription.closed = 0 + ORDER BY name + |; return $dbh->selectall_arrayref($query, { Slice => {} }); } @@ -1321,6 +1321,8 @@ sub ModSubscription { $itemtype, $previousitemtype, $mana_id ) = @_; + $aqbooksellerid ||= undef; + my $subscription = Koha::Subscriptions->find($subscriptionid); $subscription->set( { @@ -1402,6 +1404,8 @@ sub NewSubscription { ) = @_; my $dbh = C4::Context->dbh; + $aqbooksellerid ||= undef; + my $subscription = Koha::Subscription->new( { librarian => $auser, @@ -1480,6 +1484,7 @@ sub NewSubscription { serialseq_y => $subscription->{'lastvalue2'}, serialseq_z => $subscription->{'lastvalue3'}, subscriptionid => $subscriptionid, + aqbooksellerid => $subscription->{aqbooksellerid}, biblionumber => $biblionumber, status => EXPECTED, planneddate => $firstacquidate, @@ -1623,6 +1628,7 @@ sub NewIssue { serialseq_y => $subscription->lastvalue2(), serialseq_z => $subscription->lastvalue3(), subscriptionid => $subscriptionid, + aqbooksellerid => $subscription->aqbooksellerid(), biblionumber => $biblionumber, status => $status, planneddate => $planneddate, @@ -1848,7 +1854,7 @@ sub GetLateOrMissingIssues { my $sth; my $byserial = ''; if ($serialid) { - $byserial = "and serialid = " . $serialid; + $byserial = "and s.serialid = " . $serialid; } if ($order) { $order .= ", title"; @@ -1857,39 +1863,53 @@ sub GetLateOrMissingIssues { } my $missing_statuses_string = join ',', (MISSING_STATUSES); if ($supplierid) { - $sth = $dbh->prepare( - "SELECT - serialid, aqbooksellerid, name, - biblio.title, biblioitems.issn, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate, claims_count, + $sth = $dbh->prepare(qq{ + SELECT + s.serialid, s.aqbooksellerid, aqbooksellers.name, + biblio.title, biblioitems.issn, s.planneddate, s.serialseq, + s.status, s.subscriptionid, s.claimdate, s.claims_count, subscription.branchcode - FROM serial - LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid - LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber - LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.biblionumber - LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id - WHERE subscription.subscriptionid = serial.subscriptionid - AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS = ?) OR serial.STATUS = ? OR serial.STATUS = ?)) - AND subscription.aqbooksellerid=$supplierid - $byserial - ORDER BY $order" - ); + FROM serial s + LEFT JOIN subscription ON s.subscriptionid = subscription.subscriptionid + LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber + LEFT JOIN biblioitems ON subscription.biblionumber = biblioitems.biblionumber + LEFT JOIN aqbooksellers ON s.aqbooksellerid = aqbooksellers.id + WHERE + ( + s.status IN ($missing_statuses_string) + OR ( + (s.planneddate < NOW() AND s.status = ?) + OR s.status = ? + OR s.status = ? + ) + ) + AND s.aqbooksellerid = $supplierid + $byserial + ORDER BY $order + }); } else { - $sth = $dbh->prepare( - "SELECT - serialid, aqbooksellerid, name, - biblio.title, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate, claims_count, + $sth = $dbh->prepare(qq{ + SELECT + s.serialid, s.aqbooksellerid, aqbooksellers.name, + biblio.title, s.planneddate, s.serialseq, + s.status, s.subscriptionid, s.claimdate, s.claims_count, subscription.branchcode - FROM serial - LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid - LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber - LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id - WHERE subscription.subscriptionid = serial.subscriptionid - AND (serial.STATUS IN ($missing_statuses_string) OR ((planneddate < now() AND serial.STATUS = ?) OR serial.STATUS = ? OR serial.STATUS = ?)) + FROM serial s + LEFT JOIN subscription ON s.subscriptionid = subscription.subscriptionid + LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber + LEFT JOIN aqbooksellers ON s.aqbooksellerid = aqbooksellers.id + WHERE + ( + s.status IN ($missing_statuses_string) + OR ( + (s.planneddate < now() AND s.status = ?) + OR s.status = ? + OR s.status = ? + ) + ) $byserial - ORDER BY $order" - ); + ORDER BY $order + }); } $sth->execute( EXPECTED, LATE, CLAIMED ); my @issuelist; diff --git a/Koha/Schema/Result/AccountOffset.pm b/Koha/Schema/Result/AccountOffset.pm index 1b1e4bea09..81387eac3f 100644 --- a/Koha/Schema/Result/AccountOffset.pm +++ b/Koha/Schema/Result/AccountOffset.pm @@ -51,9 +51,7 @@ The id of the accountline that decreased the patron's balance data_type: 'enum' extra: {list => ["CREATE","APPLY","VOID","OVERDUE_INCREASE","OVERDUE_DECREASE"]} - is_nullable: 0 - -The type of offset this is + is_nullable: 1 =head2 amount @@ -91,7 +89,7 @@ __PACKAGE__->add_columns( "OVERDUE_DECREASE", ], }, - is_nullable => 0, + is_nullable => 1, }, "amount", { data_type => "decimal", is_nullable => 0, size => [26, 6] }, @@ -159,8 +157,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-06-21 15:27:32 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zCeE/SWvdz898zlfcvfRGg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vXNylpNHjCFtzZTeRy6MfA sub koha_object_class { 'Koha::Account::Offset'; diff --git a/Koha/Schema/Result/AdditionalContent.pm b/Koha/Schema/Result/AdditionalContent.pm index 080af4a169..d5ec88ca80 100644 --- a/Koha/Schema/Result/AdditionalContent.pm +++ b/Koha/Schema/Result/AdditionalContent.pm @@ -30,7 +30,7 @@ __PACKAGE__->table("additional_contents"); is_auto_increment: 1 is_nullable: 0 -unique identifier for the additional content +unique identifier for the news article =head2 category @@ -44,7 +44,7 @@ category for the additional content data_type: 'varchar' is_nullable: 0 - size: 20 + size: 100 code to group content per lang @@ -63,7 +63,7 @@ location of the additional content is_nullable: 1 size: 10 -branch code users to create branch specific additional content, NULL is every branch. +branch code users to create branch specific news, NULL is every branch. =head2 title @@ -72,23 +72,23 @@ branch code users to create branch specific additional content, NULL is every br is_nullable: 0 size: 250 -title of the additional content +title of the news article =head2 content data_type: 'mediumtext' is_nullable: 0 -the body of your additional content +the body of your news article =head2 lang data_type: 'varchar' default_value: (empty string) is_nullable: 0 - size: 25 + size: 50 -location for the additional content(koha is the staff interface, slip is the circulation receipt and language codes are for the opac) +location for the article (koha is the staff interface, slip is the circulation receipt and language codes are for the opac) =head2 published_on @@ -113,14 +113,14 @@ last modification datetime_undef_if_invalid: 1 is_nullable: 1 -date the additional content is set to expire or no longer be visible +date the article is set to expire or no longer be visible =head2 number data_type: 'integer' is_nullable: 1 -the order in which this additional content appears in that specific location +the order in which this article appears in that specific location =head2 borrowernumber @@ -128,7 +128,7 @@ the order in which this additional content appears in that specific location is_foreign_key: 1 is_nullable: 1 -The user who created the additional content +The user who created the news article =cut @@ -143,7 +143,7 @@ __PACKAGE__->add_columns( "category", { data_type => "varchar", is_nullable => 0, size => 20 }, "code", - { data_type => "varchar", is_nullable => 0, size => 20 }, + { data_type => "varchar", is_nullable => 0, size => 100 }, "location", { data_type => "varchar", is_nullable => 0, size => 255 }, "branchcode", @@ -153,7 +153,7 @@ __PACKAGE__->add_columns( "content", { data_type => "mediumtext", is_nullable => 0 }, "lang", - { data_type => "varchar", default_value => "", is_nullable => 0, size => 25 }, + { data_type => "varchar", default_value => "", is_nullable => 0, size => 50 }, "published_on", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "updated_on", @@ -249,8 +249,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-07-16 07:12:03 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0HtqQpArwFtGrsivukyG1Q +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qJR5e6KEWvkVqH0SQjXFGw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Aqbookseller.pm b/Koha/Schema/Result/Aqbookseller.pm index 4c5d19a0e2..4d0fdc1c9d 100644 --- a/Koha/Schema/Result/Aqbookseller.pm +++ b/Koha/Schema/Result/Aqbookseller.pm @@ -371,6 +371,36 @@ __PACKAGE__->belongs_to( }, ); +=head2 serials + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "serials", + "Koha::Schema::Result::Serial", + { "foreign.aqbooksellerid" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 subscriptions + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "subscriptions", + "Koha::Schema::Result::Subscription", + { "foreign.aqbooksellerid" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 vendor_edi_accounts Type: has_many @@ -387,8 +417,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qu4OqSCsEKEeJD9VtOEd4g +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iFntfA33lumUkMYAVyzfeA __PACKAGE__->add_columns( '+active' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 7a1db5dd46..a18e55ab7f 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -368,8 +368,6 @@ a note on the patron/borrower's account that is only visible in the staff interf is_nullable: 1 size: 100 -used for children to include the relationship to their guarantor - =head2 sex data_type: 'varchar' @@ -607,8 +605,6 @@ flag for allowing auto-renewal is_nullable: 1 size: 45 -useful for reporting purposes - =cut __PACKAGE__->add_columns( @@ -1890,8 +1886,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-27 08:42:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AyU2Z+V4O3ZWV8VhYqXyVg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EPudzl0z7jcJNjMV5QIeFw __PACKAGE__->add_columns( '+anonymized' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/BorrowerModification.pm b/Koha/Schema/Result/BorrowerModification.pm index 81c5fed1fe..50923291cb 100644 --- a/Koha/Schema/Result/BorrowerModification.pm +++ b/Koha/Schema/Result/BorrowerModification.pm @@ -429,8 +429,6 @@ data processing consent is_nullable: 1 size: 45 -useful for reporting purposes - =cut __PACKAGE__->add_columns( @@ -622,8 +620,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("verification_token", "borrowernumber"); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-07-12 13:40:00 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6giYT5URks8+6VnAs/rtkg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2qg6+X6LGQYIhmdI6W8Qqg sub koha_object_class { 'Koha::Patron::Modification'; diff --git a/Koha/Schema/Result/Branchtransfer.pm b/Koha/Schema/Result/Branchtransfer.pm index d8a64ca7bb..331f2af80f 100644 --- a/Koha/Schema/Result/Branchtransfer.pm +++ b/Koha/Schema/Result/Branchtransfer.pm @@ -100,21 +100,19 @@ the branch the transfer was going to any comments related to the transfer -=head2 reason +=head2 cancellation_reason data_type: 'enum' - extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","TransferCancellation"]} + extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","ItemLost","WrongTransfer"]} is_nullable: 1 -what triggered the transfer - -=head2 cancellation_reason +=head2 reason data_type: 'enum' - extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","ItemLost","WrongTransfer"]} + extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","TransferCancellation"]} is_nullable: 1 -what triggered the transfer cancellation +what triggered the transfer =cut @@ -171,7 +169,7 @@ __PACKAGE__->add_columns( }, "comments", { data_type => "longtext", is_nullable => 1 }, - "reason", + "cancellation_reason", { data_type => "enum", extra => { @@ -185,12 +183,13 @@ __PACKAGE__->add_columns( "Reserve", "LostReserve", "CancelReserve", - "TransferCancellation", + "ItemLost", + "WrongTransfer", ], }, is_nullable => 1, }, - "cancellation_reason", + "reason", { data_type => "enum", extra => { @@ -204,8 +203,7 @@ __PACKAGE__->add_columns( "Reserve", "LostReserve", "CancelReserve", - "ItemLost", - "WrongTransfer", + "TransferCancellation", ], }, is_nullable => 1, @@ -272,8 +270,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-06-08 08:13:08 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+ABUZOo6IHbiRH1LTy3t+A +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:eatBBQVEi1TjvAWr99KMqg sub koha_object_class { 'Koha::Item::Transfer'; diff --git a/Koha/Schema/Result/CourseItem.pm b/Koha/Schema/Result/CourseItem.pm index 53a62686e4..1c3aecf693 100644 --- a/Koha/Schema/Result/CourseItem.pm +++ b/Koha/Schema/Result/CourseItem.pm @@ -37,16 +37,12 @@ course item id is_foreign_key: 1 is_nullable: 1 -items.itemnumber for the item on reserve - =head2 biblionumber data_type: 'integer' is_foreign_key: 1 is_nullable: 0 -biblio.biblionumber for the bibliographic record on reserve - =head2 itype data_type: 'varchar' @@ -380,8 +376,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-06-11 18:35:38 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3fFJ3uJr+5pMZniZ1glIpg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:p8jX7J6nuARFwQkmWk98ZA __PACKAGE__->add_columns( '+itype_enabled' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/Deletedborrower.pm b/Koha/Schema/Result/Deletedborrower.pm index f0d7395d8d..e28d737b31 100644 --- a/Koha/Schema/Result/Deletedborrower.pm +++ b/Koha/Schema/Result/Deletedborrower.pm @@ -604,8 +604,6 @@ flag for allowing auto-renewal is_nullable: 1 size: 45 -useful for reporting purposes - =cut __PACKAGE__->add_columns( @@ -785,8 +783,8 @@ __PACKAGE__->add_columns( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-07-12 13:40:00 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9q8LmKrfO6bAAFaJ4Z3Jrg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kv30nVGZX7XzeqYuksBjMg __PACKAGE__->add_columns( '+anonymized' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/LanguageDescription.pm b/Koha/Schema/Result/LanguageDescription.pm index aed9cb67ec..b8ef96a735 100644 --- a/Koha/Schema/Result/LanguageDescription.pm +++ b/Koha/Schema/Result/LanguageDescription.pm @@ -80,9 +80,27 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS -# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fQEN7ks3f7aLuoDQWqEv+Q +=head2 C + +=over 4 + +=item * L + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("uniq_desc", ["subtag", "type", "lang"]); + + +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qe9j3WniHRYQr02i8mbf3Q # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/LanguageRfc4646ToIso639.pm b/Koha/Schema/Result/LanguageRfc4646ToIso639.pm index 0ec143c61d..5a871ba359 100644 --- a/Koha/Schema/Result/LanguageRfc4646ToIso639.pm +++ b/Koha/Schema/Result/LanguageRfc4646ToIso639.pm @@ -64,9 +64,25 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS -# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:80baGnx1j4ZZjs0Qn5VMsw +=head2 C + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("uniq_code", ["rfc4646_subtag", "iso639_2_code"]); + + +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zPavbX28u/JWNjA/DRo/Xg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/LanguageSubtagRegistry.pm b/Koha/Schema/Result/LanguageSubtagRegistry.pm index 0a47981f0b..04df8cdd3d 100644 --- a/Koha/Schema/Result/LanguageSubtagRegistry.pm +++ b/Koha/Schema/Result/LanguageSubtagRegistry.pm @@ -84,9 +84,25 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:M4QL1kgte1o/Wz+XjSduWA +=head2 C + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("uniq_lang", ["subtag", "type"]); + + +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JxOAlQQ/DwMZPBuFa0QOLQ # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Serial.pm b/Koha/Schema/Result/Serial.pm index 46c22cc420..cf1a039663 100644 --- a/Koha/Schema/Result/Serial.pm +++ b/Koha/Schema/Result/Serial.pm @@ -47,6 +47,12 @@ foreign key for the biblio.biblionumber that this issue is attached to foreign key to the subscription.subscriptionid that this issue is part of +=head2 aqbooksellerid + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 serialseq data_type: 'varchar' @@ -151,6 +157,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "subscriptionid", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "aqbooksellerid", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "serialseq", { data_type => "varchar", default_value => "", is_nullable => 0, size => 100 }, "serialseq_x", @@ -191,6 +199,26 @@ __PACKAGE__->set_primary_key("serialid"); =head1 RELATIONS +=head2 aqbooksellerid + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "aqbooksellerid", + "Koha::Schema::Result::Aqbookseller", + { id => "aqbooksellerid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "RESTRICT", + on_update => "RESTRICT", + }, +); + =head2 biblionumber Type: belongs_to @@ -237,8 +265,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SD7llCvCO+/67cXetzRKPQ +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ysyfk1S/EaT8Msd5m1yVKg # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Subscription.pm b/Koha/Schema/Result/Subscription.pm index 2d6c322320..c51231f960 100644 --- a/Koha/Schema/Result/Subscription.pm +++ b/Koha/Schema/Result/Subscription.pm @@ -59,11 +59,9 @@ start date for this subscription =head2 aqbooksellerid data_type: 'integer' - default_value: 0 + is_foreign_key: 1 is_nullable: 1 -foreign key for aqbooksellers.id to link to the vendor - =head2 cost data_type: 'integer' @@ -340,7 +338,7 @@ __PACKAGE__->add_columns( "startdate", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "aqbooksellerid", - { data_type => "integer", default_value => 0, is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "cost", { data_type => "integer", default_value => 0, is_nullable => 1 }, "aqbudgetid", @@ -433,6 +431,26 @@ __PACKAGE__->set_primary_key("subscriptionid"); =head1 RELATIONS +=head2 aqbooksellerid + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "aqbooksellerid", + "Koha::Schema::Result::Aqbookseller", + { id => "aqbooksellerid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "RESTRICT", + on_update => "CASCADE", + }, +); + =head2 aqorders Type: has_many @@ -549,8 +567,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RA/Z4pcP53tB0kXgo0W6fQ +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-17 09:22:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:C71M+F/3HWXquMi0Eon/qw __PACKAGE__->has_many( "additional_field_values", diff --git a/installer/data/mysql/atomicupdate/bug_18745.perl b/installer/data/mysql/atomicupdate/bug_18745.perl new file mode 100644 index 0000000000..dbc90e042b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18745.perl @@ -0,0 +1,29 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + UPDATE subscription + SET aqbooksellerid = NULL + WHERE aqbooksellerid = 0 + }); + $dbh->do(q{ + ALTER TABLE subscription + MODIFY COLUMN aqbooksellerid int(11) NULL DEFAULT NULL, + ADD CONSTRAINT subscription_ibfk_aqbooksellerid FOREIGN KEY (aqbooksellerid) REFERENCES aqbooksellers (id) ON DELETE RESTRICT ON UPDATE CASCADE + }); + + if (!column_exists('serial', 'aqbooksellerid')) { + $dbh->do(q{ + ALTER TABLE `serial` + ADD COLUMN `aqbooksellerid` int(11) NULL DEFAULT NULL AFTER `subscriptionid`, + ADD CONSTRAINT `serial_aqbooksellerid_fk` FOREIGN KEY (`aqbooksellerid`) REFERENCES `aqbooksellers` (`id`) + }); + $dbh->do(q{ + UPDATE serial s + JOIN subscription sub ON s.subscriptionid = sub.subscriptionid + SET s.aqbooksellerid = sub.aqbooksellerid + }); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18745 - Serial claims: save supplier info on serial-level)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 02cf864ddd..a052d48bde 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4537,6 +4537,7 @@ CREATE TABLE `serial` ( `serialid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique key for the issue', `biblionumber` int(11) NOT NULL COMMENT 'foreign key for the biblio.biblionumber that this issue is attached to', `subscriptionid` int(11) NOT NULL COMMENT 'foreign key to the subscription.subscriptionid that this issue is part of', + `aqbooksellerid` int(11) NULL DEFAULT NULL COMMENT 'the subscription''s bookseller at the time of creation (used for claims)' `serialseq` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'issue information (volume, number, etc)', `serialseq_x` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'first part of issue information', `serialseq_y` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'second part of issue information', @@ -4553,7 +4554,8 @@ CREATE TABLE `serial` ( KEY `serial_ibfk_1` (`biblionumber`), KEY `serial_ibfk_2` (`subscriptionid`), CONSTRAINT `serial_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `serial_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `serial_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `serial_ibfk_3` FOREIGN KEY (`aqbooksellerid`) REFERENCES `aqbooksellers` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -4764,7 +4766,7 @@ CREATE TABLE `subscription` ( `subscriptionid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique key for this subscription', `librarian` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT 'the librarian''s username from borrowers.userid', `startdate` date DEFAULT NULL COMMENT 'start date for this subscription', - `aqbooksellerid` int(11) DEFAULT 0 COMMENT 'foreign key for aqbooksellers.id to link to the vendor', + `aqbooksellerid` int(11) NULL DEFAULT NULL COMMENT 'foreign key for aqbooksellers.id to link to the vendor', `cost` int(11) DEFAULT 0, `aqbudgetid` int(11) DEFAULT 0, `weeklength` int(11) DEFAULT 0 COMMENT 'subscription length in weeks (will not be filled in if monthlength or numberlength is set)', @@ -4809,7 +4811,8 @@ CREATE TABLE `subscription` ( KEY `subscription_ibfk_3` (`biblionumber`), CONSTRAINT `subscription_ibfk_1` FOREIGN KEY (`periodicity`) REFERENCES `subscription_frequencies` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `subscription_ibfk_2` FOREIGN KEY (`numberpattern`) REFERENCES `subscription_numberpatterns` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `subscription_ibfk_3` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `subscription_ibfk_3` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `subscription_ibfk_4` FOREIGN KEY (`aqbooksellerid`) REFERENCES `aqbooksellers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index 39426a6253..9cc6a8200f 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -296,7 +296,7 @@ sub redirect_add_subscription { my $auser = $query->param('user'); my $branchcode = $query->param('branchcode'); - my $aqbooksellerid = $query->param('aqbooksellerid'); + my $aqbooksellerid = $query->param('aqbooksellerid') || undef; my $cost = $query->param('cost'); my $aqbudgetid = $query->param('aqbudgetid'); my @irregularity = $query->multi_param('irregularity'); @@ -390,7 +390,7 @@ sub redirect_mod_subscription { my $librarian => scalar $query->param('librarian'), my $branchcode = $query->param('branchcode'); my $cost = $query->param('cost'); - my $aqbooksellerid = $query->param('aqbooksellerid'); + my $aqbooksellerid = $query->param('aqbooksellerid') || undef; my $biblionumber = $query->param('biblionumber'); my $aqbudgetid = $query->param('aqbudgetid'); diff --git a/t/db_dependent/Serials/Claims.t b/t/db_dependent/Serials/Claims.t index afc3a18e66..a17087492e 100755 --- a/t/db_dependent/Serials/Claims.t +++ b/t/db_dependent/Serials/Claims.t @@ -1,11 +1,11 @@ use Modern::Perl; -use Test::More tests => 17; +use Test::More tests => 18; use C4::Acquisition; use C4::Budgets qw( AddBudgetPeriod AddBudget ); use Koha::Database; use Koha::Acquisition::Booksellers; -use_ok('C4::Serials', qw( GetSuppliersWithLateIssues NewSubscription GetLateOrMissingIssues updateClaim )); +use_ok('C4::Serials', qw( GetSuppliersWithLateIssues NewSubscription GetLateOrMissingIssues updateClaim NewIssue )); use Koha::DateUtils qw( dt_from_string output_pref ); @@ -162,3 +162,27 @@ is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' ); my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); # FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format! #is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' ); + +subtest "Claims when subscription's supplier has changed" => sub { + plan tests => 2; + + my $bookseller1 = Koha::Acquisition::Bookseller->new({ name => 'Bookseller #1' })->store; + my $bookseller2 = Koha::Acquisition::Bookseller->new({ name => 'Bookseller #2' })->store; + my $subscriptionid = NewSubscription( + undef, $branchcode, $bookseller1->id, undef, $budget_id, $biblionumber, + '2013-01-01', undef, undef, undef, undef, + undef, undef, undef, undef, undef, undef, + 1, "notes",undef, '2013-01-01', undef, undef, + undef, undef, 0, "intnotes", 0, + undef, undef, 0, undef, '2013-12-31', 0 + ); + NewIssue('2', $subscriptionid, $biblionumber, 3, '2013-01-02', '2013-01-02'); # 3 is late + my $subscription = Koha::Subscriptions->find($subscriptionid); + $subscription->aqbooksellerid($bookseller2->id)->store(); + NewIssue('3', $subscriptionid, $biblionumber, 3, '2013-01-03', '2013-01-03'); # 3 is late + + my @lateissues = GetLateOrMissingIssues($bookseller1->id); + is(scalar @lateissues, 2, '2 late issues for bookseller1'); + @lateissues = GetLateOrMissingIssues($bookseller2->id); + is(scalar @lateissues, 1, '1 late issue for bookseller2'); +}; -- 2.20.1