Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

consistent keyError for api.depends

Subscriure's

Get notified when there's activity on this post

This question has been flagged
apiapi.depends
2 Respostes
11722 Vistes
Avatar
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
Avatar
Descartar
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?

Avatar
Serpent Consulting Services Pvt. Ltd.
Best Answer

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
Avatar
Descartar
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!

Registrar-se
Related Posts Respostes Vistes Activitat
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Avatar
Avatar
1
d’ag. 25
1288
Using API check if Odoo is using Odoo sh or on-premises hosting. Solved
api
Avatar
Avatar
1
d’ag. 25
1669
External API XMLRPC Authentication Keeps Replying with false
api
Avatar
Avatar
Avatar
2
de jul. 25
4563
API xmlrpc - upload pdf bills to account Solved
api
Avatar
Avatar
Avatar
3
de jul. 25
1739
Odoo API connection credential - How to get these credentials?
api
Avatar
Avatar
1
de juny 25
3569
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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