GoodERP
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

30 lines
980B

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. from odoo.exceptions import UserError
  5. class Staff(models.Model):
  6. _name = 'staff'
  7. _inherit = ['mail.thread', 'mail.activity.mixin']
  8. _description = '员工'
  9. user_id = fields.Many2one('res.users', '对应用户')
  10. company_id = fields.Many2one(
  11. 'res.company',
  12. string='公司',
  13. change_default=True,
  14. default=lambda self: self.env.company)
  15. @api.constrains('user_id')
  16. def _check_user_id(self):
  17. '''一个员工只能对应一个用户'''
  18. for staff in self:
  19. staffs = []
  20. if staff.user_id:
  21. staffs = self.env['staff'].search(
  22. [('user_id', '=', staff.user_id.id)])
  23. if len(staffs) > 1:
  24. raise UserError('用户 %s 已有对应员工' % staff.user_id.name)
上海开阖软件有限公司 沪ICP备12045867号-1