https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29490 --- Comment #15 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 211799 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211799&action=edit Bug 29490: Preview for more notices Only the CHECKIN, CHECKOUT and HOLD_SLIP notices could be previewed, as each needed its own code to get the data of the notice, and their data had to be given in a specific format (e.g. barcode|borrowernumber). Notices can now all be previewed. Their data is built from what each notice receives, as listed in Koha::Notice::Template::Variables (bug 36588), by the new Koha::Notice::Template::Preview. In the notice editor, "Data for preview" is replaced with fields for the records the notice receives, all optional (Enter previews the template shown): a patron (card number) and an item (barcode) for circulation notices, a basket and a vendor for basket orders, a vendor for claims, a hold, a suggestion, an ILL request, a booking, an OAI server for OAI harvest reports... Notices not listed in the registry get a patron and an item. The notice is previewed with these records and those related to them: - the vendor and the orders of a basket, the patron and the item of a hold, the patron who made a suggestion... - the library as the senders give it: the pickup library of a hold, booking or recall, the circulation control library for checkouts, checkins and renewals, else the library of the patron - the item or the item of the patron's first checkout, their latest credit or debit, their holds, overdues, checkouts... - for other kinds of records, the latest whose table refers to all the records given (e.g. the hold of the patron on the item), else to one of them, which a note says (e.g. by basketno, borrowernumber, itemnumber, biblionumber), following the relationships of the database - for a hold, booking... on a record, an item of that record - values taken from a record, as the registry says with 'from' (e.g. the servername, endpoint and set of the OAI server of OAI_HARVEST_REPORT) - an example record of the kind when none is related, their checkouts for overdues when the patron has no overdues, and placeholders (e.g. [passwordreseturl]) for values. Without a patron, notices receiving one are previewed with an example patron; other notices (e.g. acquisition notices) get none. - the same data for the bespoke syntax, passed as tables so that <<table.column>> values are formatted as in sent notices (e.g. dates), <<items.content>> and <item>...</item> The preview says which data does not come from the records given. Notices sent once per item, whose notices for several items are combined into one message while the first is not sent yet (C4::Message->append): CHECKOUT, CHECKIN and RENEWAL, and HOLDDGST (the digest of waiting holds), can be previewed with several items, separated by commas, or with the patron's (their checkouts, returns or waiting holds, up to 3). Each item is previewed with its own records (e.g. its checkout, the patron's hold on it), and the results are combined as queued notices are: lines of ---- separate the header and the footer from the part repeated for each item. The bodies of all the items are put between the header and the footer of the last one, and the subject is that of the first item, as C4::Message->append only changes the content of the message queued for the first item. Without barcodes, up to 3 items of the patron are used, which shows how the notice combines without making the preview long. Is there a reason to preview more by default? (Any number of barcodes can be entered.) The records are also passed as tables, with the module, code and transport of the notice, as the code sending each notice does (e.g. the hold of HOLD notices, the itemnumber of issues), so that plugins adding content to notices with the notices_content hook (e.g. Rapido ILL, for holds on ILL requests) get the same data in a preview as in a notice. Test plan: 1. Apply the patch and restart services 2. Check out an item to a patron, with a due date in the past 3. Go to Tools > Notices and slips and edit the ODUE notice 4. "Preview with" offers a patron. Enter the card number of the patron, and click Preview in the Email template: => The notice is previewed for the patron, listing their overdue item 5. Edit the PASSWORD_RESET notice (Patrons) and preview it: => No record is offered; [passwordreseturl] and [user] are shown as placeholders, as the note above the preview says 6. Edit BOOKING_CONFIRMATION (Bookings): a booking is offered. Preview it without one: => If there are no bookings, the preview says the booking is empty, else that an example booking is used Enter the ID of a booking and preview again: => The preview uses that booking 7. Edit HOLD_SLIP (Circulation): a patron, an item and a hold are offered. Enter the ID of a hold only, and preview it: => The hold slip is previewed with the hold, its patron and its item, and [% branch.branchname %] is its pickup library 8. Enter a card number that does not exist and preview: => The preview says the patron was not found, and uses an example patron 9. Edit a notice using the bespoke syntax, e.g. with <<borrowers.firstname>>, <<borrowers.dateexpiry>> and <<items.content>>, and preview it with the patron of step 2: => Their first name and their item are shown, and the expiry date is formatted as dates are in sent notices 10. Create a basket for a vendor, with an order 11. Edit ACQORDER (Acquisitions): a basket and a vendor are offered, no patron. Add [% basket.basketname %], [% bookseller.name %] and [% FOREACH o IN orders %][% o.ordernumber %] [% END %] to the email template, enter the basket number, and preview it: => The basket, its vendor and its order are shown, and no example patron is used 12. Add an OAI server (Administration > OAI repositories), and edit OAI_HARVEST_REPORT (Catalog): an OAI server is offered. Preview it with the name of the server: => Its name, endpoint, set, data format and record type are shown; the numbers of records are placeholders 13. Edit CHECKOUT: "Items" takes several barcodes. Set the subject of the email template to "Checkout of [% item.barcode %]", its message body to "Hello", "----", "[% item.barcode %]", "----", "Bye" (one per line), enter two barcodes separated by a comma, and preview it: => One message, with Hello, both barcodes and Bye, and a note that the notices for 2 items are combined => The subject is "Checkout of" the first barcode only: as when the notices are sent, the message gets the subject of the first item 14. prove t/db_dependent/Koha/Notice/Template/Preview.t 15. yarn cypress run --spec t/cypress/integration/Tools/NoticePreview_spec.ts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.