【问题标题】:Calling function from another model in wizard, Odoo从向导中的另一个模型调用函数,Odoo
【发布时间】:2022-07-21 17:18:15
【问题描述】:

我可以在向导中从另一个模型调用该函数。但有一个问题。当我从另一个模型调用该函数时,我无法使用这些字段。

调用函数代码:

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.

我该如何解决?谢谢..

【问题讨论】:

    标签: odoo odoo-14 odoo-15


    【解决方案1】:

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

    假设您在your other question 中的向导上有一个 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),请始终考虑对记录进行循环。在您的操作方法中或在外部范围中。

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多