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

key Error function field error for O2M field. when opening form view of employee got below error

Subscribe

Get notified when there's activity on this post

This question has been flagged
one2manyfunction_fieldv10
1 Reply
5658 Views
Avatar
Krupesh Laiya

Traceback (most recent call last):
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/laiya/openerp/v10/odoo/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/home/laiya/openerp/v10/odoo/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/home/laiya/openerp/v10/Core-beta/core/web/controllers/main.py", line 888, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/laiya/openerp/v10/Core-beta/core/web/controllers/main.py", line 880, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/laiya/openerp/v10/odoo/odoo/api.py", line 689, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/home/laiya/openerp/v10/odoo/odoo/api.py", line 680, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/laiya/openerp/v10/odoo/odoo/models.py", line 3028, in read
    values[name] = field.convert_to_read(record[name], record, use_name_get)
  File "/home/laiya/openerp/v10/odoo/odoo/models.py", line 5232, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/home/laiya/openerp/v10/odoo/odoo/fields.py", line 918, in __get__
    value = record._cache[self]
  File "/home/laiya/openerp/v10/odoo/odoo/models.py", line 5583, in __getitem__
    value = self._recs.env.cache[field][self._recs.id]
KeyError: 12



from openerp import models, fields, api
from datetime import datetime
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT

class hr_holidays_status(models.Model):
_inherit = 'hr.holidays.status'

leave_type_code = fields.Char('Code')


class hr_holidays_status_balance(models.Model):
_name = 'hr.holidays.status.balance'

l_balance = fields.Many2one('hr.employee', 'Leave Balance')
leave_name_l = fields.Many2one('hr.holidays.status', 'Leave Type')
leave_code = fields.Char('Code')
assigned_l = fields.Integer('Assigned')
used_l = fields.Integer('Used')
waiting_l = fields.Integer('Waiting Approval')
balance_l = fields.Integer('Balance')
employee_id = fields.Many2one('hr.employee', string='Employee')

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


@api.multi
def _compute_balance_of_leaves(self):
for record in self:
holiday_status_obj = self.env['hr.holidays.status']
holiday_status_balance_obj = self.env['hr.holidays.status.balance']
holiday_obj = self.env['hr.holidays']

leave_balance_dict = {}
leave_type_ids = holiday_status_obj.search([])
for leave_type_id in leave_type_ids:
leave_type_bal_ids = holiday_status_balance_obj.search([('employee_id', '=', record.id), ('leave_name_l', '=', leave_type_id.id)])

# Getting current year
current_date_year = datetime.now().year

# Getting no of used leaves by an employee
leave_used_ids = holiday_obj.search([('employee_id','=',record.id),('holiday_status_id', '=', leave_type_id.id),('type', '=', 'remove'), ('state', '=', 'validate')])
leave_used_count = 0
for leave_used_id in leave_used_ids:
used_start_date_year = datetime.strptime(leave_used_id.date_from, DEFAULT_SERVER_DATETIME_FORMAT).year
used_end_date_year = datetime.strptime(leave_used_id.date_to, DEFAULT_SERVER_DATETIME_FORMAT).year
if current_date_year == used_start_date_year and current_date_year == used_end_date_year:
leave_used_count += leave_used_id.number_of_days_temp

# Getting no of leaves waiting to approve for an employee
leave_waiting_ids = holiday_obj.search([('employee_id', '=', record.id),('holiday_status_id', '=', leave_type_id.id),('type', '=', 'remove'), ('state', '=', 'confirm')])
leave_waiting_count = 0
for leave_waiting_id in leave_waiting_ids:
waiting_start_date_year = datetime.strptime(leave_waiting_id.date_from,DEFAULT_SERVER_DATETIME_FORMAT).year
waiting_end_date_year = datetime.strptime(leave_waiting_id.date_to, DEFAULT_SERVER_DATETIME_FORMAT).year
if current_date_year == waiting_start_date_year and current_date_year == waiting_end_date_year:
leave_waiting_count += leave_waiting_id.number_of_days_temp

# Getting no of leaves assigned for an employee
leave_assigned_ids = holiday_obj.search([('employee_id', '=', record.id),('holiday_status_id', '=', leave_type_id.id),('type', '=', 'add'), ('state', '=', 'validate')])
leave_assigned_count = 0
for leave_assigned_id in leave_assigned_ids:
assigned_start_date = datetime.strptime(leave_assigned_id.hr_year_id.date_start,DEFAULT_SERVER_DATE_FORMAT)
assigned_end_date = datetime.strptime(leave_assigned_id.hr_year_id.date_stop,DEFAULT_SERVER_DATE_FORMAT)
assigned_start_date_year = datetime.strptime(str(assigned_start_date),DEFAULT_SERVER_DATETIME_FORMAT).year
assigned_end_date_year = datetime.strptime(str(assigned_end_date),DEFAULT_SERVER_DATETIME_FORMAT).year
if current_date_year == assigned_start_date_year and current_date_year == assigned_end_date_year:
leave_assigned_count += leave_assigned_id.number_of_days_temp

# Calculating balance leave based on leaves used, Waiting and assigned for an employee
leave_balance = leave_assigned_count - leave_used_count - leave_waiting_count

leave_balance_dict['leave_name_l'] = leave_type_id.id
leave_balance_dict['leave_code'] = leave_type_id.name
leave_balance_dict['assigned_l'] = leave_assigned_count
leave_balance_dict['used_l'] = leave_used_count
leave_balance_dict['waiting_l'] = leave_waiting_count
leave_balance_dict['balance_l'] = leave_balance
leave_balance_dict['employee_id'] = record.id
if leave_balance_dict['assigned_l'] > 0 or leave_balance_dict['used_l'] > 0 or leave_balance_dict['waiting_l'] > 0 or leave_balance_dict['balance_l'] > 0:
if leave_type_bal_ids:
leave_type_bal_ids.unlink()
holiday_status_balance_rec = holiday_status_balance_obj.create(leave_balance_dict)
else:
holiday_status_balance_rec = holiday_status_balance_obj.create(leave_balance_dict)
record.bl_leave_type = self.env['hr.holidays.status.balance'].search([('employee_id', '=', record.id)])

bl_leave_type = fields.One2many('hr.holidays.status.balance', 'l_balance', compute='_compute_balance_of_leaves',
string='Leave Type')
0
Avatar
Discard
Hilar Andikkadavath

We cant help with this log, put your code also or update question for generating the same error.

Krupesh Laiya
Author

updated code pls. review it again.

thanks

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
one2many fileds search view and group by and filter in v10
one2many searchview v10
Avatar
Avatar
1
Jul 19
5412
How to write function fields for many2one or one2many?
many2one one2many function_field
Avatar
Avatar
2
May 16
7418
Display fields.function on tree view Solved
treeview one2many function_field
Avatar
Avatar
Avatar
4
Jan 24
13360
Dataerror updating function field of one2many object using on_change event
one2many on_change function_field
Avatar
0
Mar 15
5698
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
Jan 25
2673
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