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

Hi Forum!

I have a computed field called 'remain', but the problem with it is that it doesn't seem to call the function it uses.

What could be the problem?


remain = fields.Integer(string='Remain', compute='_compute_remain', store=True)
working_days = fields.Integer(compute='_compute_working_days_count')
yearly = fields.Integer(string='Yearly pool')

@api.multi
@api.depends('yearly', 'working_days')
def _compute_remain(self):
for record in self:
record.remain = record.yearly - record.working_days

Thank you for your help!


Regards,

Steven


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Steven,

please make working_days compute field to store=True

hope this will help you

Thanks & regards

Ankit Vaghela

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

Thanks for the quick response! Looks like the problem is solved!

Regards,
Steven

Tác giả

Thank you very much!

Regards,
Steven

Tác giả

now there would be a problem with working_days not updating when it gets a new value, what could be the problem?

Working_days compute field method:
@api.multi
def _compute_working_days(self):
for record in self:
record.working_days = sum(record.holidays_ids.mapped('working_days'))

@api.multi
@api.depends('holidays_ids')
def _compute_working_days(self):
for record in self:
record.working_days = sum(record.holidays_ids.mapped('working_days'))

Try this hope this will work

Tác giả

I try this, but it's not working.
Here are all the fields:

yearly_pool = fields.Integer(string='Yearly pool')
working_days = fields.Integer(string='Wordkdays count', compute='_compute_working_days', store=True)
remaining = fields.Integer(string='Remaining', compute='_compute_remaining', store=True)
holidays_ids = fields.Many2many('hr.holidays', string='Freedoms allowed ', compute='_compute_holidays_ids')

Field methods:

remaining:

@api.multi
@api.depends('yearly_pool', 'working_days')
def _compute_remaining(self):
for record in self:
record.remaining = record.yearly_pool - record.working_days

working_days:

@api.multi
@api.depends('holidays_ids')
def _compute_working_days(self):
for record in self:
record.working_days = sum(record.holidays_ids.mapped('working_days'))

holiday_ids:

@api.multi
def _compute_holidays_ids(self):
for record in self:
record.holidays_ids = self.env['hr.holidays'].search([
('employee_id', '=', record.employee_id.id),
('year', '=', record.year),
('state', '=', 'validate'),
])

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 16
3517
2
thg 3 24
2520
0
thg 12 23
1296
1
thg 7 22
2273
1
thg 10 21
2274