def METHOD_NAME(self):
    for mandate in self:
        if mandate.state not in ("draft", "valid"):
            raise UserError(_("Mandate should be in draft or valid state."))
    self.write({"state": "cancel"})