Odoo Help

0

How to make downloading a pdf file

By
Matthieu
on 6/7/16, 5:36 AM 1,145 views

Hello,


I'm currently creating an Odoo 9 module and I've got a Class with a report_coupon function called by a button.

Here is my class :

class loyalty_coupon(models.Model):

    _name = 'loyalty.coupon'

    _columns = {

        'name': fields.char('Name', size=32, select=1, required=True, help='An internal identification for this loyalty coupon'),

       'loyalty_program_id': fields.many2one('loyalty.program', 'Loyalty Program', help='The Loyalty Program this coupon belongs to'),

       'reduction': fields.float('Reduction', help='The amount of reduction of this coupon in EUR'),

       'date': fields.date('Date Limit', help='The date limit of the coupon'),

       'limited': fields.boolean('Limited', help='The kind of coupon'),

       'used': fields.boolean('Used', help='The state of the coupon, used or not used'),

       'barcode': fields.char('Barcode', help="International Article Number used for coupon identification.", oldname='ean13', copy=False),

    }

    @api.one

    def report_coupon(self):

       _logger.info("IMPRESS")

I want this function to allow the user to download a pdf file generated (composed of attributes of the class).

How can I do this ? :)


Thank you in advance for your replies and help !



1

Hi,

Please make one button inside your form. i.e. 

<button name="report_coupon"  type="object" string="Download PDF" />

According to the button defination you need to define one method inside your model with following lines of code. thats it.

@api.multi
def report_coupon(self):
return self.env['report'].get_action(self, 'modulename.xmlidofyourreport') #modulename.custom_report_coupon

  

Above line of code will give the option to download pdf report on clicking of that button.

Please try it in your module.


Well, thank you, it's better but i've got an error :

raise ValueError('External ID not found in the system: %s' % (xmlid))

ValueError: External ID not found in the system:

account.report_coupon

Matthieu
on 6/10/16, 4:16 AM

I have updated my answer, you just need to give external ID of your report. thats it.

Emipro Technologies Pvt. Ltd.
on 6/10/16, 6:39 AM

Thank you ! Now, a new error appeared :

Bad Report ReferenceThis report is not loaded into the database: loyalty.report_coupon

Why is it still not working ? What's wrong ?

Matthieu
on 6/13/16, 5:29 AM
0
Matthieu
On 6/9/16, 10:17 AM

Currently, I have the following reports and records in an XML file called "report.xml" :

<template id="report_coupon">

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

   <div class="page">

    <div class="row">

     <h3>Title</h3>

    </div>

   </div>

  </t>

</template>

<template id="report_without_prices">

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

   <t t-foreach="doc_ids" t-as="doc_id">

    <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'account.coupon')"/>

   </t>

  </t>

</template>

In my view, I have

<report

  id="custom_report_coupon"

  model="account.invoice"

 string="Coupons"

  report_type="qweb-pdf"

  name="account.report_coupon"

  attachment_use="False"

  file="account.report_coupon"

/>

So, my question is how to call this from a button and allow the user to download a pdf file of this view ?


Thanks in advance !

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)

Stats

Asked: 6/7/16, 5:36 AM
Seen: 1145 times
Last updated: 6/11/16, 5:38 PM