Skip to Content
Menu
This question has been flagged
1 Reply
1761 Views

Hi odoo forum!

I have a field called :

yearly_holidays_ids = fields.One2many('hr.employee.yearly.holidays','employee_id')

in hr.employee model and i create this field here too:


current_holiday_pool= fields.Integer(compute='_get_current_holiday_pool',store=True)


i need to get this


remaining_count= fields.Integer(compute='_compute_remaining_count',store=True)
data from \hr.employee.yearly.holidays model to hr.employee model filtered by current year

year=fields.Integer(readonly=True)(this field also in hr.employee.yearly.holidays model)


So,how do i count in the field below current_holiday_pool to get these data from hr.employee.yearly.holidays model ?


Thank you for your help!

Avatar
Discard
Author

Hi Odoomates!

This way I got the field data from another model field called 'remaining_count'? I mean the remaining_count field is in hr.employee.yearly.holidays model and already have a computed field, I need a new field ín hr.employee called current.holiday.pool, and the one2many filed called yearly.holiday.ids also here, so I need to get data from this one2many filed

Best Answer

Hi,

You can try like this,

remaining_count = fields.Integer(compute='_compute_remaining_count', store=True)

def _compute_remaining_count(self):
for rec in self:
rec.remaining_count = len(rec.yearly_holidays_ids.filtered(lambda x: x.year == fields.Date.today().year).ids)

Thanks

Avatar
Discard
Author


Avatar
Steven Salty
31 August 2021

Hi Odoomates!

This way I got the field data from another model field called 'remaining_count'? I mean the remaining_count field is in hr.employee.yearly.holidays model and already have a computed field, I need a new field in hr.employee called current.holiday.pool, and the one2many filed called yearly.holiday.ids also here, so I need to get data from this one2many filed

(In hr.employee model i have this field: yearly_holidays_ids)
(In hr.employee.yearly.holidays model i have employee_id, year, remaining_count fields)

Author

i have these fields in my hr.employee model:

yearly_holidays_ids = fields.One2many('hr.employee.yearly.holidays','employee_id')
current_holiday_pool = fields.Integer()

And i have these fields in my hr.employee.yearly.holidays model:

employee_id= fields.Many2one('hr.employee', readonly=True)
year = fields.Integer(string='Year', readonly=True)
remaining_count=fields.Integer(string='Remaining', compute='_compute_remaining_count', store=True)

I want the value of current_holiday_pool in the hr.employee model to use the value to that in the hr.employee.yearly.holidays model, the remaining_count field, and only the records for the current year (in this case 2021).

Related Posts Replies Views Activity
0
Aug 21
1393
3
Sep 20
9456
0
Jul 22
2736
3
Jul 20
10015
4
Oct 24
3683