Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
one2manyfunction_fieldv10
1 Răspunde
5661 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Hilar Andikkadavath

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

Krupesh Laiya
Autor

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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
one2many fileds search view and group by and filter in v10
one2many searchview v10
Imagine profil
Imagine profil
1
iul. 19
5416
How to write function fields for many2one or one2many?
many2one one2many function_field
Imagine profil
Imagine profil
2
mai 16
7424
Display fields.function on tree view Rezolvat
treeview one2many function_field
Imagine profil
Imagine profil
Imagine profil
4
ian. 24
13364
Dataerror updating function field of one2many object using on_change event
one2many on_change function_field
Imagine profil
0
mar. 15
5705
how pass value to on2many field from parent form via context
one2many
Imagine profil
Imagine profil
1
ian. 25
2699
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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