diff --git a/data/users.json b/data/users.json index 5b1a6f2ee7..298b7c89d0 100644 --- a/data/users.json +++ b/data/users.json @@ -73,7 +73,7 @@ "postal_code": "11100", "street": "Via Croix Noire 3", "communication_channel": "email", - "communication_language": "it" + "communication_language": "ita" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -93,7 +93,7 @@ "postal_code": "11100", "street": "Panoramica Collinare, 47", "communication_channel": "email", - "communication_language": "it" + "communication_language": "ita" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -131,7 +131,7 @@ "postal_code": "1950", "street": "Rue du Nord 7", "communication_channel": "email", - "communication_language": "fr" + "communication_language": "fre" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -152,7 +152,7 @@ "postal_code": "95054", "street": "520 Scott Blvd", "communication_channel": "email", - "communication_language": "en" + "communication_language": "eng" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -173,7 +173,7 @@ "postal_code": "1892", "street": "Route du Village 6", "communication_channel": "email", - "communication_language": "fr" + "communication_language": "fre" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -194,7 +194,7 @@ "postal_code": "6500", "street": "Piazza Collegiata 12", "communication_channel": "email", - "communication_language": "it" + "communication_language": "ita" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -215,7 +215,7 @@ "postal_code": "1920", "street": "Gare 45", "communication_channel": "email", - "communication_language": "en" + "communication_language": "eng" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -236,7 +236,7 @@ "postal_code": "1926", "street": "Vignettes 25", "communication_channel": "email", - "communication_language": "de" + "communication_language": "ger" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -275,7 +275,7 @@ "postal_code": "55555", "street": "Magic Street 3", "communication_channel": "email", - "communication_language": "en" + "communication_language": "eng" }, { "$schema": "https://ils.rero.ch/schema/patrons/patron-v0.0.1.json", @@ -295,6 +295,6 @@ "postal_code": "55555", "street": "Diagon Alley 72", "communication_channel": "email", - "communication_language": "en" + "communication_language": "eng" } ] diff --git a/rero_ils/config.py b/rero_ils/config.py index 2f2b2db7d9..253cf452bf 100644 --- a/rero_ils/config.py +++ b/rero_ils/config.py @@ -909,7 +909,6 @@ def _(x): 'notif': '/notifications/notification-v0.0.1.json', } - # Login Configuration # =================== #: Allow password change by users. diff --git a/rero_ils/modules/notifications/api.py b/rero_ils/modules/notifications/api.py index eee1a23cb9..153b0d4c01 100644 --- a/rero_ils/modules/notifications/api.py +++ b/rero_ils/modules/notifications/api.py @@ -27,7 +27,7 @@ from __future__ import absolute_import, print_function from copy import deepcopy -from datetime import datetime +from datetime import datetime, timedelta from functools import partial from invenio_search.api import RecordsSearch @@ -37,6 +37,7 @@ from ..api import IlsRecord from ..documents.api import Document from ..fetchers import id_fetcher +from ..libraries.api import Library from ..locations.api import Location from ..minters import id_minter from ..patrons.api import Patron @@ -103,6 +104,17 @@ def replace_pids_and_refs(self): data['loan']['pickup_location'] = \ pickup_location.replace_refs().dumps() # del(data['loan']['pickup_location_pid']) + library_pid = data['loan']['pickup_location']['library']['pid'] + library = Library.get_record_by_pid(library_pid) + data['loan']['pickup_location']['library'] = library + keep_until = datetime.now() + timedelta(days=10) + next_open = library.next_open(keep_until) + # language = data['loan']['patron']['communication_language'] + next_open = next_open.strftime("%d-%b-%Y") + data['loan']['next_open'] = next_open + else: + data['loan']['pickup_location'] = \ + self.transaction_location.replace_refs().dumps() data['loan']['document'] = self.document.replace_refs().dumps() # del(data['loan']['document_pid']) return data diff --git a/rero_ils/modules/notifications/dispatcher.py b/rero_ils/modules/notifications/dispatcher.py index 84c01c743f..6ff0fcf18b 100644 --- a/rero_ils/modules/notifications/dispatcher.py +++ b/rero_ils/modules/notifications/dispatcher.py @@ -26,6 +26,7 @@ from __future__ import absolute_import, print_function +from flask import current_app from flask_security.utils import config_value from invenio_mail.api import TemplatedMessage from invenio_mail.tasks import send_email @@ -38,15 +39,26 @@ def dispatch_notification(self, notification=None): """Dispatch the notification.""" if notification: data = notification.replace_pids_and_refs() - self.send_mail(data=data) + communication_channel = \ + data['loan']['patron']['communication_channel'] + if communication_channel == 'email': + self.send_mail(data=data) + if communication_channel == 'sms': + pass + if communication_channel == 'whatsapp': + pass + if communication_channel == 'letter': + pass notification = notification.update_process_date() return notification def send_mail(self, data): """Send email.""" + data['loan']['profile_url'] = \ + 'https://ils.test.rero.ch/patrons/profile' notification_type = data.get('notification_type') - language = 'eng' - template = 'email/{type}_{lang}'.format( + language = data['loan']['patron']['communication_language'] + template = 'email/{type}/{lang}'.format( type=notification_type, lang=language ) @@ -54,13 +66,17 @@ def send_mail(self, data): msg = TemplatedMessage( # template_html='{template}.html'.format(template=template), template_body='{template}.txt'.format(template=template), - subject=notification_type, sender=config_value('EMAIL_SENDER'), recipients=[recipient], ctx=data['loan'] ) - + text = msg.body.split('\n') + msg.subject = text[0] + msg.body = '\n'.join(text[1:]) try: - send_email.delay(msg.__dict__) + send_email.run(msg.__dict__) + # TODO: investigate why delay does not work + # send_email.delay(msg.__dict__) + # current_app.extensions['mail'].send(msg) except Exception as e: raise(e) diff --git a/rero_ils/modules/notifications/templates/email/availability/eng.txt b/rero_ils/modules/notifications/templates/email/availability/eng.txt new file mode 100644 index 0000000000..205df0c457 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/availability/eng.txt @@ -0,0 +1,17 @@ +Invitation to pick up a document +Dear patron, + +The document you requested is now available. You can pick it up at the loan desk of the library mentioned below. + +Author: {{ document.authors[0].name }} +Title: {{ document.title }} +Pick up location: {{ pickup_location.name }} +To pick up until: {{ next_open }} + +Should the document not be picked up within the given period, it will be made available for other people. +You can consult your account and extend the loan period of your documents at: {{ profile_url }} + +Best regards + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/availability/fre.txt b/rero_ils/modules/notifications/templates/email/availability/fre.txt new file mode 100644 index 0000000000..5eb874655f --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/availability/fre.txt @@ -0,0 +1,17 @@ +Invitation à retirer un document +Chère lectrice, cher lecteur, + +Le document que vous avez demandé est maintenant disponible. Vous pouvez venir le retirer au bureau de prêt de la bibliothèque mentionnée ci-dessous. + +Auteur : {{ document.authors[0].name }} +Titre : {{ document.title }} +Lieu de retrait : {{ pickup_location.name }} +A retirer jusqu'au : {{ next_open }} + +Si le document n'est pas retiré dans les délais, il sera remis en circulation pour d'autres personnes. +Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }} + +Avec nos compliments + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/availability/ger.txt b/rero_ils/modules/notifications/templates/email/availability/ger.txt new file mode 100644 index 0000000000..fdffad8c03 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/availability/ger.txt @@ -0,0 +1,17 @@ +Abholeinladung +Sehr geehrte Leserin, sehr geehrter Leser, + +Das von Ihnen bestellte Dokument ist nun verfügbar und kann an der Ausleihtheke der nachstehend genannten Bibliothek abgeholt werden. + +Autor: {{ document.authors[0].name }} +Titel: {{ document.title }} +Abholort: {{ pickup_location.name }} +Abholen bis: {{ next_open }} + +Wenn das Dokument innerhalb der gegebenen Frist nicht abgeholt wird, wird es anderen Personen zur Verfügung gestellt. +Unter folgender Adresse können Sie Ihr Konto einsehen und die Ausleihfrist Ihrer Dokumente verlängern: {{ profile_url }} + +Freundliche Grüsse + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/availability/ita.txt b/rero_ils/modules/notifications/templates/email/availability/ita.txt new file mode 100644 index 0000000000..1e87adbb90 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/availability/ita.txt @@ -0,0 +1,17 @@ +Invito a ritirare un documento +Cara lettrice, caro lettore, + +Il documento che Lei ha domandato è ora disponibile. Lei può ritirarlo al servizio prestiti della biblioteca sotto indicata. + +Autore: {{ document.authors[0].name }} +Titolo: {{ document.title }} +Punto di ritiro: {{ pickup_location.name }} +Ritirare entro: {{ next_open }} + +Se il documento non è ritirato entro detto termine, esso sarà rimesso in circolazione per altre persone. +Lei può consultare il Suo conto et prorogare la durata di prestito dei Suoi documenti al seguente indirizzo: {{ profile_url }} + +Cordiali saluti + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/availability_eng.txt b/rero_ils/modules/notifications/templates/email/availability_eng.txt deleted file mode 100644 index 39babbd95b..0000000000 --- a/rero_ils/modules/notifications/templates/email/availability_eng.txt +++ /dev/null @@ -1,6 +0,0 @@ -Document is available: -pid: {{ document.pid }} -title: {{ document.title }} - -Best regards -Your library diff --git a/rero_ils/modules/notifications/templates/email/due_soon/eng.txt b/rero_ils/modules/notifications/templates/email/due_soon/eng.txt new file mode 100644 index 0000000000..e96e230506 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/due_soon/eng.txt @@ -0,0 +1,16 @@ +Expiry notice +Dear patron, + +The loan period of following documents is expiring: + +Author: {{ document.authors[0].name }} +Title: {{ document.title }} +Due date: {{ end_date }} +Note: Non extendable + +You can consult your account and extend the loan period of your documents at: {{ profile_url }} + +Best regards + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/due_soon/fre.txt b/rero_ils/modules/notifications/templates/email/due_soon/fre.txt new file mode 100644 index 0000000000..9f954ef35e --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/due_soon/fre.txt @@ -0,0 +1,16 @@ +Avis d'échéance +Chère lectrice, cher lecteur, + +Le délai de prêt des documents mentionnés ci-dessous arrive à échéance : + +Auteur : {{ document.authors[0].name }} +Titre : {{ document.title }} +Echéance : {{ end_date }} +Note : Non extendable + +Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }} + +Avec nos compliments + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/due_soon/ger.txt b/rero_ils/modules/notifications/templates/email/due_soon/ger.txt new file mode 100644 index 0000000000..3cf72df1cd --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/due_soon/ger.txt @@ -0,0 +1,16 @@ +Ablauf der Ausleihfrist +Sehr geehrte Leserin, sehr geehrter Leser, + +Die Ausleihfrist der folgenden Dokumente läuft ab: + +Autor: {{ document.authors[0].name }} +Titel: {{ document.title }} +Rückgabedatum: {{ end_date }} +Anmerkung: Non extendable + +Unter folgender Adresse können Sie Ihr Konto einsehen und die Ausleihfrist Ihrer Dokumente verlängern: {{ profile_url }} + +Freundliche Grüsse + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/due_soon/ita.txt b/rero_ils/modules/notifications/templates/email/due_soon/ita.txt new file mode 100644 index 0000000000..81567f8458 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/due_soon/ita.txt @@ -0,0 +1,16 @@ +Avviso di scadenza +Cara lettrice, caro lettore, + +La durata di prestito dei seguenti documenti sta per scadere: + +Autore: {{ document.authors[0].name }} +Titolo: {{ document.title }} +Scadenza: {{ end_date }} +Nota: Non extendable + +Lei può consultare il Suo conto et prorogare la durata di prestito dei Suoi documenti al seguente indirizzo: {{ profile_url }} + +Cordiali saluti + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/due_soon_eng.txt b/rero_ils/modules/notifications/templates/email/due_soon_eng.txt deleted file mode 100644 index 08674e8494..0000000000 --- a/rero_ils/modules/notifications/templates/email/due_soon_eng.txt +++ /dev/null @@ -1,6 +0,0 @@ -Document due soon: -pid: {{ document.pid }} -title: {{ document.title }} - -Best regards -Your library diff --git a/rero_ils/modules/notifications/templates/email/overdue/eng.txt b/rero_ils/modules/notifications/templates/email/overdue/eng.txt new file mode 100644 index 0000000000..3e684ff9a7 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/overdue/eng.txt @@ -0,0 +1,16 @@ +1st reminder +Dear patron, + +The loan period of following documents has expired: + +Author: {{ document.authors[0].name }} +Title: {{ document.title }} +Due date: {{ end_date }} +Note: 1st reminder + +You can consult your account and extend the loan period of your documents at: {{ profile_url }} + +Best regards + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/overdue/fre.txt b/rero_ils/modules/notifications/templates/email/overdue/fre.txt new file mode 100644 index 0000000000..d96f8a4c76 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/overdue/fre.txt @@ -0,0 +1,16 @@ +1er rappel +Chère lectrice, cher lecteur, + +La durée du prêt des documents mentionnés ci-dessous est échue : + +Auteur : {{ document.authors[0].name }} +Titre : {{ document.title }} +Echéance : {{ end_date }} +Note : 1er rappel + +Vous pouvez consulter votre compte et prolonger la durée de prêt de vos documents à l'adresse : {{ profile_url }} + +Avec nos complimen + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/overdue/ger.txt b/rero_ils/modules/notifications/templates/email/overdue/ger.txt new file mode 100644 index 0000000000..21580baf55 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/overdue/ger.txt @@ -0,0 +1,16 @@ +1. Mahnung +Sehr geehrte Leserin, sehr geehrter Leser, + +Die Ausleihfrist folgender Dokumente ist abgelaufen: + +Autor: {{ document.authors[0].name }} +Titel: {{ document.title }} +Rückgabedatum: {{ end_date }} +Anmerkung: 1. Mahnung + +Unter folgender Adresse können Sie Ihr Konto einsehen und die Ausleihfrist Ihrer Dokumente verlängern: {{ profile_url }} + +Freundliche Grüsse + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/overdue/ita.txt b/rero_ils/modules/notifications/templates/email/overdue/ita.txt new file mode 100644 index 0000000000..29e864b960 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/overdue/ita.txt @@ -0,0 +1,16 @@ +1° richiamo +Cara lettrice, caro lettore, + +La durata di prestito dei seguenti documenti è scaduta: + +Autore: {{ document.authors[0].name }} +Titolo: {{ document.title }} +Scadenza: {{ end_date }} +NoNotate: 1° richiamo + +Lei può consultare il Suo conto et prorogare la durata di prestito dei Suoi documenti al seguente indirizzo: {{ profile_url }} + +Cordiali saluti + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/overdue_eng.txt b/rero_ils/modules/notifications/templates/email/overdue_eng.txt deleted file mode 100644 index 88c78d0411..0000000000 --- a/rero_ils/modules/notifications/templates/email/overdue_eng.txt +++ /dev/null @@ -1,6 +0,0 @@ -Document overdue: -pid: {{ document.pid }} -title: {{ document.title }} - -Best regards -Your library diff --git a/rero_ils/modules/notifications/templates/email/recall/eng.txt b/rero_ils/modules/notifications/templates/email/recall/eng.txt new file mode 100644 index 0000000000..88c96b70f7 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/recall/eng.txt @@ -0,0 +1,17 @@ +Non-extendable document +Dear patron, + +The document you borrowed has been requested by another person. +An extension of the loan period is therefore no longer possible and we kindly ask you to return it at the latest by the due date. + +Author: {{ document.authors[0].name }} +Title: {{ document.title }} +Due date: {{ end_date }} +Note: Non-extendable + +You can consult your account at: {{ profile_url }} + +Best regards + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/recall/fre.txt b/rero_ils/modules/notifications/templates/email/recall/fre.txt new file mode 100644 index 0000000000..85983bcd24 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/recall/fre.txt @@ -0,0 +1,17 @@ +Document non prolongeable +Chère lectrice, cher lecteur, + +Le document que vous avez emprunté vient d'être réservé par une autre personne. +D'ores et déjà nous vous signalons que nous ne pourrons pas le prolonger et vous demandons de bien vouloir le restituer au plus tard à la date d'échéance. + +Auteur : {{ document.authors[0].name }} +Titre : {{ document.title }} +Échéance : {{ end_date }} +Note : Non prolongeable + +Vous pouvez consulter votre compte à l'adresse : {{ profile_url }} + +Avec nos compliments + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/recall/ger.txt b/rero_ils/modules/notifications/templates/email/recall/ger.txt new file mode 100644 index 0000000000..75dd0247a9 --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/recall/ger.txt @@ -0,0 +1,16 @@ +Nicht verlängerbares Dokument +Sehr geehrte Leserin, sehr geehrter Leser, + +Das von Ihnen ausgeliehene Dokument ist von einer anderen Person reserviert worden. +Eine Verlängerung der Ausleihfrist ist deshalb nicht mehr möglich und wir bitten Sie, das Dokument spätestens bis zum Rückgabedatum zurückzugeben. + +Autor: {{ document.authors[0].name }} +Titel: {{ document.title }} +Rückgabedatum: {{ end_date }} +Anmerkung: Nicht verlängerbar + +Unter folgender Adresse können Sie Ihr Konto einsehen: {{ profile_url }} + +Freundliche Grüsse +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/recall/ita.txt b/rero_ils/modules/notifications/templates/email/recall/ita.txt new file mode 100644 index 0000000000..d74d66505d --- /dev/null +++ b/rero_ils/modules/notifications/templates/email/recall/ita.txt @@ -0,0 +1,17 @@ +Documento non prorogabile +Cara lettrice, caro lettore, + +Il documento che Lei ha presto in prestito è stato riservato da un'altra persona. +Una proroga della durata di prestito non è quindi più possibile e La preghiamo di restituirlo entro la scadenza. + +Autore: {{ document.authors[0].name }} +Titolo: {{ document.title }} +Scadenza: {{ end_date }} +Nota: Non prorogabile + +Lei può consultare il Suo conto al seguente indirizzo: {{ profile_url }} + +Cordiali saluti + +{{ pickup_location.library.name }} +{{ pickup_location.library.address }} diff --git a/rero_ils/modules/notifications/templates/email/recall_eng.txt b/rero_ils/modules/notifications/templates/email/recall_eng.txt deleted file mode 100644 index 967ca90e9b..0000000000 --- a/rero_ils/modules/notifications/templates/email/recall_eng.txt +++ /dev/null @@ -1,6 +0,0 @@ -Document recalled: -pid: {{ document.pid }} -title: {{ document.title }} - -Best regards -Your library diff --git a/rero_ils/modules/patrons/jsonschemas/form_patrons/patron-v0.0.1.json b/rero_ils/modules/patrons/jsonschemas/form_patrons/patron-v0.0.1.json index e512fa858f..b1b8a330fd 100644 --- a/rero_ils/modules/patrons/jsonschemas/form_patrons/patron-v0.0.1.json +++ b/rero_ils/modules/patrons/jsonschemas/form_patrons/patron-v0.0.1.json @@ -157,10 +157,10 @@ "htmlClass": "px-2", "type": "select", "titleMap": { - "en": "English", - "fr": "French", - "de": "German", - "it": "Italian" + "eng": "English", + "fre": "French", + "ger": "German", + "ita": "Italian" }, "placeHolder": "Select\u2026", "condition": { diff --git a/rero_ils/modules/patrons/jsonschemas/patrons/patron-v0.0.1.json b/rero_ils/modules/patrons/jsonschemas/patrons/patron-v0.0.1.json index 53d116dd30..4fc18a7aec 100644 --- a/rero_ils/modules/patrons/jsonschemas/patrons/patron-v0.0.1.json +++ b/rero_ils/modules/patrons/jsonschemas/patrons/patron-v0.0.1.json @@ -138,10 +138,10 @@ "title": "Communication language", "type": "string", "enum": [ - "de", - "en", - "fr", - "it" + "ger", + "eng", + "fre", + "ita" ] } } diff --git a/tests/data/data.json b/tests/data/data.json index 3d4153d9ca..79f33891b1 100644 --- a/tests/data/data.json +++ b/tests/data/data.json @@ -1324,6 +1324,8 @@ }, "email": "lroduit@gmail.com", "phone": "+41324993156", + "communication_language": "eng", + "communication_channel": "email", "roles": [ "patron" ] @@ -1343,6 +1345,8 @@ }, "email": "lmoret@gmail.com", "phone": "+41324993151", + "communication_language": "eng", + "communication_channel": "email", "roles": [ "patron" ] @@ -1397,6 +1401,8 @@ }, "email": "reroilstest+jules@gmail.com", "phone": "+41324993673", + "communication_language": "eng", + "communication_channel": "email", "roles": [ "patron" ]