How to do it...

Follow these steps to send a reminder email to the borrower:

  1. Create a new file called my_library/data/mail_template.xml and add the mail template:
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="book_return_reminder" model="mail.template">
<field name="name">Book Return Reminder</field>
<field name="email_from">${object.book_id.create_uid.email}</field>
<field name="email_to">${object.borrower_id.email}</field>
<field name="subject">Reminder for book return</field>
<field name="model_id" ref="my_library.model_library_book_rent"/>
<field name="body_html">
<![CDATA[
<p>Dear ${object.borrower_id.name},</p>
<p>You had rented the
<b>${object.book_id.name}</b> book on ${format_date(object.rent_date)}
<br/>
The due date of book is <b style="color:red;">${format_date(object.return_date)}.</b>
</p>
<br/>

<p>Best regards,
<br/> Librarian</p>
]]>
</field>
</record>
</odoo>
  1. Register the template file in the manifest file:
...
'data': [
'security/groups.xml',
'security/ir.model.access.csv',
'views/library_book.xml',
'views/library_book_categ.xml',
'views/library_book_rent.xml',
'data/mail_template.xml'
],
...

  1. Add a Send reminder button in the form view of the library.book.rent model to send the email:
...
<header>
<button name="book_return" string="Return the Book" states="ongoing" type="object"/>
<button name="book_return_reminder" string="Send reminder" states="ongoing" type="object"/>
<field name="state" widget="statusbar"/>
</header>
...
  1. Add the book_return_reminder() method in the library.book.rent model:
...
def book_return_reminder(self):
template_id = self.env.ref('my_library.book_return_reminder')
self.message_post_with_template(template_id.id)

Update the my_library module to apply the changes. This will add a Send reminder button in the form view of the library.book.rent model. When they click on the button, followers will get the following message:


The procedure shown in this recipe is useful when you want to send updates to your customer through emails. Because of the Jinja template, you can send emails dynamically based on individual records.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset