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

consistent keyError for api.depends

Abonare

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

Această întrebare a fost marcată
apiapi.depends
2 Răspunsuri
11750 Vizualizări
Imagine profil
Muhammad

I keep getting keyError for values in api.depends

here is the traceback:

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/opt/odoo8/odoo/openerp/service/server.py", line 290, in app
return self.app(e, s)
File "/opt/odoo8/odoo/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "/opt/odoo8/odoo/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "/opt/odoo8/odoo/openerp/http.py", line 1290, in __call__
return self.dispatch(environ, start_response)
File "/opt/odoo8/odoo/openerp/http.py", line 1264, in __call__
return self.app(environ, start_wrapped)
File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 579, in __call__
return self.app(environ, start_response)
File "/opt/odoo8/odoo/openerp/http.py", line 1426, in dispatch
ir_http = request.registry['ir.http']
File "/opt/odoo8/odoo/openerp/http.py", line 346, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/opt/odoo8/odoo/openerp/modules/registry.py", line 339, in get
update_module)
File "/opt/odoo8/odoo/openerp/modules/registry.py", line 370, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo8/odoo/openerp/modules/loading.py", line 357, in load_modules
registry.setup_models(cr)
File "/opt/odoo8/odoo/openerp/modules/registry.py", line 197, in setup_models
model._setup_complete(cr, SUPERUSER_ID)
File "/opt/odoo8/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo8/odoo/openerp/api.py", line 336, in old_api
result = method(recs, *args, **kwargs)
File "/opt/odoo8/odoo/openerp/models.py", line 3023, in _setup_complete
field.setup_triggers(self.env)
File "/opt/odoo8/odoo/openerp/fields.py", line 593, in setup_triggers
self._setup_dependency([], model, path.split('.'))
File "/opt/odoo8/odoo/openerp/fields.py", line 607, in _setup_dependency
fields = [model._fields[head]]
KeyError: 'hr_employee'

here is my code:

lateform.py

class late_form(osv.Model):
_name = "late.form"
_columns = {
'name': fields.char('Label',required=True,size=32),
'user_id': fields.many2one('hr.employee', 'Name', required=True),
'date': fields.datetime('Date & Time',required=True),
'reason': fields.text('Reason'),
'employee_id': fields.one2many('late.form','user_id'),
'state': fields.selection([('invalid', 'Invalid'),
('valid', 'Valid')]),
}
_defaults = {
'name': "Late report",
'date': fields.datetime.now,
'state': 'invalid',
}

def set_invalid(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'invalid'}, context=context)

def set_valid(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'valid'}, context=context)

def _send_user_id(self, cr, uid, context=None):
""" Returns ID of user
"""
if context is None:
context = {}
return {'user_id': self.browse(cr, uid, employee_id, context=context)}

class hr_employee(models.Model):
_inherit = 'hr_employee'

#what will trigger this functional field
@api.one
#events which will decide when this functional field will be updated
#when an id is added, or when the state of a sale_order_id is changed, e.g. from draft to confirmed
@api.depends('hr.employee')
def compute_late_mtd(self):
cursor = self._cr
user = self._uid
#loop through all employees in the view
for employee in self:
#define starting date and time
today = datetime.datetime.today()
#define them as strings just in case
start_date = str(today.replace(day=1).strftime('%m/%d/%Y'))
next_month = today.replace(day=28) + datetime.timedelta(days=4)
end_date = str(next_month - datetime.timedelta(days=next_month.day))
print end_date

#references the model we need to work with
employee_obj = self.pool.get('late.form')
#narrowing down and selecting all the relevant instances with specific domains
#this search returns an array
late_times = employee_obj.search(cursor, user, [('date','>=',start_date),('date','<=',end_date),('user_id','=',user.id),('state','=','valid')])
print late_times

total = 0.0
for late.form in employee_obj.browse(cursor, user, late_times):
total += 1
hr.employee.late_mtd = total

#run the function defined above and insert into a float field named late_mtd

_columns = {
'late_mtd': fields.float(compute='compute_late_mtd', store=False, string='Times late this month'),
}
0
Imagine profil
Abandonează
OdooBot
Hi Jusab,

Yes I have.

I get a keyError:
KeyError: 'hr'

On Tue, Jun 30, 2015 at 12:39 PM, Jusab Sida (jsi) <jsi@odoo.com> wrote:

Have you put "hr.employee" in depends???

--
Jusab Sida (jsi)
Sent by Tiny ERP Pvt Ltd using Odoo about Forum Post consistent keyError for api.depends

Jusab Sida (jsi)

my bad....you have to put "hr" not hr.employee

Muhammad
Autor

Hi Jusab, this works fine with hr in @api.depends but the code does not compute. Do you think there is another error somewhere?

Imagine profil
Serpent Consulting Services Pvt. Ltd.
Cel mai bun răspuns

Muhammad,

I see 2 places where you must enhance:

1. _inherit = 'hr_employee' should be _inherit = 'hr.employee'

2. @api.depends('hr.employee') should be @api.depends()

Also, make sure your module 'depends' on 'hr' module.

Thanks.

0
Imagine profil
Abandonează
Muhammad
Autor

Thank you sir, I have tried it and the module runs fine. However it seems like the late_mtd does not compute. I am trying to just add the number of instances where a person submits a "late form" within a month. Thank you.

Serpent Consulting Services Pvt. Ltd.

Ramadan kareem. In the method you should write self.late_mtd = total

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
How do I get Product Prices with json API? Rezolvat
api
Imagine profil
Imagine profil
1
nov. 25
2758
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Imagine profil
Imagine profil
1
aug. 25
1356
Using API check if Odoo is using Odoo sh or on-premises hosting. Rezolvat
api
Imagine profil
Imagine profil
1
aug. 25
1732
External API XMLRPC Authentication Keeps Replying with false
api
Imagine profil
Imagine profil
Imagine profil
2
iul. 25
4660
API xmlrpc - upload pdf bills to account Rezolvat
api
Imagine profil
Imagine profil
Imagine profil
3
iul. 25
1827
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