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

NameError: name 'o' is not defined

By
Drees Far
on 8/26/15, 5:24 AM 1,143 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?



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

Drees Far
on 8/26/15, 5:52 AM
2

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 8/26/15, 6:20 AM

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....

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/26/15, 6:29 AM

 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.




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...]

Pawan
on 8/26/15, 6:35 AM

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

Drees Far
on 8/26/15, 6:44 AM

Please update your error.... Drees

Pawan
on 8/26/15, 6:47 AM

I have updated it after modifying all what you said

Drees Far
on 8/26/15, 6:49 AM

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

Drees Far
on 8/26/15, 6:51 AM

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']"...

Pawan
on 8/26/15, 6:53 AM

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

Drees Far
on 8/26/15, 6:54 AM

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

Drees Far
on 8/26/15, 7:00 AM

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

Pawan
on 8/26/15, 7:03 AM

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

Pawan
on 8/26/15, 7:04 AM
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 Far
on 8/26/15, 7:06 AM

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

Pawan
on 8/26/15, 7:10 AM
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
Drees Far
on 8/26/15, 7:18 AM

Pawan please you still there??

Drees Far
on 8/26/15, 7:23 AM

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.

Pawan
on 8/26/15, 7:28 AM

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

Drees Far
on 8/26/15, 7:32 AM

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

Drees Far
on 8/26/15, 7:37 AM

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

Pawan
on 8/26/15, 8:41 AM

Pawan my friend you still here??

Drees Far
on 8/26/15, 9:33 AM

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 Far
on 8/26/15, 12:54 PM

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

Pawan
on 8/27/15, 4:23 AM

Pawan please it doesnt work nothing had changed

Drees Far
on 8/27/15, 5:45 AM

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

Pawan
on 8/27/15, 5:52 AM

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

Drees Far
on 8/27/15, 6:02 AM

sorry i have changed the o to s

Drees Far
on 8/27/15, 6:03 AM

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

Pawan
on 8/27/15, 6:07 AM

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

Drees Far
on 8/27/15, 6:22 AM

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

Pawan
on 8/27/15, 6:32 AM

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

Drees Far
on 8/27/15, 6:35 AM

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

Pawan
on 8/27/15, 7:06 AM

It doesnt work pawan :/

Drees Far
on 8/27/15, 7:19 AM

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'] ]]

Pawan
on 8/27/15, 7:35 AM

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'...

Drees Far
on 8/27/15, 7:58 AM

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.....

Pawan
on 8/27/15, 8:15 AM

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

Drees Far
on 8/27/15, 8:28 AM

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

Drees Far
on 8/27/15, 8:30 AM

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....

Pawan
on 8/27/15, 9:05 AM

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

Drees Far
on 8/27/15, 9:12 AM

res_list : Abdelwahed Rihene Amine Msakni

Drees Far
on 8/27/15, 9:13 AM

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....

Pawan
on 8/27/15, 9:20 AM

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

Drees Far
on 8/27/15, 9:29 AM

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

Pawan
on 8/27/15, 9:44 AM

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

Drees Far
on 8/27/15, 10:12 AM

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 Far
on 8/28/15, 7:57 AM

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?

Pawan
on 8/31/15, 1:10 AM

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

Drees Far
on 8/31/15, 6:00 AM

Pawan are here please ?? need your help

Drees Far
on 8/31/15, 6:53 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/26/15, 5:24 AM
Seen: 1143 times
Last updated: 8/26/15, 12:55 PM