【问题标题】:can someone suggest how to remove delete button in one2many lines whenone field is True有人可以建议如何在一个字段为 True 时删除 one2many 行中的删除按钮
【发布时间】:2017-10-23 06:53:57
【问题描述】:

当一个字段为真时,有人可以建议如何删除 one2many 行中的删除按钮

我尝试过使用 def取消链接(自我): 并覆盖此方法

注意:我在 odoo 10 中工作

【问题讨论】:

  • 多解释一下你的异常看起来很乱!并且不完整。
  • 实际上我有一个 one2many 字段,其中包含一个布尔字段和其他字段....我想要的是每当布尔字段为 True 我只希望 one2many 行中的删除按钮应该不可见。 ....

标签: openerp one2many


【解决方案1】:

您可以设置 在视图中禁用所有记录的删除。否则无法设置条件。

您尝试覆盖 unlink() 的方式是唯一的方法。 您可以在方法中检查您的布尔字段值并相应地引发错误。

@api.multi
def unlink(self):
    for rec in self:
        if rec.your_boolean_field :
            raise UserError(_('In order to delete a record, you must first unset your_boolean_field.'))
    return super(YourModel, self).unlink()

希望这会有所帮助!

【讨论】:

  • 首先感谢您的回复,但取消链接方法在 odoo 10 中无法用于 one2many 行中的删除按钮...我需要一些帮助...我只是想看看为那个按钮..TIA
  • 如果您在“comodel”中定义它,它将适用于 one2many,即如果您在 sale.order.line 中编写 unlink() 并从 sale.order 中删除行,它将要求取消链接。 order.line,你可以从那里引发错误。3
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-28
  • 1970-01-01
  • 2011-05-08
  • 1970-01-01
  • 2015-07-11
相关资源
最近更新 更多