Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

consistent keyError for api.depends

Subscribe

Get notified when there's activity on this post

This question has been flagged
apiapi.depends
2 Replies
11733 Views
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
Discard
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
Author

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
Discard
Muhammad
Author

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!

Sign up
Related Posts Replies Views Activity
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Avatar
Avatar
1
Aug 25
1295
Using API check if Odoo is using Odoo sh or on-premises hosting. Solved
api
Avatar
Avatar
1
Aug 25
1687
External API XMLRPC Authentication Keeps Replying with false
api
Avatar
Avatar
Avatar
2
Jul 25
4588
API xmlrpc - upload pdf bills to account Solved
api
Avatar
Avatar
Avatar
3
Jul 25
1761
Odoo API connection credential - How to get these credentials?
api
Avatar
Avatar
1
Jun 25
3611
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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