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 instantiate a paperformat from the model report.paperformat?

By
Pascal Tremblay
on 2/24/15, 7:26 PM 1,087 views

Hello all of you,

I need to instAntiate a paperformat in my custom module class.

I will return this instance from a function

Thanks for your idea.

UPDATED 1 --------

May be I need a line like this one. I will try to complete it. Could you?

defaultpaper = self.pool.get('ir.model.data').....

UPDATED 2 ----------

We want to attrib this paperformat to a variable :

Our code :

        if model == 'pos.order':
            cie_pos_paperformat = user.company_id.x_pos_paperformat
            
            if cie_pos_paperformat:
                paperformat = cie_pos_paperformat
            elif report.paperformat_id:
                paperformat = report.paperformat_id
            else:
                paperformat = {
                        'us_stmt': ref('report_lapagept.paperformat_us_stmt'),
            }.get(company.rml_paper_format) or ref('report.paperformat_euro')

 

We get an error for the moment...

 

UPDATE 3 ------------------------------

Our new code :

       if modelll == 'pos.order':
            cie_pos_paperformat = user.company_id.x_pos_paperformat
            if cie_pos_paperformat:
                paperformat = cie_pos_paperformat
            elif report.paperformat_id:
                paperformat = report.paperformat_id
            else:
                ref = partial(self.pool['ir.model.data'].xmlid_to_res_id, cr, SUPERUSER_ID)
                paperformat = ref('report_lapagept.paperformat_us_stmt')

     _logger.error('paper :' + paperformat)

We get error :

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'

In the log :

  • Usually, if I log a paperformat instance, I get this :

ERROR : test openerp.addons.report_lapagept.models.report_lapagept: paper : report.paperformat(28,)

  • For the moment, we get this, and it is not a paperformat instance. Just an integer of th ID, I think. :

ERROR test openerp.addons.report_lapagept.models.report_lapagept: paper : 28

Idea? Thanks

See init in class res_company in report/models/report.paperformat.py, help you?

zbik
on 2/25/15, 7:21 AM

answer updated, If is only int ID then... browse, hope you helps

zbik
on 2/26/15, 8:25 AM
1

zbik

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


zbik
On 2/26/15, 3:36 AM

Try this:

   if model == 'pos.order':
            cie_pos_paperformat = user.company_id.x_pos_paperformat
            
            if cie_pos_paperformat:
                paperformat = cie_pos_paperformat
            elif report.paperformat_id:
                paperformat = report.paperformat_id
            else:
                ref = partial(self.pool['ir.model.data'].xmlid_to_res_id, cr, SUPERUSER_ID)
                ref_id = ref('report_lapagept.paperformat_us_stmt') or ref('report.paperformat_euro')
                paperformat = self.pool['report.paperformat'].browse(cr, SUPERUSER_ID, ref_id, context=context)

BIG THANKS MISTER!

Pascal Tremblay
on 2/26/15, 8:56 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

1 follower(s)

Stats

Asked: 2/24/15, 7:26 PM
Seen: 1087 times
Last updated: 3/16/15, 8:10 AM