Bug 18783 - Allow automatic claims for serials
Summary: Allow automatic claims for serials
Status: Patch doesn't apply
Alias: None
Product: Koha
Classification: Unclassified
Component: Serials (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 18784
  Show dependency treegraph
 
Reported: 2017-06-12 10:41 UTC by Julian Maurice
Modified: 2023-12-22 13:52 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 18783: Allow automatic claims for serials (17.63 KB, patch)
2017-06-12 10:45 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 18783: Allow automatic claims for serials (15.96 KB, patch)
2019-07-09 12:38 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 18783: Allow automatic claims for serials (15.29 KB, patch)
2021-09-17 12:36 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 18783: Allow automatic claims for serials (31.88 KB, patch)
2023-09-08 19:42 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 18783: Allow automatic claims for serials (31.99 KB, patch)
2023-09-08 20:00 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 18783: DBIC Build (1.51 KB, patch)
2023-09-08 20:02 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Maurice 2017-06-12 10:41:56 UTC

    
Comment 1 Julian Maurice 2017-06-12 10:45:06 UTC
Created attachment 64195 [details] [review]
Bug 18783: Allow automatic claims for serials

This patch adds a new script misc/cronjobs/serialsClaim.pl which send
email notification to all suppliers that have late or missing issues.
This is configurable per subscription and is disabled by default.

Test plan:
1. Create a new bookseller B1 with a delivery time of 5 days
2. Create a new daily subscription with bookseller B1 and enable
   automatic claims (new checkbox on the first page of
   subscription-add.pl)
3. Generate some late serials with an expected date in the past (some
   with more than 5 days in the past, some with less)
4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write
   something in the 'Email' template
5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and
   verify that it sends an email notification only for serials that were
   expected more than 5 days ago
Comment 2 Katrin Fischer 2017-07-09 14:38:24 UTC
This is another of the 'missing features' that I have been asked about often. I have tried to test, but when running the script, I receive an error:

kohadev-koha@kohadevbox:/home/vagrant/kohaclone$ ./misc/cronjobs/serialsClaim.pl --letter-code RLIST
The method auto_claim_enabled is not covered by tests!

Possible future enh: 
For servers with multiple instances it would be nice if the letter code could be configured inside Koha. Either as a system preference or even better per vendor, then you could have different letters for different languages.
Comment 3 Julian Maurice 2017-08-09 09:21:27 UTC
Hi Katrin,

(In reply to Katrin Fischer from comment #2)
> kohadev-koha@kohadevbox:/home/vagrant/kohaclone$
> ./misc/cronjobs/serialsClaim.pl --letter-code RLIST
> The method auto_claim_enabled is not covered by tests!

Did you run updatedatabase.pl and misc/devel/update_dbix_class_files.pl ?
Comment 4 Katrin Fischer 2017-08-10 11:17:31 UTC
Hi Julian, 
that fixed the issue. 
I have tested adding and modifying subscriptions, the new option works nicely.
I have also run the command without errors, but then realized that I cannot currently test emails on my installation. As they are not going through the message_queue I can't verify them being sent/generated correctly right now. 
Leaving this Needs Signoff for now, maybe someone else can continue testing.

Note: You might want to add a test for the changes to SendAlert.
Comment 5 Katrin Fischer 2017-08-10 11:34:41 UTC
Ok, I have figured out a way to see the email:

1) Errors when running script
My message template was:

Das folgende Heft ist jetzt verfügbar:

<<biblio.title>> <<biblio.author>> <<biblio.serial>>

When I run the command, I receive some errors:
kohadev-koha@kohadevbox:/home/vagrant/kohaclone$ ./misc/cronjobs/serialsClaim.pl --letter-code RLIST
Use of uninitialized value in substitution iterator at /home/vagrant/kohaclone/C4/Letters.pm line 776.
Use of uninitialized value in substitution iterator at /home/vagrant/kohaclone/C4/Letters.pm line 776.
Claim sent to Osiandersche Buchhandlung (3) for serials 3

The email is generated, but the placeholders are not being replaced.

2) Verbosity
I wonder if the success message should only be shown if you add -v, this way it would be a bit less noisy when run as cronjob.
Comment 6 Katrin Fischer 2018-01-01 20:27:44 UTC
Would be nice to see this progressing, it's often asked for!
Comment 7 Fridolin Somers 2018-06-19 09:38:58 UTC
Needs rebase.
For example serials/subscription-add.pl has been modified by Bug 20461
Comment 8 Julian Maurice 2019-07-09 12:38:15 UTC
Created attachment 91428 [details] [review]
Bug 18783: Allow automatic claims for serials

This patch adds a new script misc/cronjobs/serialsClaim.pl which send
email notification to all suppliers that have late or missing issues.
This is configurable per subscription and is disabled by default.

Test plan:
1. Create a new bookseller B1 with a delivery time of 5 days
2. Create a new daily subscription with bookseller B1 and enable
   automatic claims (new checkbox on the first page of
   subscription-add.pl)
3. Generate some late serials with an expected date in the past (some
   with more than 5 days in the past, some with less)
4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write
   something in the 'Email' template
5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and
   verify that it sends an email notification only for serials that were
   expected more than 5 days ago
Comment 9 Julian Maurice 2019-07-09 12:38:39 UTC
Patch rebased on master
Comment 10 Katrin Fischer 2019-10-14 21:56:05 UTC
I am sorry, doesn't apply - can we get another rebase?
Comment 11 Julian Maurice 2021-09-17 12:36:20 UTC
Created attachment 124984 [details] [review]
Bug 18783: Allow automatic claims for serials

This patch adds a new script misc/cronjobs/serialsClaim.pl which send
email notification to all suppliers that have late or missing issues.
This is configurable per subscription and is disabled by default.

Test plan:
1. Create a new bookseller B1 with a delivery time of 5 days
2. Create a new daily subscription with bookseller B1 and enable
   automatic claims (new checkbox on the first page of
   subscription-add.pl)
3. Generate some late serials with an expected date in the past (some
   with more than 5 days in the past, some with less)
4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write
   something in the 'Email' template
5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and
   verify that it sends an email notification only for serials that were
   expected more than 5 days ago
Comment 12 Julian Maurice 2021-09-17 12:36:39 UTC
Patch rebased on master
Comment 13 Jessie Zairo 2021-12-22 15:17:00 UTC
When testing we got an error of DBIx::Class::Row::store_column(): No such column 'auto_claim_enabled' on Koha::Schema::Result::Subscription at /kohadevbox/koha/Koha/Object.pm line 79
 at /usr/share/perl5/DBIx/Class/Exception.pm line 77
Comment 14 Fridolin Somers 2022-07-29 08:11:33 UTC
Hi,

This change looks like outside of scope :

@@ -502,7 +507,8 @@ sub SendAlerts {
         }
 
         my $success = try {
-            $mail->send_or_die({ transport => $library->smtp_server->transport });
+            my $smtp_server = $library ? $library->smtp_server : Koha::SMTP::Servers->get_default;
+            $mail->send_or_die({ transport => $smtp_server->transport });
         }
Comment 15 Katrin Fischer 2022-07-30 19:59:50 UTC
(In reply to Jessie Zairo from comment #13)
> When testing we got an error of DBIx::Class::Row::store_column(): No such
> column 'auto_claim_enabled' on Koha::Schema::Result::Subscription at
> /kohadevbox/koha/Koha/Object.pm line 79
>  at /usr/share/perl5/DBIx/Class/Exception.pm line 77

If you see an error like this, make sure that the database update has run and if there is no Schema update patch, you need to 'refresh schema' in the sandbox or run the dbic command.

Would love to see this back in the queues!
Comment 16 Fridolin Somers 2023-09-01 21:09:41 UTC
+ use C4::Installer qw(column_exists);
Not sure this is needed in atomicupdate bug-18783.pl, I dont see it in existing DBRevs
Comment 17 Fridolin Somers 2023-09-01 21:10:41 UTC
installer/data/mysql/atomicupdate/bug-18783.pl needs exec file permission : chmod 775
Comment 18 Fridolin Somers 2023-09-01 21:12:20 UTC
@@ -1859,7 +1862,7 @@ sub GetLateOrMissingIssues {
     if ($supplierid) {
         $sth = $dbh->prepare(
             "SELECT
-                serialid,      aqbooksellerid,        name,
+                serialid,      serial.aqbooksellerid,        name,

This is outside of scope no ?
Maybe linked to Bug 18745
Comment 19 Martin Renvoize 2023-09-08 19:42:07 UTC
Created attachment 155458 [details] [review]
Bug 18783: Allow automatic claims for serials

This patch adds a new script misc/cronjobs/serialsClaim.pl which send
email notification to all suppliers that have late or missing issues.
This is configurable per subscription and is disabled by default.

Test plan:
1. Create a new bookseller B1 with a delivery time of 5 days
2. Create a new daily subscription with bookseller B1 and enable
   automatic claims (new checkbox on the first page of
   subscription-add.pl)
3. Generate some late serials with an expected date in the past (some
   with more than 5 days in the past, some with less)
4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write
   something in the 'Email' template
5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and
   verify that it sends an email notification only for serials that were
   expected more than 5 days ago
Comment 20 Martin Renvoize 2023-09-08 19:42:33 UTC
Rebased ready for testing again
Comment 21 Martin Renvoize 2023-09-08 19:44:10 UTC
Taking a look at some modernising patches now to bring it closer to current guidelines/practices.
Comment 22 Martin Renvoize 2023-09-08 20:00:04 UTC
Created attachment 155462 [details] [review]
Bug 18783: Allow automatic claims for serials

This patch adds a new script misc/cronjobs/serialsClaim.pl which send
email notification to all suppliers that have late or missing issues.
This is configurable per subscription and is disabled by default.

Test plan:
1. Create a new bookseller B1 with a delivery time of 5 days
2. Create a new daily subscription with bookseller B1 and enable
   automatic claims (new checkbox on the first page of
   subscription-add.pl)
3. Generate some late serials with an expected date in the past (some
   with more than 5 days in the past, some with less)
4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write
   something in the 'Email' template
5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and
   verify that it sends an email notification only for serials that were
   expected more than 5 days ago

Rescued-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 23 Martin Renvoize 2023-09-08 20:00:54 UTC
Patch tidied and other minor QA script issues resolved inline.
Comment 24 Martin Renvoize 2023-09-08 20:02:53 UTC
Created attachment 155463 [details] [review]
Bug 18783: DBIC Build