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 could I use « t-if » in a qweb report to test the paper format?

By
Pascal Tremblay
on 2/24/15, 8:20 AM 2,480 views

hello all,

How could I test the paperformat of the actual report with « t-if »?

I'm already able to test many thing, but I don't find for the paperformat.

Idea?

Thanks

UPDATED - UPDATED - UPDATED - MANY TIMES :

In  try this code in my qweb /home/odoo-test/addons/report_lapagept/views/report_saleslines_lapagept.xml.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="report_lapagept.report_saleslines_pt" inherit_id="point_of_sale.report_saleslines">
            <xpath expr="//div[@class='page']" position="replace">
                <div style="font-family: Ubuntu;" class="page">
                    <div class="row">
                        <div class="col-xs-12" style="padding-top: 8px;">
                            <h1><span t-if="not paperformat">There is no paperformat here</span></h1>
                            <h1><span t-if="paperformat">There is a paperformat here</span></h1>
                            <h3><span t-esc="o.user_id.company_id.name" /> - Saleslines</h3>
                        </div>
                    </div>

 

And this code in /home/odoo-test/addons/report_lapagept/report_saleslines_pt.py.

import logging
_logger = logging.getLogger(__name__)
from openerp import api, models
class report_saleslines_pt(models.AbstractModel):
    _name = 'report.point_of_sale.report_saleslines'
    _template = 'point_of_sale.report_saleslines'

    @api.multi
    def render_html(self, data=None):

        report_obj = self.env['report']
        report = report_obj._get_report_from_name('point_of_sale.report_saleslines')
        if not report.paperformat_id:
            paperformat_obj = self.env.user.company_id.paperformat_id
            _logger.error('REPORT_SALES_LINES :: NO PAPER HERE IN THIS REPORT... WEIRD!  ' + str(paperformat_obj))
        else:
            paperformat_obj = report.paperformat_id
            _logger.error('REPORT_SALES_LINES :: LE PAPIER POUR CE RAPPORT EST :  ' + str(paperformat_obj))
        docargs = {
            'paperformat': paperformat_obj,
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        return report_obj.render('point_of_sale.report_saleslines', docargs)

report_saleslines_pt()

 

I get this error when trying to get the PDF.

raceback (most recent call last): File "/home/odoo-test/addons/report_lapagept/controllers/control_pt.py", line 130, in report_download response = ReportController().report_routes(reportname, docids=docids, converter='pdf') File "/home/odoo-test/openerp/http.py", line 395, in response_wrap response = f(*args, **kw) File "/home/odoo-test/addons/report/controllers/main.py", line 65, in report_routes pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context) File "/home/odoo-test/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo-test/addons/report_lapagept/models/report_lapagept.py", line 165, in get_pdf paperformat, specific_paperformat_args, save_in_attachment File "/home/odoo-test/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/odoo-test/addons/report/models/report.py", line 390, in _run_wkhtmltopdf command_args.extend(self._build_wkhtmltopdf_args(paperformat, spec_paperformat_args)) File "/home/odoo-test/addons/report/models/report.py", line 513, in _build_wkhtmltopdf_args if paperformat.format and paperformat.format != 'custom': AttributeError: 'int' object has no attribute 'format'

 

answer updated, demo and small correction in code

zbik
on 2/24/15, 11:01 AM

change .... 'paperformat': paperformat_obj, ... to .... 'pformatFOO': paperformat_obj, ... names conflict???

zbik
on 2/24/15, 4:16 PM

In my system works without problems!

zbik
on 2/24/15, 4:20 PM

Thanks a lot. I will disable all my modules. Almost sure the problem come for there. I will come back later.

Pascal Tremblay
on 2/24/15, 4:34 PM
1

zbik

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


zbik
On 2/24/15, 9:36 AM

Custom Report with defined paperformat value, like this:

from openerp import api, models

class ParticularReport(models.AbstractModel):
    _name = 'report.module.report_name'
    @api.multi
    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name('module.report_name')
        if not report.paperformat_id:
            paperformat_obj = self.env.user.company_id.paperformat_id
        else:
            paperformat_obj = report.paperformat_id
        docargs = {
            'doc_paperformat': paperformat_obj
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        return report_obj.render('module.report_name', docargs)

in report:

<span t-esc="doc_paperformat.name"/>
<span t-if="doc_paperformat.id == 32">STMT</span>

Ok, if I understand correctly, I have to modify also the python code. Not only the xml qweb file. Thanks, I come back soon.

Pascal Tremblay
on 2/24/15, 11:04 AM

change '32' to 32

zbik
on 2/24/15, 11:10 AM

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

3 follower(s)

Stats

Asked: 2/24/15, 8:20 AM
Seen: 2480 times
Last updated: 3/16/15, 8:10 AM