This question has been flagged
2 Replies
12263 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 !



Avatar
Discard
Best Answer

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.


Avatar
Discard
Author

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

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

Author

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 ?

Author Best Answer

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 !

Avatar
Discard