0

when clicking the Print Survey button (Human Resources - Apraissal - Interview Requests), the standard output is HTML (action_print_survey method). I want to change output to PDF. I couldn't find on Odoo configuration nor standard structure for Qweb reports the way they do it as the standard stands (template yes, menu no, python wrapper no). I tried to right a wrapper but it doesn't work. Any ideas? Thanks in advance Gustavo

jack10bells
  • 1
  • 1
  • 4
  • If you need to create a new qweb report for that, I can help. – Kenly Dec 21 '15 at 08:16
  • All I want to do is add a new button (I already know how to do that) to print the survey as PDF, instead of the standard HTML output, using the same qweb template (if possible). It should be possible to do that with a simple configuration, without changing Qweb templates or redeveloping the whole report. Thanks – jack10bells Jan 08 '16 at 13:55
  • The template is "survey_templates.xml" – jack10bells Jan 08 '16 at 14:04

2 Answers2

0

Report

Every report must be declared by a report action.

For simplicity, a shortcut <report> element is available to define a report, rather than have to set up the action and its surroundings manually. That <report> can take the following attributes:

id :

the generated record's external id

name (mandatory):

only useful as a mnemonic/description of the report when looking for one in a list of some sort

model (mandatory):

the model your report will be about

report_type (mandatory) :

  • either qweb-pdf for PDF reports or qweb-html for HTML

report_name :

the name of your report (which will be the name of the PDF output)

groups:

Many2many field to the groups allowed to view/use the current report

attachment_use:

if set to True, the report will be stored as an attachment of the record using the name generated by the attachment expression; you can use this if you need your report to be generated only once (for legal reasons, for example)

attachment:

python expression that defines the name of the report; the record is acessible as the variable object

Example :

<report
    id="account_invoices"
    model="account.invoice"
    string="Invoices"
    report_type="qweb-pdf"
    name="account.report_invoice"
    file="account.report_invoice"
    attachment_use="True"
    attachment="(object.state in ('open','paid')) and
        ('INV'+(object.number or '').replace('/','')+'.pdf')"
/>

Reference Link : https://www.odoo.com/documentation/8.0/reference/reports.html

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Jainik Patel
  • 2,284
  • 1
  • 15
  • 35
  • Thanks for your help. All I want to do is to add a new button (I already know how to do that) to print the survey as PDF, instead of the standard HTML output, using the same qweb template (if possible). It should be possible to do that with a simple configuration, without changing Qweb templates or redeveloping the whole report. The template is "survey_templates.xml" – jack10bells Jan 08 '16 at 13:56
  • There is no definition for the original html output report. It is launched by controllers. I would like to be able to output as pdf without doing a redeveloping of this functionality. Thanks – jack10bells Jan 13 '16 at 19:51
0

@Gustavo That is not an html report, it's a rendered template in response to the request for print the survey using that button action. That's why you couldn't find any declaration for the report but you could easily do it by changing the method definition of the model survey.survey like:

def action_print_survey(self, cr, uid, ids, context=None):
    context = dict(context or {}, active_ids=ids, active_model=self._name)
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'module.survey_print',
        'context': context,
    }

Also you need to define the report module.survey_print to use the original template. For that you could see how to do it on: https://www.odoo.com/fr_FR/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

aekis.dev
  • 2,626
  • 1
  • 12
  • 19
  • @Alex, I've done things according your instructions but I got the following error: **QWebException: 'NoneType' object has no attribute '_fields'** What should I look for to find the error? (I don't know how to post here the entire code I wrote) – jack10bells Jan 22 '16 at 17:49
  • You could put it on a gist and left here the link – aekis.dev Jan 22 '16 at 17:51
  • That means that your report is getting rendered. Let me check that error in the report template and I will post it – aekis.dev Jan 22 '16 at 18:06
  • Hi @Axel, have you found anything about this issue? – jack10bells Feb 05 '16 at 14:14
  • Today I was implementing something like this. All depends of what you need. The survey format without answer values is easy, but if you need to print the answer values of already answered survey that's more hard than I first though. I already have a working solution but the matrix type of question is not working properly yet. It is repeating the matrix for every answer value of the matrix questions – aekis.dev Apr 04 '16 at 19:50