res_users.py 889 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models
  4. class ResUsers(models.Model):
  5. _inherit = 'res.users'
  6. resource_ids = fields.One2many(
  7. 'resource.resource', 'user_id', 'Resources')
  8. resource_calendar_id = fields.Many2one(
  9. 'resource.calendar', 'Default Working Hours',
  10. related='resource_ids.calendar_id', readonly=False)
  11. def write(self, vals):
  12. rslt = super().write(vals)
  13. # If the timezone of the admin user gets set on their first login, also update the timezone of the default working calendar
  14. if (vals.get('tz') and len(self) == 1 and not self.env.user.login_date
  15. and self.env.user == self.env.ref('base.user_admin', False) and self == self.env.user):
  16. self.resource_calendar_id.tz = vals['tz']
  17. return rslt