GoodERP
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

32 rindas
1.0KB

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