我想使用many2many字段来选择我自己的自定义模块(称为赛车队)中的所有员工。每个员工在自己的团队中都会有不同的层级。
型号
class RacingTeams (models.Model):
_name = "racing.teams"
_description = "Helpdesk Teams"
_rec_name = 'name'
name = fields.Char(string="Name", tracking=True)
desc = fields.Char(string="Description", tracking=True)
employee_ids = fields.Many2many(
comodel_name='hr.employee',
relation='hr_teams_rel',
column1='name',
column2='employee_id',
string='Employee',
)
XML
<notebook>
<page string="Team Member" name="team_member">
<field name="employee_ids" required="1">
<tree editable="top">
<field name="name"/>
<field name="tier_id"/>
</tree>
</field>
</page>
</notebook>
人力资源模型继承
class HelpdeskHR (models.Model):
_inherit = "hr.employee"
name = fields.Char(string="Employee Name", related='resource_id.name', store=True, readonly=False, tracking=False)
tier_id = fields.Many2one('helpdesk.tier',string="Tier", ondelete='cascade')
但我现在的问题是,如果我在新团队中添加员工,
tier_id
将从上一个团队中显示。如果我加入其他团队,如何让员工有不同的等级?
团队、员工及其团队之间的独特关系 相应的层必须由中间模型捕获,以便 保证每位员工在不同岗位上都能拥有独特的层级 赛车队。尝试下面的解决方案。
型号-赛车成员:
class RacingTeamMember(models.Model):
_name = 'racing.team.member'
_description = 'Racing Team Member'
team_id = fields.Many2one('racing.teams', string="Team", required=True, ondelete='cascade')
employee_id = fields.Many2one('hr.employee', string="Employee", required=True)
tier_id = fields.Many2one('helpdesk.tier', string="Tier", ondelete='cascade')
型号 - 赛车队:
class RacingTeams(models.Model):
_name = "racing.team"
_description = "Racing Teams"
_rec_name = 'name'
name = fields.Char(string="Name", tracking=True)
desc = fields.Char(string="Description", tracking=True)
team_member_ids = fields.One2many('racing.team.member', 'team_id', string="Team Members")
XML 视图:
<notebook>
<page string="Team Members" name="team_members">
<field name="team_member_ids">
<tree editable="top">
<field name="employee_id"/>
<field name="tier_id"/>
</tree>
</field>
</page>
</notebook>