~openerp-community-reviewer/openerp-program/program

« back to all changes in this revision

Viewing changes to program/program_action_level.py

  • Committer: Sandy Carter
  • Date: 2014-04-05 17:15:43 UTC
  • Revision ID: sandy.carter@savoirfairelinux.com-20140405171543-zshrpb9zve5qylzw
Unittests added for program_action, some refactoring done

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    _name = 'program.action.level'
30
30
 
31
31
    def create(self, cr, uid, data, context=None):
32
 
        if context is None:
33
 
            context = {}
34
 
 
35
 
        depth = data['depth']
36
 
 
37
 
        if depth < 0:
 
32
        if data.get('depth', -1) < 0:
38
33
            raise orm.except_orm(
39
34
                _('Error!'),
40
35
                _('Depth must be greater than or equal to 0.')
41
36
            )
42
 
 
43
 
        return super(
44
 
            program_action_level, self).create(cr, uid, data, context=context)
 
37
        return super(program_action_level, self).create(
 
38
            cr, uid, data, context=context)
45
39
 
46
40
    def write(self, cr, uid, ids, vals, context=None):
47
 
        if context is None:
48
 
            context = {}
49
 
 
50
 
        if 'depth' in vals:
51
 
            depth = vals['depth']
52
 
            if depth < 0:
53
 
                raise orm.except_orm(
54
 
                    _('Error!'),
55
 
                    _('Depth must be greater than or equal to 0.')
56
 
                )
57
 
 
58
 
        return super(
59
 
            program_action_level, self).write(
 
41
        if vals.get('depth', 0) < 0:
 
42
            raise orm.except_orm(
 
43
                _('Error!'),
 
44
                _('Depth must be greater than or equal to 0.')
 
45
            )
 
46
        return super(program_action_level, self).write(
60
47
            cr, uid, ids, vals, context=context)
61
48
 
62
49
    def name_get(self, cr, uid, ids, context=None):
67
54
 
68
55
    _columns = {
69
56
        'name': fields.char(
70
 
            'Name',
71
 
            size=128,
72
 
            required=True,
73
 
            select=True,
74
 
            translate=True,
75
 
        ),
76
 
 
 
57
            'Name', size=128, required=True, select=True, translate=True),
77
58
        'action': fields.one2many(
78
 
            'program.action',
79
 
            'action_level',
80
 
            string='Action',
81
 
        ),
82
 
 
83
 
        'code': fields.char(
84
 
            'Code',
85
 
            size=32,
86
 
        ),
87
 
 
88
 
        'depth': fields.integer(
89
 
            'Level',
90
 
            required=True,
91
 
        ),
 
59
            'program.action', 'action_level', string='Action'),
 
60
        'code': fields.char('Code', size=32),
 
61
        'depth': fields.integer('Level', required=True),
92
62
    }
93
 
 
94
63
    _defaults = {
95
64
        'depth': 1,
96
65
    }