无法完成操作:创建/更新:未设置必填字段。奥多14

2024-05-13 01:18:23 发布

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

如果有条件,我需要在“pos.order.line”中创建新记录;在“onchange”函数中

这是我的代码,我得到了这个错误:

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.  Model: Point of Sale Order Lines (pos.order.line), Field: Order Ref (order_id) .

如果我还没有保存订单,如何获取订单id

class PosOrder(models.Model):

    _inherit = "pos.order.line"

    @api.onchange('product_id')

    def onchange_product(self):

        if condition:

            new_pos_order_line = self.create({

                'product_id': ....,

                'price_unit': ....,

                'qty':1,

            })

需要帮忙吗? 谢谢


Tags: 函数代码订单posselfidmodel错误