Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Unable to Inherit function field in v8

Subscriure's

Get notified when there's activity on this post

This question has been flagged
v8methodfields.functionodoo
3 Respostes
4704 Vistes
Avatar
Sairam Bandaru

Hi

I want inherit these field to modify the result in functional field but inherited function not calling


class hr_employee_inherit(osv.osv):
_inherit = 'hr.employee'

def _get_leave_status(self, cr, uid, ids, name, args, context=None):
holidays_obj = self.pool.get('hr.holidays')
holidays_id = holidays_obj.search(cr, uid,
[('employee_id', 'in', ids), ('leave_from','<=',fields.date.context_today),
('leave_to','>=',time.strftime('%Y-%m-%d')),('type','=','remove'),('state','not in',('cancel','refuse'))],
context=context)
print holidays_id,ids,'holidays_id****In INHERIT***********-------------------------',time.strftime('%Y-%m-%d'),fields.date.context_today
result = {}
for id in ids:
result[id] = {
'current_leave_state': False,
'current_leave_id': False,
'leave_date_from':False,
'leave_date_to':False,
}
for holiday in self.pool.get('hr.holidays').browse(cr, uid, holidays_id, context=context):
result[holiday.employee_id.id]['leave_date_from'] = holiday.date_from
result[holiday.employee_id.id]['leave_date_to'] = holiday.date_to
result[holiday.employee_id.id]['current_leave_state'] = holiday.state
result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id
print result,'Reslu leave status---------------******-----------'
return result

_columns = {
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),
}


help me out


thanks

0
Avatar
Descartar
Avatar
Akhil P Sivan
Best Answer

Hi,

If you want to inherit the functional fields and make some changes, you may redefine the fields and function in new api and make the changes you need. For eg, you may try like this:

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

current_leave_id = fields.Many2one('hr.holidays.status', compute='_get_leave_status', string="Current Leave Type")
leave_date_from = fields.Date(compute='_get_leave_status', string='From Date')
leave_date_to = fields.Date(compute='_get_leave_status', string='To Date')


@api.one
@api.depends('employee_id')
def _get_leave_status(self):
holidays_obj = self.env['hr.holidays']
holidays = holidays_obj.search([('employee_id', 'in', self.ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')),
('date_to','>=',time.strftime('%Y-%m-%d 23:59:59')),('type','=','remove'),('state','not in',('cancel','refuse'))])

for holiday in holidays:
self.leave_date_from = holiday.date_from
self.leave_date_to = holiday.date_to
self.current_leave_state = holiday.state
self.current_leave_id = holiday.holiday_status_id.id

Please check it n let me know.

2
Avatar
Descartar
Avatar
Sairam Bandaru
Autor Best Answer

Hi, that's fine now able to inherit but in the function I have changed main code because 'self' contained all employees ,So I looped on self instead of holidays as per this code it raising error, So I modified like this working fine  

@api.multi

def _get_leave_status(self):

holidays_obj = self.env['hr.holidays']

print self.ids,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

print self.env.context,'Context ***********8-------------------------',self,self.env.cr,self.env.uid

holidays_id = holidays_obj.search(

[('employee_id', 'in', self.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],

)

print holidays_id,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

#result = {}

'''

for id in ids:

result[id] = {

'current_leave_state': False,

'current_leave_id': False,

'leave_date_from':False,

'leave_date_to':False,

}

'''

for holiday in holidays_id:

print holiday,'****************************',holiday.holiday_status_id.id

for rec in self:

print rec.ids,'Rec*88888888888888888888'

holidays_id = holidays_obj.search(

[('employee_id', 'in', rec.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],

)

rec.leave_date_from = holidays_id and holidays_id[0].date_from or None

rec.leave_date_to = holidays_id and holidays_id[0].date_to or None

rec.current_leave_state = holidays_id and holidays_id[0].state or None

rec.current_leave_id = holidays_id and holidays_id[0].holiday_status_id.id or None


Thanks

0
Avatar
Descartar
Akhil P Sivan

Hi did you manage to solve it? Is it working now?

Sairam Bandaru
Autor

Yes working fine.Resolved I inherited fields along with function as computed fields Thanks.

Akhil P Sivan

Instead of looping on self, I used "@api.one" decorator. Both should have same effect. Anyway I didn't get time to check by running the above. Hope, it helped you in solving the problem.

Sairam Bandaru
Autor

Thanks Akhil.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
How to insert line break ?
v8 placeholder odoo
Avatar
Avatar
Avatar
Avatar
3
de febr. 25
18403
How to use the "or" operator in functions(/methods)
python method odoo
Avatar
Avatar
Avatar
2
d’oct. 21
5012
[Error] : _prepare_invoice_line() takes exactly 5 arguments (3 given)
method arguments odoo
Avatar
0
de nov. 16
4600
[8.0]sale_quotation_number: Error "undefined get method" when updating the amount
v8 error odoo
Avatar
Avatar
1
de jul. 16
5250
Ajout d'une liste déroulante Odoo 8
v8 dropdown odoo
Avatar
0
de jul. 16
6118
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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