从向导中的另一个模型Odoo调用函数



我可以在向导中从另一个模型调用函数。但是有一个问题。当我从另一个模型调用函数时,我不能使用字段。

调用功能代码:

self.env['inventory.menu'].action_delete()

另一种型号的功能:

def action_delete(self):
print("girdi", self.price)
vals = {
'ref_code': self.ref_code,
'products_id': self.products_id.id,
'product_description': self.product_description,
'teslim_alan': self.teslim_alan,
'teslim_eden': self.teslim_eden,
'quantity': self.scrap_quantity,
'price': self.price,
'unit_price': self.unit_price,
'warehouse_id': self.warehouse_id.id
}
self.env['scrap'].create(vals)

我得到这个错误:

The operation cannot be completed:
- Create/update: a mandatory field is not set.
- Delete: another model requires the record being deleted. If possible, archive it instead.

我该怎么解决?谢谢

您在一个空记录集(self.env['inventory.menu'](上调用它。如果您想使用记录/实例的值,您可能应该先获得一个。

假设您在向导上有一个Many2one字段,就像在另一个问题中一样,然后按下该向导上的按钮,调用向导方法action_do:

def action_do(self):
# self is the wizard record/instance
# do other things before
self.inventory_id.action_delete()
# do other things afterwards

还要记住,如果调用多记录集(one2many,many2many(,请始终考虑循环使用这些记录。要么在你的行动方法中,要么在外部范围中。

最新更新