跳至内容
菜单
此问题已终结
1 回复
5163 查看

I'd like to set conditional deletion on my one2many tree.

Static solution works perfect:

<tree string="My Tree" delete="false">
...
</tree>

but I can't find a solution to set it dynamically ie. if invoice type equals 'out_refund' than delete="false", else delete="true"

形象
丢弃
最佳答案

Hi,

I think another solution is to define an unlink method in that class. Here I think, you need to inherit the account.invoice class and define the unlink method.

for eg:

class AccountInvoice(models.Model):

_inherit = "account.invoice"


    @api.multi

def unlink(self):

for rec in self:

if rec.type == 'out_refund':

raise UserError(_('You cannot delete these type of invoices!'))

return super(AccountInvoice, self).unlink()

This will allow deletion of records only after checking the condition. 

Hope this helps.

形象
丢弃
编写者

Thanks for your help. It works and gives even more possibilities than I need for my use case. Problem is, this works on a different layer - model, so error is raised when record is saved. It gives strange user experience: when user deletes record in list and when whole form is saved then error appears. I'll use it right now (thanks again) and I'll try to find solution which works on presentation layer.

相关帖文 回复 查看 活动
0
2月 21
3426
2
11月 20
17788
1
7月 20
4682
0
11月 15
4976
0
3月 15
4249