填充多个字段(odoo 8)

2024-06-16 11:49:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我所做的:

我有一个模块

myfield = fields.Many2one('res.partner', string="Graduate", domain=[('is_graduated', '=', True)])

然后我有另一个班级

_inherit = 'res.partner'
is_graduated = fields.Boolean("Graduated before?", default=False)
graduations = fields.Many2many('my_module.courses', string="Graduation courses")

我得到的:

myfield工作正常,但graduations字段为空。如果您编辑user 1配置文件,您可以使用Add item将条目添加到graduation字段,但我需要它被自动填充。

我的期望:

我希望当您打开user 1配置文件时,myfield设置为user 1的每个记录都将在字段graduations中可见。当我创建记录并将myfield值设置为user 1时,该记录必须在字段graduationsuser 1配置文件中可见。如何做到这一点?


Tags: 模块fieldspartnerstringis配置文件记录res
3条回答

user_rel_ids=fields.Many2many(comodel_name='课程', relation='用户课程'u rel', column1='用户id', column2='课程id')

或者

user_rel_id = fields.Many2many('course') 

用于填充数据(用于添加新关系)

user_rel_id = [(4,course_id)]

根据http://odoo4u.blogspot.com/2014/10/orm-methods.html,上面写着: 类的文档中有一个完整的选项列表。 同样的事情也适用于2万人

For a many2many and one2many field, a list of tuples is expected. Here is the list of the tuple that is accepted, with the corresponding semantics:

(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)

您需要为myfield使用onchange method,然后在其中填充graduations字段,如下所示:

@api.onchange('myfield'):
def _onchange_myfield(self):
    #fill graduations field here...
    ...
_inherit = 'crm.phonecall'    
alarm_ids = fields.Many2many('calendar.alarm',string="Reminders") 
 set the alarm_ids of calendar.event model in create method of crm phonecall...
 alarm_ids = [(6,0,self.alarm_ids.ids)] 

_inherit = 'calendar.event'
 alarm_ids = fields.Many2many('calendar.alarm',string="Reminders") 

相关问题 更多 >