且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建记录而不将其保存在数据库中

更新时间:2023-02-15 15:45:39

我相信您可以通过直接将值分配给move_line_ids来实现.当然,鉴于该字段是One2many,您需要使用三元组的特殊列表来实现此目的.在您的情况下,您需要一个[(0, _, values)]来创建新记录(其中values是保存每个新记录的字段值的字典).在下面的示例中,我仅创建一条记录附加到给定的stock.move实例,并且仅在字典中传递move_id值.您应该使用新的移动行的适当值来完成代码,但是请注意,您应始终告诉新记录将其链接到哪个股票移动.

I believe you can achieve it by directly assigning the value to move_line_ids. Of course, given the field is a One2many, you need to use the special list of triplets to achieve this. In your case, you need a [(0, _, values)] for you want to create a new record (where values is the dictionary that holds each new record's field values). In the example below I only create one record attached to a given stock.move instance and I merely pass the move_id value in the dictionary. You should complete the code with the appropriate values for the new move line, but note that you should always tell the new record which stock move it is been linked to.

@api.onchange('your_field_name')
def _onchange_field(self):
    self.move_line_ids = [(0, False, {'move_id': self.id})]