Home > front end >  Odoo overriding unlink, why are all values False
Odoo overriding unlink, why are all values False

Time:03-22

Im doing the odoo getting started tutorial. Im trying to override the unlink method so that I prevent the deletion when a record in a specific state. I couldn't get it to work so I used some breakpoints to inspect the variables. To my suprise the values are all False. I guess this is some default value for undefined variables in odoo, but my record is not undefined.

@api.model
def unlink(self, record_id):
    breakpoint() # all values of self are False
    for record in self:
        breakpoint() # I never get here
    breakpoint()

I dont understand why everything is False. In other functions(depends, inverse, onchange) that I wrote for this tutorial this never is the case.

And I also can't find a get_by_id function. Does that not exist in odoo?

CodePudding user response:

try this..., i think it will helps you...

@api.multi
def unlink(self):
    if self.stage == "Your_stage":
        raise UserError(_('You can not delete record in Your_stage stage.'))
    return super(Your_current_class, self).unlink()

CodePudding user response:

Ah I just found out that apparently in odoo if I do:

def unlink(self): # takes only self
    breakpoint() # I can access the values

@api.model
def unlink(self, record_id): # takes two arguments
    breakpoint() # all values are False

I dont know why though

  • Related