Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

NameError: name 'o' is not defined

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pythonrmlopenerp7
3 Răspunsuri
13237 Vizualizări
Imagine profil
Rihene

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?



0
Imagine profil
Abandonează
Rihene
Autor

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

Imagine profil
Pawan
Cel mai bun răspuns

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

2
Imagine profil
Abandonează
Imagine profil
Rihene
Autor Cel mai bun răspuns

 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.




0
Imagine profil
Abandonează
Pawan

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

Rihene
Autor

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

Pawan

Please update your error.... Drees

Rihene
Autor

I have updated it after modifying all what you said

Rihene
Autor

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

Pawan

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

Rihene
Autor

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

Rihene
Autor

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

Pawan

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

Pawan

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

Rihene
Autor
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
Pawan

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

Rihene
Autor
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
Rihene
Autor

Pawan please you still there??

Pawan

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.

Rihene
Autor

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

Pawan my friend you still here??

Rihene
Autor

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

Pawan

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

Rihene
Autor

Pawan please it doesnt work nothing had changed

Pawan

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

Rihene
Autor

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

Rihene
Autor

sorry i have changed the o to s

Pawan

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

It doesnt work pawan :/

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

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

Rihene
Autor

res_list : Abdelwahed Rihene Amine Msakni

Pawan

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

Rihene
Autor

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

Pawan

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

Rihene
Autor

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

Rihene
Autor

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

Pawan

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?

Rihene
Autor

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

Rihene
Autor

Pawan are here please ?? need your help

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Spliting rml intotwo halves
rml openerp7
Imagine profil
0
apr. 18
3366
How to add condation in rml
rml openerp7
Imagine profil
0
feb. 18
4423
How to send email in openerp by python code Rezolvat
python openerp7
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
oct. 16
32050
How to divide a data into x caracters to be displayed in a field?
python openerp7
Imagine profil
Imagine profil
1
sept. 15
4649
How to realise a page break or specify number of columns in rml for openerp Rezolvat
rml openerp7
Imagine profil
1
sept. 15
4500
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now