How to do it...

In order to print the book loan report with report_py3o, you need to do the following:

  1. In my_module/data, add a file called py3o_server.xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="local_py3o_server" model="py3o.server">
<field name="url">http://localhost:8765/form</field>
</record>
</odoo>
  1. In my_module/reports, add a file called book_loan_report.xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="report_book_loans_py3o" model="ir.actions.report.xml">
<field name="name">Book Loans</field>
<field name="model">library.member</field>
<field name="report_name">library.member.loans</field>
<field name="report_type">py3o</field>
<field name="py3o_filetype">pdf</field>
<field name="py3o_server_id" ref="local_py3o_server"/>
<field name="module">my_module</field>
<field
name="py3o_template_fallback">reports/book_loans.odt</field>
</record>

</odoo>
  1. Add both files to the manifest of the addon, and declare a dependency on report_py3o:
{
'name': 'Chapter 14 code the py3o recipe',
'depends': ['mail', 'report_py3o'],
'data': [
'data/py3o_server.xml',
'reports/book_loan_report.xml'
# ...
],
}
  1. Create an empty LibreOffice ODT document and save it in reports/book_loans.odt
  2. Place the cursor at the beginning of the document, and choose Insert > Hyperlink... in the menu
  3. In the dialog, set the following as shown in the screen capture below:
    • Targetpy3o://for="member in objects"
    • Text: for="member in objects"
  1. After the hyperlink, set the format as Title, and type Book loans for
  2. With the cursor after "for", choose Insert > Field > More Fields... (Ctrl+F2) in the menu
  3.  In the dialog, choose the Variables tab:
    • Set the Type to User Field
    • Set Name to py3o.member.name
    • Set Value to Member Name
    • Click on the Insert button:
  1. Insert a table with two columns and four rows
  2. In the first row, type Book title and Expected return date
  3. In the second row, insert a hyperlink as you did in step 6. The Target is py3o://for="loan in member.loan_ids" and the Text is for="loan in member.loan_ids"
  4. In the third row, insert these to the user fields as you did in step 9:
    • In the first column, the Name is py3o.loan.book_id.name and the Value is Book Title
    • In the second column, the Name is py3o.loan.expected_return_date and the Value is Expected Return Date
  1. In the last row, insert a hyperlink as you did in step 12. The Target is py3o:///for and the text is /for
  2. After the table, insert a hyperlink as you did in step 14 with the same Target and Text
In steps 14 and 15, pay attention to the number of slashes: there are three consecutive slashes before for.

Here's what your document should look like:

To test your report, install your module. Display a library member and select Print > Book Loans.

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

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