Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

consistent keyError for api.depends

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
apiapi.depends
2 Réponses
11753 Vues
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
Ignorer
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
Auteur

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.
Meilleure réponse

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
Ignorer
Muhammad
Auteur

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

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
How do I get Product Prices with json API? Résolu
api
Avatar
Avatar
1
nov. 25
2763
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Avatar
Avatar
1
août 25
1358
Using API check if Odoo is using Odoo sh or on-premises hosting. Résolu
api
Avatar
Avatar
1
août 25
1732
External API XMLRPC Authentication Keeps Replying with false
api
Avatar
Avatar
Avatar
2
juil. 25
4661
API xmlrpc - upload pdf bills to account Résolu
api
Avatar
Avatar
Avatar
3
juil. 25
1827
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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