Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Problem with printing custom report

By
Matthieu
on 6/14/16, 4:40 AM 333 views

Hello,

After many things tried, I've still a problem.

I'm developping a custom loyalty coupon module and I want to print them.

I've got a popup view with a preview of a coupon that seems like this :

http://i.imgur.com/JcoHQit.png

In this picture, the print button is in a file called "views.xml" and the code is :

<button string="Print" icon="gtk-print" type="object" name="%(action_report_coupon)d" class="oe_highlight"/>

In the same class, I've created a declaration for my report as this :

<report

  id="action_report_coupon"

 model="loyalty.coupon"

  report_type="qweb-pdf"

  string="Print"

  name="loyalty.report"

  file="loyalty.report"

/>

loyalty, here, is the name of the python file loyalty.py (the model class for my module) which contains the class loyalty.coupon.

In another file, called by the report above, there is my template for the pdf that will be print by clicking the previous button. Its name is "report.xml" and its code is :

<?xml version="1.0" encoding="utf-8"?>

<odoo>

<template id="loyalty.report_coupon_document">

  <t t-call="report.external_layout">

   <div class="page">
    <!-- content -->

   </div>

  </t>

</template>

<template id="report_coupon">

  <t t-call="report.html_container">

   <t t-foreach="docs" t-as="o">

    <t t-call="loyalty.report_coupon_document" t-lang="o.lang"/>

   </t>

  </t>

</template>

</odoo>

But, it's still not working. I don't understand where the problem is, even if it's possible to read an error message when clicking on the button that is :

AttributeError: 'loyalty.coupon' object has no attribute '354'


Please, help me. The lack of information about this is a big problem for me, that is a beginner with Odoo.


Thank you so much in advance !

I forgot something : I have a class in "loyalty.py" with the render_html function for the report :

class reportCoupon(models.AbstractModel):

_name = 'report.loyalty.report_coupon'

@api.multi

def render_html(self, data):

docargs = {

'doc_ids': self.ids,

'doc_model': 'loyalty.coupon',

'docs': self.env['loyalty.coupon'].browse(self.ids),

'Date': fields.date.today(),

}

return self.env['report'].render('loyalty.report_coupon', values=docargs)

Matthieu
on 6/14/16, 5:41 AM

At /report/pdf/account.report_invoice/1, there is there pdf version of the account report.

But, when I go at /report/pdf/loyalty.report_coupon/1, there is nothing at all. just an "Internal Server Error".

And in the log, I can see "IndexError: list index out of range".

When I go at not existing url as /report/pdf/not_existing.report_test/1, it's the same error.

So maybe, I think the controller don't create the report to print at all ?

How can I solve that ?

Matthieu
on 6/14/16, 10:54 AM
0
Matthieu
On 6/15/16, 10:13 AM

I've solved my problem. Now I can print coupons as needed.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/14/16, 4:40 AM
Seen: 333 times
Last updated: 6/15/16, 10:13 AM