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

IndentationError: expected an indented block

By
oumaima
on 4/29/13, 9:10 AM 4,133 views

Hi everyone, I developed my own module,it works;but once i added a function i had an error identation even if i made indentation :s the error is : res = {} ^ IndentationError: expected an indented block

code of function :

Blockquote

def get_parent(self, cr, uid, ids, fields, args, context=None):
    res = {}
    parent_obj = self.pool.get('school.parent')
    for student in self.browse(cr, uid, ids):
        level=0
        ids2 = parent_obj.search(cr, uid,[('id','<>',0)], context=context)
            for parent_id in parent_obj.browse(cr, uid, ids2):
                for fils in parent_id.student_ids:
                    if student.id == fils.id:
                        level = level +1
                        res[student.id]=parent_id.id
                    else:
                        level = level +1
                return res

which editor you used. used gedit text editor. there may be indentation problem but it not show in your editor

jamesbale
on 4/29/13, 9:12 AM

notepad++ ,i'm working in windows 7

oumaima
on 4/29/13, 9:15 AM

I have no expr of windows, try to remove manually

jamesbale
on 4/29/13, 9:19 AM

It seems to me that the return should be with indentation of 4 spaces from the outermost indentation level. The return is of the whole function and now your are returning for a single parent.

Lucio
on 4/29/13, 9:39 AM
0
nazarii
On 4/30/13, 5:26 PM

All you need to to is to move lines from 7th to the end 4 spaces leftwards, so it looks like:

def get_parent(self, cr, uid, ids, fields, args, context=None):
    res = {}
    parent_obj = self.pool.get('school.parent')
    for student in self.browse(cr, uid, ids):
        level=0
        ids2 = parent_obj.search(cr, uid,[('id','<>',0)], context=context)
        for parent_id in parent_obj.browse(cr, uid, ids2):
            for fils in parent_id.student_ids:
                if student.id == fils.id:
                    level = level +1
                    res[student.id]=parent_id.id
                else:
                    level = level +1
            return res

have you given 4 spaces for the first line i.e def get_parent(self, cr, uid, ids, fields, args, context=None):

Maniganda
on 5/2/13, 5:28 AM

Yes, this method need 4 spaces block at the beginning, because it is inside some class.

nazarii
on 5/6/13, 5:32 PM
0
Yug Faa
On 4/29/13, 9:55 AM

It would be like

def get_parent(self, cr, uid, ids, fields, args, context=None):
res = {}
parent_obj = self.pool.get('school.parent')
for student in self.browse(cr, uid, ids):
    level=0
    ids2 = parent_obj.search(cr, uid,[('id','<>',0)], context=context)
        for parent_id in parent_obj.browse(cr, uid, ids2):
            for fils in parent_id.student_ids:
                if student.id == fils.id:
                    level = level +1
                    res[student.id]=parent_id.id
                else:
                    level = level +1
return res

If you have other problem, try to replace all tab with 4 spaces, using Alt+R

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: 4/29/13, 9:10 AM
Seen: 4133 times
Last updated: 3/16/15, 8:10 AM