将合作伙伴添加到Odoo中的日历



我需要在Odoov.9中为用户的日历创建一个事件,但它没有创建与会者。

event={
    'start':start_time.strftime('%Y-%m-%d %H:%M:%S'),
    'stop':end_time.strftime('%Y-%m-%d %H:%M:%S'),
    'duration':hours,
    'allday':False,
    'partner_ids': [emp.employee_id.id],
    'name': myshift.account_id.name,
    'user_id': emp.employee_id.user_id.id,
  }
event=self.env['calendar.event'].create(event)

集合partner_ids是与 res.partner 的 Many2Many 关系,这是在 calendar.event 中写入合作伙伴 ID 的方法?

你不能在 many2many 字段中创建值,只是给它 id (这仅适用于 many2one)。如果字段是 one2many 或 many2many:

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write values on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

因此,您应该添加的是列表,而不是列表[(4,emp.employee_id.id)]

这是有效的代码

'partner_ids': [(4,[emp.employee_id.user_id.partner_id.id])],

最新更新