删除订单行按钮

Remove order line button

我尝试使用此方法删除名称为 "Services" 的行,但没有成功。

    @api.multi
    def remove_line(self):
         for line in self.order_line:
            if line.name == 'Services':
                self.order_line.write({
                       'line': [(3, self.product_id.id)]
                    })

试试这个

@api.multi
def remove_line(self):
    for rec in self:
        for line in rec.order_line:
            if line.name == 'Services':
                line.unlink()

如果您想使用命令执行此操作,请按以下方式执行:

      # update the record it self
      self.write({
                   # update the one2many field and remove the current line in for loop
                   'order_line': [(3, line.id)]
                })

只有 one2many 或 many2many 接受命令行