Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
one2manyfunction_fieldv10
1 Odgovori
5662 Prikazi
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
Opusti
Hilar Andikkadavath

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

Krupesh Laiya
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
one2many fileds search view and group by and filter in v10
one2many searchview v10
Avatar
Avatar
1
jul. 19
5416
How to write function fields for many2one or one2many?
many2one one2many function_field
Avatar
Avatar
2
maj 16
7424
Display fields.function on tree view Solved
treeview one2many function_field
Avatar
Avatar
Avatar
4
jan. 24
13365
Dataerror updating function field of one2many object using on_change event
one2many on_change function_field
Avatar
0
mar. 15
5705
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
jan. 25
2700
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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