Hello,
I want to calculate the staff number of departments after entering the department.
Here's my code:
class TrainingAndDevelopment(models.Model):
_name = 'hr.training'
_inherit = 'mail.thread'
_description = "training and development"
employee_name = fields.Many2one('hr.employee', string='Employee Name', required=True)
job_title = fields.Char("Job Title", required=True)
employee_status = fields.Char(string='employee status')
date = fields.Date('Date', required=True, readonly=True, default=fields\.Date\.today\(\)\)
department_id\ =\ fields\.Many2one\('hr\.department',\ string='Department',\ required=True\)
manager_name\ =\ fields\.Many2one\('hr\.employee',\ string='Manager\ Name',\ \)
No_of_Staff\ =\ fields\.Integer\(string='No\ of\ Staff',\ compute='staff_number'\)
@api\.depends\('department_id',\)
def\ staff_number\(self\):
for\ record\ in\ self:
record\.No_of_Staff\ =\ record\.env\['hr\.department'\]\.search_count\(
\[\('department_id',\ '=', record.department.id)])
Thank you in advance for any help