How to do it...

  1. In this recipe, we add a report on res.partner, which prints a list of books the partner borrowed. We need to add a one2many field on the partner model with relation to the model library.book.rent, as shown in the following example:
class ResPartner(models.Model):
_inherit = 'res.partner'

rent_ids = fields.One2many('library.book.rent', 'borrower_id')

  1. Define a view for your report in reports/book_rent_templates.xml, as follows:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="book_rents_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.internal_layout">
<div class="page">
<h1>Book Rent for <t t-esc="doc.name"/></h1>
<table class="table table-condensed">
<thead>
<tr>
<th>Title</th>
<th>Expected return date</th>
</tr>
</thead>
<tbody>
<tr t-foreach="doc.rent_ids" t-as="rent" >
<td><t t-esc="rent.book_id.name" /></td>
<td><t t-esc="rent.return_date" /></td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
</template>
</odoo>
  1. Use this view in a report tag in reports/book_loan_report.xml, as shown in the following example:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<report id="report_book_rent"
name="my_library.book_rents_template"
model="res.partner"
string="Book Rents"
report_type="qweb-pdf" />
</odoo>
  1. Add both files in the manifest of the add-on and add contacts in depends, so you can open the form view of the partner, as shown in the following example:
...
'depends': ['base', 'contacts'],
'data': [
'views/library_book.xml',
'views/library_member.xml',
...
'reports/book_loan_report.xml',
'reports/book_loan_report_template.xml',
],
...

Now, when opening the partner form view, or when selecting partners in the list view, you should be offered the option to print the book loans in a drop-down menu, as shown in the following image:

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

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