44
44
'date_start': lambda *a: (datetime.datetime.today() + relativedelta(months=-3)).strftime('%Y-%m-%d')
47
def _check_unicity(self, cr, uid, ids, 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:
57
(_check_unicity, 'You cannot have the same code or name between analytic accounts in the same category!', ['code', 'name', 'category']),
60
def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False):
61
account = self.browse(cr, uid, id, context=context)
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)
69
def set_funding_pool_parent(self, cr, uid, vals):
70
if 'category' 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']
78
53
def _check_date(self, vals):
79
54
if 'date' in vals and vals['date'] is not False:
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)
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)
97
72
def search(self, cr, uid, args, offset=0, limit=None, order=None,
129
104
view['arch'] = etree.tostring(tree)
133
def on_change_category(self, cr, uid, id, category):
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)]
141
107
analytic_account()
143
109
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: