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

How do I stop the automatic download of a report?

By
AJ Schrafel Paper Corp
on 5/6/13, 2:25 AM 1,396 views

I created a custom module with the following code, everything works except for the fact that I do not want the report to be downloaded by the client when I run the function. How do I stop a report from being downloaded automatically?

def cover_print(self, cr, uid, ids, context=None):
    for numbers in self.browse(cr, uid, ids, context=context):
         record = numbers
    ir_actions_report = self.pool.get('ir.actions.report.xml')
    matching_reports = ir_actions_report.search(cr, uid, [('id','=',record.report_id.id)])
    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 = record.name_get()[0][1]
            file_name = re.sub(r'[^a-zA-Z0-9_-]', '_', file_name)
            file_name += ".pdf"
            self.pool.get('ir.attachment').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
0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 5/7/13, 6:02 PM

I found that if i chage the code to be:

result = self.pool.get('ir.attachment').create(cr, uid,
                                                  {
                                                   'name': file_name,
                                                   'datas': result,
                                                   'datas_fname': file_name,
                                                   'res_model': self._name,
                                                   'res_id': record.id,
                                                   'type': 'binary'
                                                  },
                                                  context=context)

Then the report is not automatically downloaded, which is fine for my customer modules but does not really help me for base/ addon modules. Over writing those would make updates over complicated.

Is there a better solution?

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: 5/6/13, 2:25 AM
Seen: 1396 times
Last updated: 10/16/15, 1:15 PM