Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to set conditional deleletion in one2many tree in odoo 9?

By
Bartosz Dmytrak
on 5/3/16, 4:25 PM 342 views

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"

2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 5/4/16, 3:13 AM

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.

Bartosz Dmytrak
on 5/5/16, 4:32 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/3/16, 4:25 PM
Seen: 342 times
Last updated: 5/5/16, 4:32 PM