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 to override get_pdf() in report.py?

By
Pascal Tremblay
on 2/5/15, 12:52 PM 1,555 views

Hello guys,

Like usually, I'm not able to override a method. Grrr.

In my custom module, I try to override .../addons/report/models/report.py. I want to completely override (replace) the orignal one. 

How could I declare it????

Please and thanks!

Here it's  what I have :

from openerp.osv import osv
from openerp import api

class Report(osv.Model):
    _name = "report"
    _description = "Report"

    @api.v7
    def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None):
        """This method generates and returns pdf version of a report.
        """
       my code here.....

 

UPDATE :

I get this error when trying to print a report.

Traceback (most recent call last): File "/home/odoo/openerp/http.py", line 525, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/odoo/openerp/http.py", line 562, in dispatch result = self._call_function(**self.params) File "/home/odoo/openerp/http.py", line 302, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/odoo/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/home/odoo/openerp/http.py", line 299, in checked_call return self.endpoint(*a, **kw) File "/home/odoo/openerp/http.py", line 791, in __call__ return self.method(*args, **kw) File "/home/odoo/openerp/http.py", line 395, in response_wrap response = f(*args, **kw) File "/home/odoo/addons/web/controllers/main.py", line 949, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/odoo/addons/web/controllers/main.py", line 941, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/home/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo/addons/email_template/wizard/mail_compose_message.py", line 54, in default_get res.get('model'), res.get('res_id'), context=context File "/home/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo/addons/email_template/wizard/mail_compose_message.py", line 103, in onchange_template_id values = self.generate_email_for_composer_batch(cr, uid, template_id, [res_id], context=context)[res_id] File "/home/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo/addons/email_template/wizard/mail_compose_message.py", line 167, in generate_email_for_composer_batch template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, fields=fields, context=ctx) File "/home/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo/addons/email_template/email_template.py", line 514, in generate_email_batch result, format = self.pool['report'].get_pdf(cr, uid, [res_id], report_service, context=ctx), 'pdf' File "/home/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo/addons/report_lapagept/models/report_lapagept.py", line 22, in get_pdf html = self.get_html(cr, uid, ids, report_name, data=data, context=context) AttributeError: 'report' object has no attribute 'get_html'

 

1

Pascal Tremblay

--Pascal Tremblay--
1314
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 2/5/15, 1:14 PM

Here is the new code. It works.

from openerp import api
from openerp import SUPERUSER_ID
from openerp.exceptions import AccessError
from openerp.osv import osv
from openerp.tools import config
from openerp.tools.misc import find_in_path
from openerp.tools.translate import _
from openerp.addons.web.http import request
from openerp.tools.safe_eval import safe_eval as eval

import re
import time
import base64
import logging
import tempfile
import lxml.html
import os
import subprocess
from contextlib import closing
from distutils.version import LooseVersion
from functools import partial
from pyPdf import PdfFileWriter, PdfFileReader


import logging
_logger = logging.getLogger(__name__)


class Report(osv.Model):
    _inherit = "report"
    _name = "report"
    _description = "Report"


    @api.v7
    def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None):
        """This method generates and returns pdf version of a report.
        """
        if context is None:
            context = {}

        _logger.error('HERE = GGGGGG')

Hello, What is the purpose of your modification? I search for a solution to print pdf reports from a batch program, can this function do that? I work in V7, this function is only available in V8. Thanks, David

David Verove
on 2/6/15, 7:17 AM

My goal, for the moment, was only to have different paperformat according to the company (in multi-companies setup). This code is not complete for this. This code is only for the declaration of the override.

Pascal Tremblay
on 2/6/15, 7:19 AM
0

zbik

--zbik--
5976
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/5/15, 1:18 PM

Try and add, but I'm not sure if help:

    @api.v8
    def get_pdf(self, records, report_name, html=None, data=None):
        return self._model.get_pdf(self._cr, self._uid, records.ids, report_name,
                                   html=html, data=data, context=self._context)

 

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

2 follower(s)

Stats

Asked: 2/5/15, 12:52 PM
Seen: 1555 times
Last updated: 3/16/15, 8:10 AM