Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2479 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả


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)

Tác giả

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).

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 21
2025
3
thg 9 20
11282
1
thg 6 25
5079
0
thg 7 22
3699
3
thg 7 20
11716