Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

NameError: name 'o' is not defined

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
pythonrmlopenerp7
3 Risposte
13239 Visualizzazioni
Avatar
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
Avatar
Abbandona
Rihene
Autore

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

Avatar
Pawan
Risposta migliore

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
Avatar
Abbandona
Avatar
Rihene
Autore Risposta migliore

 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
Avatar
Abbandona
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
Autore

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

Pawan

Please update your error.... Drees

Rihene
Autore

I have updated it after modifying all what you said

Rihene
Autore

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
Autore

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

Rihene
Autore

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

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
Autore

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
Autore

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
Autore

Pawan my friend you still here??

Rihene
Autore

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
Autore

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
Autore

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
Autore

sorry i have changed the o to s

Pawan

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

Rihene
Autore

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
Autore

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

Pawan

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

Rihene
Autore

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
Autore

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
Autore

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

Rihene
Autore

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
Autore

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
Autore

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
Autore

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
Autore

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

Rihene
Autore

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
Autore

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
Autore

Pawan are here please ?? need your help

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Spliting rml intotwo halves
rml openerp7
Avatar
0
apr 18
3367
How to add condation in rml
rml openerp7
Avatar
0
feb 18
4424
How to send email in openerp by python code Risolto
python openerp7
Avatar
Avatar
Avatar
Avatar
Avatar
4
ott 16
32051
How to divide a data into x caracters to be displayed in a field?
python openerp7
Avatar
Avatar
1
set 15
4652
How to realise a page break or specify number of columns in rml for openerp Risolto
rml openerp7
Avatar
1
set 15
4500
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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