From 748643e22a8affdab3272912ada7288c171ac3dd Mon Sep 17 00:00:00 2001 From: Martin Vesper Date: Wed, 18 Nov 2015 14:32:19 +0100 Subject: [PATCH] BibCirculation: reset ILL overdue_letter_number * A ILL is currently extended by manually updating the *due_date* of that ILL, this leads to the following issue: A user receives an ILL recall letter, therefore gets the ILL extended at the library. The next ILL recall letter will be of the second category, since the *overdue_letter_number* never gets reseted. * Introduces the new function *update_ill_request_letter_number* * Changes the *overdue_letter_number* in case the updated due_date is a later date than the current due_date in *ill_request_details_step2*. Signed-off-by: Martin Vesper --- .../lib/bibcirculation_dblayer.py | 5 +++++ .../lib/bibcirculationadminlib.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/modules/bibcirculation/lib/bibcirculation_dblayer.py b/modules/bibcirculation/lib/bibcirculation_dblayer.py index 42ecbce514..8110d551c6 100644 --- a/modules/bibcirculation/lib/bibcirculation_dblayer.py +++ b/modules/bibcirculation/lib/bibcirculation_dblayer.py @@ -2700,6 +2700,11 @@ def get_purchase_request_borrower_details(ill_request_id): else: return None +def update_ill_request_letter_number(ill_request_id, overdue_letter_number): + query = ('UPDATE crcILLREQUEST set overdue_letter_number={0} ' + 'where id="{1}"') + run_sql(query.format(overdue_letter_number, ill_request_id)) + def update_ill_request(ill_request_id, library_id, request_date, expected_date, arrival_date, due_date, return_date, status, cost, barcode, library_notes): diff --git a/modules/bibcirculation/lib/bibcirculationadminlib.py b/modules/bibcirculation/lib/bibcirculationadminlib.py index c5647a8b88..a13d9ae50c 100644 --- a/modules/bibcirculation/lib/bibcirculationadminlib.py +++ b/modules/bibcirculation/lib/bibcirculationadminlib.py @@ -4936,6 +4936,25 @@ def ill_request_details_step2(req, delete_key, ill_request_id, new_status, barcode = db.get_ill_barcode(ill_request_id) db.update_ill_loan_status(borrower_id, barcode, return_date, 'ill') + # ill recall letter issue + try: + from invenio.dbquery import run_sql + _query = ('SELECT due_date from crcILLREQUEST where id = "{0}"') + _due = run_sql(_query.format(ill_request_id))[0][0] + + # Since we don't know if the due_date is a string or datetime + try: + _due_date = datetime.datetime.strptime(due_date, '%Y-%m-%d') + except TypeError: + _due_date = due_date + + # This means that the ILL got extended, we therefore reset the + # overdue_letter_numer + if _due < _due_date: + db.update_ill_request_letter_number(ill_request_id, 0) + except Exception: + pass + db.update_ill_request(ill_request_id, library_id, request_date, expected_date, arrival_date, due_date, return_date, new_status, cost, barcode,