This question has been flagged
2 Replies
44098 Views

hi , i am new to openerp as well as python their exists an error while installing. please help me. my code was here.

from openerp.osv import osv, fields

class mymod(osv.Model):
    _name = 'mymod.mymod'    
    _columns = {
               'name': fields.char('Name', size = 100), 
               'dob': fields.date('Date of birth'),
               'father_name': fields.char('Father Name', size = 100),
               'state': fields.selection([
                                    ('new','New'),
                                    ('assigned','Assigned'),
                                    ('negotiation','Negotiation'),
                                    ('won','Won'),
                                    ('lost','Lost')], 'Stage', readonly=True),
                }

    def mymod_new(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'new'})
         return True

    def mymod_assigned(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'assigned'})
         return True

    def mymod_negotiation(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'negotiation'})
         return True

    def mymod_won(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'won'})
         return True

    def mymod_lost(self, cr, uid, ids):
         self.write(cr, uid, ids, {'state': 'lost'})
         return True    

mymod()

i am studying the workflow example pls help me.. The error is IndentationError: unexpected indent

Avatar
Discard

try removing all tabs and indenting again...

Best Answer

Rules for Python Indentation:

  • Either always use tab or always use spaces - never mix the two.
  • Even better would be to never use tabs, they don't always survive copy/paste.
  • Use 4 spaces per indentation level (or 2, or 8) and always be consistent.

The problem with your source (assuming you don't have any tabs - although what you posted doesn't have tabs - your source may since the tabs could have been lost during copy/paste):

You have an indentation level of 4 spaces beneath class and 5 spaces beneath def. Remove a space from the indentation below all of the function definitions.

Avatar
Discard
Author

thanks Ray Carnes

Best Answer

As the error message indicates, you have an indentation error . This error occurs when a statement is unnecessarily indented or its indentation does not match the indentation of former statements in the same block. Python not only insists on indentation, it insists on consistent indentation . You are free to choose the number of spaces of indentation to use, but you then need to stick with it. If you indent one line by 4 spaces, but then indent the next by 2 (or 5, or 10, or ...), you'll get this error.

However, by default, mixing tabs and spaces is still allowed in Python 2 , but it is highly recommended not to use this "feature". Python 3 disallows mixing the use of tabs and spaces for indentation. Replacing tabs with 4 spaces is the recommended approach for writing Python code .

http://net-informations.com/python/err/indent.htm

Avatar
Discard