Odoo:创建后将当前ID保存在另一个模型的many2one字段中

问题描述

我想做的是为产品创建一个custom.modify.price模型,在该模型中,我可以选择某个条件来选择产品,然后填写一个百分比影响所有先前选择的价格。我希望它为选择中的每个产品在另一个模型custom.sale.price中创建一个新记录,并且每个记录都应保存在其中创建它的ID记录中的custom.modify.pricemany2one字段。事情是,我可以通过覆盖custom.sale.price custom.modify.price方法并为其提供值来创建此create的新记录,但是我无法以当前{ {1}}的“尚未创建” ID记录

custom.modify.price

解决方法

您需要创建custom.modify.price并用结果id更新值,然后创建custom.sale.price

@api.model
def create(self,vals):
  result = super(CustomModifyPrice,self).create(vals)
  values = {'modification_id': result.id,...}
  self.env['custom.sale.price'].create(values)      
  return result