Odoo Help

2

2
2 Answers
1
Avatar

Serpent Consulting Services Pvt. Ltd. India

--Serpent Consulting Services Pvt. Ltd.--
Serpent Consulting Services Pvt. Ltd.
http://www.serpentcs.com
5103
| 7 6 10
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. is an Official Odoo Partner, working on Odoo ever since 2007, experience of 11+ years and witnessed the growth of Odoo.

We are a team of 80+ experts on various verticals. Our portfolio of products can be seen at http://www.serpentcs.com and http://www.serpentcs.in

Our Expertise and Services:

  • Odoo Support

  • Odoo Development

  • Odoo Training

  • Odoo Migration

  • Odoo Implementation

  • Odoo Consulting

Our 290+ Apps on Appstore : https://apps.odoo.com/apps/modules/browse?author=Serpent Consulting Services Pvt. Ltd.

Thanks.

Serpent Consulting Services Pvt. Ltd. India
11/14/13, 1:59 AM

Hello Julian Solorzano,

You may make take reference of following code.

The following code generates the report and creates the attachment.

def cover_print(self, cr, uid, ids, context=None):
    attachment_obj = self.pool.get('ir.attachment')
    for record in self.browse(cr, uid, ids, context=context):
        ir_actions_report = self.pool.get('ir.actions.report.xml')
        matching_reports = ir_actions_report.search(cr, uid, [('name','=','report_service_name_given_in_xml')])
        if matching_reports:
            report = ir_actions_report.browse(cr, uid, matching_reports[0])
            report_service = 'report.' + report.report_name
            service = netsvc.LocalService(report_service)
            (result, format) = service.create(cr, uid, [record.id], {'model': self._name}, context=context)
            eval_context = {'time': time, 'object': record}
            if not report.attachment or not eval(report.attachment, eval_context):
                # no auto-saving of report as attachment, need to do it manually
                result = base64.b64encode(result)
                file_name = re.sub(r'[^a-zA-Z0-9_-]', '_', 'Your Report Name')
                file_name += ".pdf"
                attachment_id = attachment_obj.create(cr, uid,
                    {
                        'name': file_name,
                        'datas': result,
                        'datas_fname': file_name,
                        'res_model': self._name,
                        'res_id': record.id,
                        'type': 'binary'
                    }, context=context)
    return True

Hope this will help you.

Thanks,

Serpent Consulting Services.

4 Comments
Zenpar S.A. de C.V., Julian Solorzano Mexico
11/14/13, 2:13 AM

Perfect, thanks

Sayed Anisul Hoque Bangladesh
9/18/15, 4:04 PM

matching_reports = ir_actions_report.search(cr, uid, [('name','=','report_service_name_given_in_xml')]) --> this returning as "matching_reports::: []" can you please tell why empty list is created ?? moreover can you please tell what is report_service_name_given_in_xml ?

Sayed Anisul Hoque Bangladesh
10/15/15, 7:25 AM

report_service = 'report.' + report.report_name service = netsvc.LocalService(report_service) (result, format) = service.create(cr, uid, [record.id], {'model': self._name}, context=context) Above line was giving me error since the openerp.netsvc.LocalService() function is deprecated. This could be solved as per below editing result, format = openerp.report.render_report(cr, uid, [record.id], report.report_name, {'model': self._name}, context=context)

Sebin Siby India
1/10/18, 3:36 AM

From where I have to call this function?

I have a wizard for the report to be generated.

1
Avatar

Navrang Oza India

--Navrang Oza--
Navrang Oza
853
| 3 2 8
Gandhinagar, India
--Navrang Oza--

Having 13+ years of experience in Odoo, Magento, Wordpress, Android, PHP Expert.

Skype : acespritech

Email : info@acespritech.com

Navrang Oza India
11/14/13, 2:01 AM

Hi,

I think Invoices report is the best example of attaching a generated report in OpenERP interface.
You can get it from here.

<report
    auto="False"
    id="account_invoices"
    model="account.invoice"
    name="account.invoice"
    rml="account/report/account_print_invoice.rml"
    string="Invoices"
    attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
    attachment_use="True"
    usage="default"
    />

To save report as attachment attachment and attachment_use are compulsory or you can manually add your generated report to attachment by following steps :

  1. Generate report and save in your file system.
  2. Then go to the form view of the record and click on Attachment(s) on top and add there. Below is the screenshot.
  3. You can see all your attachments which are saved in OpenERP in Knowledge -> Documents -> Documents.

image description

Ask a Question
Keep Informed
1 follower(s)
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