0

can someone suggest how to remove delete button in one2many lines whenone field is True

i have tried using def unlink(self): and overridding this method

Note: i am working in odoo 10

mani shankar
  • 3
  • 1
  • 7
  • Explain bit more your exception seems messy! and incomplete. – DexJ May 23 '17 at 10:57
  • actually i have a one2many field containing one boolean field and other fields in it....what i want is whenever the boolean field is True i just want the delete button in that one2many lines should invisible..... – mani shankar May 23 '17 at 11:02

1 Answers1

1

You can set <tree delete="0"> in view to disable deletion for all records. otherwise there is not way to put condition on that.

The way you tried overriding unlink() is only way to do it. you can check your Boolean field value in method and raise Error Accordingly.

@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()

hope this helps!

DexJ
  • 1,264
  • 13
  • 24
  • firstly thank you for your response ,but unlink method is not working in odoo 10 for delete button in one2many lines...i need some help for this..i just want to see the method written for that button..TIA – mani shankar May 23 '17 at 11:59
  • surly it will work for one2many if you define it in "comodel" i.e. if you write unlink() in sale.order.line and delete line from sale.order it will call for unlink of so.order.line and you can rais error from there.3 – DexJ May 23 '17 at 12:31