~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to funding_pool/analytic_account.py

  • Committer: Quentin THEURET
  • Date: 2012-02-02 10:10:59 UTC
  • mto: This revision was merged to the branch mainline in revision 587.
  • Revision ID: qt@tempo-consulting.fr-20120202101059-y8gkodfqbdmf93sb
UF-716 [IMP] Change columns titles

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        'date_start': lambda *a: (datetime.datetime.today() + relativedelta(months=-3)).strftime('%Y-%m-%d')
45
45
    }
46
46
 
47
 
    def _check_unicity(self, cr, uid, ids, context={}):
48
 
        if not context:
49
 
            context={}
50
 
        for account in self.browse(cr, uid, ids, context=context):
51
 
            bad_ids = self.search(cr, uid, [('category', '=', account.category),('|'),('name', '=ilike', account.name),('code', '=ilike', account.code)])
52
 
            if len(bad_ids) and len(bad_ids) > 1:
53
 
                return False
54
 
        return True
55
 
 
56
 
    _constraints = [
57
 
        (_check_unicity, 'You cannot have the same code or name between analytic accounts in the same category!', ['code', 'name', 'category']),
58
 
    ]
59
 
 
60
 
    def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False):
61
 
        account = self.browse(cr, uid, id, context=context)
62
 
        if not default:
63
 
            default = {}
64
 
        default = default.copy()
65
 
        default['code'] = (account['code'] or '') + '(copy)'
66
 
        default['name'] = (account['name'] or '') + '(copy)'
67
 
        return super(analytic_account, self).copy(cr, uid, id, default, context=context)
68
 
 
69
 
    def set_funding_pool_parent(self, cr, uid, vals):
70
 
        if 'category' in vals and \
71
 
           'code' in vals and \
72
 
            vals['category'] == 'FUNDING' and \
73
 
            vals['code'] != 'FUNDING':
74
 
            # for all accounts except the parent one
75
 
            funding_pool_parent = self.search(cr, uid, [('category', '=', 'FUNDING'), ('parent_id', '=', False)])[0]
76
 
            vals['parent_id'] = funding_pool_parent
 
47
    def set_category(self, cr, uid, vals):
 
48
        if 'parent_id' in vals and vals['parent_id']:
 
49
            parent = self.read(cr, uid, [vals['parent_id']], ['category'])[0]
 
50
            if parent['category']:
 
51
                vals['category'] = parent['category']
77
52
    
78
53
    def _check_date(self, vals):
79
54
        if 'date' in vals and vals['date'] is not False:
86
61
    
87
62
    def create(self, cr, uid, vals, context=None):
88
63
        self._check_date(vals)
89
 
        self.set_funding_pool_parent(cr, uid, vals)
 
64
        self.set_category(cr, uid, vals)
90
65
        return super(analytic_account, self).create(cr, uid, vals, context=context)
91
66
    
92
67
    def write(self, cr, uid, ids, vals, context=None):
93
68
        self._check_date(vals)
94
 
        self.set_funding_pool_parent(cr, uid, vals)
 
69
        self.set_category(cr, uid, vals)
95
70
        return super(analytic_account, self).write(cr, uid, ids, vals, context=context)
96
71
 
97
72
    def search(self, cr, uid, args, offset=0, limit=None, order=None,
129
104
            view['arch'] = etree.tostring(tree)
130
105
        return view
131
106
 
132
 
    
133
 
    def on_change_category(self, cr, uid, id, category):
134
 
        if not category:
135
 
            return {}
136
 
        res = {'value': {}, 'domain': {}}
137
 
        parent = self.search(cr, uid, [('category', '=', category), ('parent_id', '=', False)])[0]
138
 
        res['value']['parent_id'] = parent
139
 
        res['domain']['parent_id'] = [('category', '=', category)]
140
 
        return res
141
107
analytic_account()
142
108
 
143
109
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: