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

Report custom function

By
jean44
on 8/21/14, 11:11 PM 734 views

Hello

Please I want to add a function in the report code so I can call it when the report is generated, it works for simple functions that returns simple 'char', but when I put this code it didn't work, for example I want to create some data in the  table 'expense.virement': 

class payment(report_sxw.rml_parse):

     def __init__(self, cr, uid, name, context):
        super(payment, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({'time': time, 'convert':self.convert, })

    def convert(self, amount, cur):
        vir = self.pool.get("expense.virement")
        data = {'col1' : 123, 'col2' : "33", 'col3' : '1223478', 'col4' : '1234' }
        vir.create(cr, uid, data)
        return 'Ok'

report_sxw.report_sxw('report.expense.payment', 'expense.ram', 'addons/expense_ram/report/payment.rml',parser=payment)

0
Lucio
On 8/22/14, 1:12 PM

You cannot use the database cursor (i.e. cr) nor the user id (i.e. uid) in the definition of the function convert.
You have to add them to the localcontext first. 

Try:

     def __init__(self, cr, uid, name, context):
        super(payment, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({'time': time, 'convert':self.convert, 'cr': cr, 'uid', uid, })

    def convert(self, amount, cur):
        vir = self.pool.get("expense.virement")
        data = {'col1' : 123, 'col2' : "33", 'col3' : '1223478', 'col4' : '1234' }
        vir.create(self.cr, self.uid, data)
        return True

 

Hope it helps!

Thanks, I tried what you said but it didn't work

jean44
on 8/23/14, 4:56 PM

Thanks, I tried what you said but it didn't work

jean44
on 8/23/14, 4:56 PM

now it works thank you :)

jean44
on 8/23/14, 5:39 PM
0
jean44
On 8/22/14, 7:24 AM

How I can fix that please ?

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 8/22/14, 11:36 AM

In convert method, you have to "return data" to return the data. I think you can return any python object in method for report.
 

Thank you for your reply, I can't understand what do you mean ? why I should return the data ? I just want to insert some data to another table when the report is called

jean44
on 8/23/14, 5:10 PM

Ok, sorry I missed your point. My common use case is that when report is called the data is already in database. I thought your problem is about returning the data.

Ben Bernard
on 8/24/14, 8:03 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: 8/21/14, 11:11 PM
Seen: 734 times
Last updated: 3/16/15, 8:10 AM