Skip to Content
Menu
This question has been flagged
3 Replies
10898 Views

I have this function in my python file:


    def get_employee_lines(self, cr, uid, ids, company_id, date_start, date_end):
print ('--------------------MOMO----------------------')
payslip_line = self.pool.get('hr.payslip')
print payslip_line
print company_id
print date_start
print date_end
obj_ids = payslip_line.search(cr, uid,ids, [ ('date_from', '=', date_start), ('date_to', '=', date_end)])
res = obj.read( obj_ids, ['employee_id'], context)
print res['employee_id']
return res


And, i have called it in my RML:

[[ repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o') ]] 

And in front of the cell:

[[ o.employee_id]]

But, i have gotten this error:


2015-08-26 09:23:22,979 4118 ERROR company openerp.tools.safe_eval: Cannot eval "repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o')"
Traceback (most recent call last):
File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval
return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
File "", line 1, in <module>
TypeError: get_employee_lines() takes exactly 7 arguments (4 given)
2015-08-26 09:23:22,980 4118 ERROR company openerp.tools.safe_eval: Cannot eval 'o.employee_id'
Traceback (most recent call last):
File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval
return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
File "", line 1, in <module>
NameError: name 'o' is not defined

Any tips?



Avatar
Discard
Author

Buy why!!!!! Really i need an answer why dont you help me instead of this

Best Answer

Drees,

try this:
1) take a list, res_list=[] in you py file

2) After "res = obj.read( obj_ids, ['employee_id'], context)", add,

         'res_list.append(res)'

3) and then replace [return res], with  [return res_list]

3) in your rml, replace "o.employee_id" wih "o['employee_id']"

Hope it helps....

Avatar
Discard
Author Best Answer

 Thanks a lot to Pawan :)

Here is the answer friends!!

Python:


def get_employee_lines(self, company_id, date_start, date_end, context=None):

print ('--------------------MOMO----------------------')

res_list=[]

payslip_line = self.pool.get('hr.payslip')

print payslip_line

print company_id

print date_start

print date_end

obj_ids = payslip_line.search(self.cr, self.uid, [ ('date_from', '=', date_start), ('date_to', '=', date_end)])

print obj_ids

for res in payslip_line.read(self.cr, self.uid, obj_ids, ['id', 'employee_id'], context=False):

res_list.append(res['employee_id'][1])

return res_list

RML:

[[ repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o') ]]

[[ o['employee_id'] ]]

Regards.




Avatar
Discard

Drees,
In,
, 2015-08-26 10:28:44,730 5779 ERROR company openerp.tools.safe_eval: Cannot eval "repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end, 'o') )"
you have wrongly called the function, it should be like:
"repeatIn (get_employee_lines( example.company_id, example.date_start, example.date_end), 'o' )
[NOTE: 'o' should be out of the function brackets...]

Author

Pawan please need your help: I have corrected it again and i have gotton the same error

Please update your error.... Drees

Author

I have updated it after modifying all what you said

Author

Python: def get_employee_lines(self, cr, uid, ids, company_id, date_start, date_end): print ('--------------------MOMO----------------------') res_list=[ payslip_line = self.pool.get('hr.payslip') print payslip_line print company_id print date_start print date_end obj_ids = payslip_line.search(cr, uid,ids, [ ('date_from', '=', date_start), ('date_to', '=', date_end)]) res = obj.read( obj_ids, ['employee_id'], context) res_list.append(res) return res_list

Ok dress, update your py function defination with:
"def get_employee_lines(self, company_id, date_start, date_end):"
and remove space in "o ['employee_id']"...

Author

Here is a link to the rml: http://www.zupimages.net/viewer.php?id=15/35/31mj.png

Author

Pawan when i have eliminated cr, uid, and ids i got this: 2015-08-26 10:59:40,994 8469 INFO company werkzeug: 127.0.0.1 - - [26/Aug/2015 10:59:40] "POST /web/action/load HTTP/1.1" 200 - ----------------------test-------------------------- --------------------MOMO---------------------- browse_record(res.company, 1) 01/08/2015 31/08/2015 2015-08-26 10:59:41,305 8469 ERROR company openerp.tools.safe_eval: Cannot eval "repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o')" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in File "/opt/openerp/v7/addons/seetek_example/report/journal_paie.py", line 46, in get_employee_lines obj_ids = payslip_line.search(cr, id, ids, [ ('date_from', '=', date_start), ('date_to', '=', date_end)]) NameError: global name 'cr' is not defined 2015-08-26 10:59:41,306 8469 ERROR company openerp.tools.safe_eval: Cannot eval "o['employee_id']" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 'o' is not defined

Dress, in py now everywhere in place of cr and uid, you have to use self.cr, self.uid...........

and in search(), we don't need "ids" anyway...

Author
browse_record(res.company, 1) 01/08/2015 31/08/2015 2015-08-26 11:05:17,811 8574 ERROR company openerp.tools.safe_eval: Cannot eval "repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o')" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in File "/opt/openerp/v7/addons/seetek_example/report/journal_paie.py", line 46, in get_employee_lines obj_ids = payslip_line.search(self.cr, self.uid, self.ids, [ ('date_from', '=', date_start), ('date_to', '=', date_end)]) File "/opt/openerp/v7/server/openerp/osv/orm.py", line 2372, in search return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count) File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4935, in _search query = self._where_calc(cr, user, args, context=context) File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4761, in _where_calc e = expression.expression(cr, user, domain, self, context) File "/opt/openerp/v7/server/openerp/osv/expression.py", line 646, in __init__ self.parse(cr, uid, context=context) File "/opt/openerp/v7/server/openerp/osv/expression.py", line 746, in parse self.stack = [ExtendedLeaf(leaf, self.root_model) for leaf in self.expression] File "/opt/openerp/v7/server/openerp/osv/expression.py", line 532, in __init__ self.check_leaf() File "/opt/openerp/v7/server/openerp/osv/expression.py", line 588, in check_leaf raise ValueError("Invalid leaf %s" % str(self.leaf)) ValueError: Invalid leaf 5 2015-08-26 11:05:17,880 8574 ERROR company openerp.tools.safe_eval: Cannot eval "o['employee_id']" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 'o' is not defined

Drees, NO "ids" should be passed to search() method, it doesn't accept ids nor self.ids...

Author
browse_record(res.company, 1) 01/08/2015 31/08/2015 2015-08-26 11:18:02,951 9606 ERROR company openerp.tools.safe_eval: Cannot eval "repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o')" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in File "/opt/openerp/v7/addons/seetek_example/report/journal_paie.py", line 47, in get_employee_lines res = payslip_line.read( obj_ids, ['employee_id'], context=False) TypeError: read() takes at least 4 arguments (4 given) 2015-08-26 11:18:02,953 9606 ERROR company openerp.tools.safe_eval: Cannot eval "o['employee_id']" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 'o' is not defined
Author

Pawan please you still there??

please replace your "payslip_line.read( obj_ids, ['employee_id'], context=False)" with:
for res in payslip_line.read(self.cr, self.uid, obj_ids, ['id', 'employee_id'], context=False):
res_list.append(res)
remove res_list.append() which you added earlier
This loop is added because you may have more than one id returned from search method.
and cause of error was , you didn't passed self.cr and self.uid.

Author

Pawan, it works but i got this in the terminal: browse_record(res.company, 1) 01/08/2015 31/08/2015 [1] 2015-08-26 11:31:05,767 10372 ERROR company openerp.tools.safe_eval: Cannot eval "o['employee_id']" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 'o' is not defined and in the report: [{'o': {'employee_id': (2, u'Abdelwahed Rihene'), 'id': 1}}] but i need only Abdelwahed Rihene

Author

Pawan i get this : [{'o': u'Abdelwahed Rihene'}] !!! how can i change it to this: Abdelwahed Rihene please

use this 'o' key to get this value, as a dictionary...

Author

Pawan my friend you still here??

Author

Please pawan my friend i need your help extremely: In my field employee_id i have this result: [{'o': u'Abdelwahed Rihene'}, {'o': u'Amine Msakni'}] wben i want to get ABdelwahed Rihene in a cell and amine msakni in an other cell please friend how can i get the name in that json and how can i create automatically a new td please please help me

Drees, you can try by keeping,
o['employee_id'][0]['o'] in one cell and
o['employee_id'][1]['o'] in nother one...

Author

Pawan please it doesnt work nothing had changed

Drees, can u pls show what you are getting in return statement from python function.?

Author

Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 's' is not defined

Author

sorry i have changed the o to s

i m not getting you, can u pls show me res_list values...

Author

here is my function pawan: def get_employee_lines(self, company_id, date_start, date_end, context=None): print ('--------------------MOMO----------------------') res_list=[] payslip_line = self.pool.get('hr.payslip') print payslip_line print company_id print date_start print date_end obj_ids = payslip_line.search(self.cr, self.uid, [ ('date_from', '=', date_start), ('date_to', '=', date_end)]) print obj_ids for res in payslip_line.read(self.cr, self.uid, obj_ids, ['id', 'employee_id'], context=False): print res['employee_id'][1] res_list.append(res['employee_id'][1]) return res_list

can u print res_list before return and show your result here....

Author

[u'Abdelwahed Rihene', u'Amine Msakni']

then in rml, instead of putting, o['employee_id'], try putting [[ o ]] only .

Author

It doesnt work pawan :/

ok, do this,
at py replace "res_list.append(res['employee_id'][1])", with :
res['employee_id'] = res['employee_id][1], and then
res_list.append(res), under loop only
and at rml, keep: [[ o['employee_id'] ]]

Author

I have gotten this: [{'s': {'employee_id': (2, u'Abdelwahed Rihene'), 'id': 1}}, {'s': {'employee_id': (3, u'Amine Msakni'), 'id': 3}}]. What i didnt understand is why it is adding [{'s'...

its because, the list n from python function, is again been moulded by rml template parser, and uses its 'o', 's', to refer the data now, ... so every record turns into a dictionary with key selected in repeatIn ...
anyway did u kept: res['employee_id'] = res['employee_id][1], before "res_list.append(res)"
if not please keep it....
n in rml... [[ o['employee_id'] ]] if not work.... then [[ o['o']['employee_id'] ]],
where o/s is your variable in repeatln.....

Author

Am doing all things that you have told me friend :/

Author

It is telling me that 2015-08-27 12:29:21,380 13947 ERROR company openerp.tools.safe_eval: Cannot eval "o['o']['employee_id']" NameError: name 'o' is not defined

u have to replace 'o' with variable u took in "repeatln", :
repeatIn (get_employee_lines ( example.company_id, example.date_start, example.date_end), 'o'),
hope its clear....
please print res_list value and show the same here,
and also what you are getting by just keeping [[ o['employee_id'] ]] in rml file....

Author

2015-08-27 13:11:36,231 16322 ERROR company openerp.tools.safe_eval: Cannot eval "o['employee_id']" Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/tools/safe_eval.py", line 285, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in NameError: name 'o' is not defined

Author

res_list : Abdelwahed Rihene Amine Msakni

Drees, did you kept "res_list.append(res['employee_id'])",
if yes then pleaseeee change it to "res_list.append(res)" after "res['employee_id'] = res['employee_id]"
i have mentioned this is above comments also.... please refer them....

Author

I have kept everything as you told mme but i have the same error: NameError: name 'o' is not defined

hehe....it seeming we are making small thing complicated .... can u please update ur latest codes..... py n rml..

Author

Pawan i think that my openerp addons are making this wrong :/

Author

hey pawan my friend u still there. please can you help me my friend i want to create a new cell to every new record please

Drees, if you are still looking for help, then please can u post your requirement and wat have you done till now in detail.... and is previous one sorted?

Author

Pawan my fried i have asked a new question.here is the link: https://www.odoo.com/forum/help-1/question/how-to-make-each-result-in-a-cell-90226

Author

Pawan are here please ?? need your help

Related Posts Replies Views Activity
0
Apr 18
1955
0
Feb 18
2517
4
Oct 16
29680
1
Sep 15
2667
1
Sep 15
2768