__init__.py 876 B

123456789101112131415161718192021
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from . import models
  4. def post_init(cr, registry):
  5. """ Set the timesheet project and task on existing leave type. Do it in post_init to
  6. be sure the internal project/task of res.company are set. (Since timesheet_generate field
  7. is true by default, those 2 fields are required on the leave type).
  8. """
  9. from odoo import api, SUPERUSER_ID
  10. env = api.Environment(cr, SUPERUSER_ID, {})
  11. for hr_leave_type in env['hr.leave.type'].search([('timesheet_generate', '=', True), ('timesheet_project_id', '=', False)]):
  12. company = hr_leave_type.company_id or env.company
  13. hr_leave_type.write({
  14. 'timesheet_project_id': company.internal_project_id.id,
  15. 'timesheet_task_id': company.leave_timesheet_task_id.id,
  16. })