Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5181 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 21
3439
One2many fields in tree views แก้ไขแล้ว
2
พ.ย. 20
17798
1
ก.ค. 20
4695
0
พ.ย. 15
4985
0
มี.ค. 15
4253