33
33
def _analysis_all(self, cr, uid, ids, fields, arg, context=None):
35
35
res = dict([(i, {}) for i in ids])
37
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
38
res.update(dict([(i, {}) for i in parent_ids]))
36
parent_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
37
#parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
38
#res.update(dict([(i, {}) for i in parent_ids]))
39
39
accounts = self.browse(cr, uid, ids, context=context)
72
72
if account_id not in res:
73
73
res[account_id] = {}
74
74
res[account_id][f] = sum
75
for account in accounts:
76
for child in account.child_ids:
77
if res[account.id][f] < res.get(child.id, {}).get(f):
78
res[account.id][f] = res.get(child.id, {}).get(f, False)
75
#for account in accounts:
76
# for child in account.child_ids:
77
# if res[account.id][f] < res.get(child.id, {}).get(f):
78
# res[account.id][f] = res.get(child.id, {}).get(f, False)
79
79
elif f == 'ca_to_invoice':
111
111
res[account_id] = {}
112
112
res[account_id][f] = round(sum, dp)
114
for account in accounts:
115
#res.setdefault(account.id, 0.0)
116
res2.setdefault(account.id, 0.0)
117
for child in account.child_ids:
118
if child.id != account.id:
119
res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
120
res2[account.id] += res2.get(child.id, 0.0)
114
#for account in accounts:
115
# #res.setdefault(account.id, 0.0)
116
# res2.setdefault(account.id, 0.0)
117
# for child in account.child_ids:
118
# if child.id != account.id:
119
# res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
120
# res2[account.id] += res2.get(child.id, 0.0)
121
121
# sum both result on account_id
123
123
res[id][f] = round(res.get(id, {}).get(f, 0.0), dp) + round(res2.get(id, 0.0), 2)
135
135
GROUP BY account_analytic_line.account_id",(parent_ids,))
136
136
for account_id, lid in cr.fetchall():
137
137
res[account_id][f] = lid
138
for account in accounts:
139
for child in account.child_ids:
140
if res[account.id][f] < res.get(child.id, {}).get(f):
141
res[account.id][f] = res.get(child.id, {}).get(f, False)
138
#for account in accounts:
139
# for child in account.child_ids:
140
# if res[account.id][f] < res.get(child.id, {}).get(f):
141
# res[account.id][f] = res.get(child.id, {}).get(f, False)
142
142
elif f == 'last_worked_date':
144
144
res[id][f] = False
152
152
if account_id not in res:
153
153
res[account_id] = {}
154
154
res[account_id][f] = lwd
155
for account in accounts:
156
for child in account.child_ids:
157
if res[account.id][f] < res.get(child.id, {}).get(f):
158
res[account.id][f] = res.get(child.id, {}).get(f, False)
155
#for account in accounts:
156
# for child in account.child_ids:
157
# if res[account.id][f] < res.get(child.id, {}).get(f):
158
# res[account.id][f] = res.get(child.id, {}).get(f, False)
159
159
elif f == 'hours_qtt_non_invoiced':
173
173
if account_id not in res:
174
174
res[account_id] = {}
175
175
res[account_id][f] = round(sua, dp)
176
for account in accounts:
177
for child in account.child_ids:
178
if account.id != child.id:
179
res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
176
#for account in accounts:
177
# for child in account.child_ids:
178
# if account.id != child.id:
179
# res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
181
181
res[id][f] = round(res[id][f], dp)
182
182
elif f == 'hours_quantity':
195
195
if account_id not in res:
196
196
res[account_id] = {}
197
197
res[account_id][f] = round(hq, dp)
198
for account in accounts:
199
for child in account.child_ids:
200
if account.id != child.id:
201
if account.id not in res:
202
res[account.id] = {f: 0.0}
203
res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
198
#for account in accounts:
199
# for child in account.child_ids:
200
# if account.id != child.id:
201
# if account.id not in res:
202
# res[account.id] = {f: 0.0}
203
# res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
205
205
res[id][f] = round(res[id][f], dp)
206
206
elif f == 'ca_theorical':
207
207
# TODO Take care of pricelist and purchase !
212
212
# This computation doesn't take care of pricelist !
213
213
# Just consider list_price
232
232
AND account_analytic_journal.type IN ('purchase', 'general')
233
233
GROUP BY account_analytic_line.account_id""",(parent_ids,))
234
234
for account_id, sum in cr.fetchall():
235
res2[account_id] = round(sum, dp)
237
for account in accounts:
238
res2.setdefault(account.id, 0.0)
239
for child in account.child_ids:
240
if account.id != child.id:
241
if account.id not in res:
242
res[account.id] = {f: 0.0}
243
res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
244
res[account.id][f] += res2.get(child.id, 0.0)
235
res[account_id][f] = round(sum, dp)
236
#for account in accounts:
237
# res2.setdefault(account.id, 0.0)
238
# for child in account.child_ids:
239
# if account.id != child.id:
240
# if account.id not in res:
241
# res[account.id] = {f: 0.0}
242
# res[account.id][f] += res.get(child.id, {}).get(f, 0.0)
243
# res[account.id][f] += res2.get(child.id, 0.0)
246
245
# sum both result on account_id
248
res[id][f] = round(res[id][f], dp) + round(res2.get(id, 0.0), dp)
247
# res[id][f] = round(res[id][f], dp) + round(res2.get(id, 0.0), dp)
252
251
def _ca_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
255
child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
254
child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
255
#child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
256
256
for i in child_ids:
260
261
if not child_ids:
269
270
AND account_analytic_journal.type = 'sale' \
270
271
GROUP BY account_analytic_line.account_id", (child_ids,))
271
272
for account_id, sum in cr.fetchall():
272
res[account_id][name] = round(sum,2)
273
data = self._compute_level_tree(cr, uid, ids, child_ids, res, [name], context=context)
275
res_final[i] = data[i][name]
273
res[account_id] = round(sum,2)
275
#data = self._compute_level_tree(cr, uid, ids, child_ids, res, [name], context=context)
277
# res_final[i] = data[i][name]
278
280
def _total_cost_calc(self, cr, uid, ids, name, arg, context=None):
281
child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
283
child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
284
#child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
283
285
for i in child_ids:
287
290
if not child_ids:
291
293
cr.execute("""SELECT account_analytic_line.account_id, COALESCE(SUM(amount), 0.0) \
292
294
FROM account_analytic_line \
297
299
GROUP BY account_analytic_line.account_id""",(child_ids,))
298
300
for account_id, sum in cr.fetchall():
299
res[account_id][name] = round(sum,2)
300
data = self._compute_level_tree(cr, uid, ids, child_ids, res, [name], context)
302
res_final[i] = data[i][name]
301
res[account_id] = round(sum,2)
303
#data = self._compute_level_tree(cr, uid, ids, child_ids, res, [name], context)
305
# res_final[i] = data[i][name]
305
308
def _remaining_hours_calc(self, cr, uid, ids, name, arg, context=None):
455
458
max_user = cr.fetchone()[0]
456
459
account_ids = [int(str(x/max_user - (x%max_user == 0 and 1 or 0))) for x in ids]
457
460
user_ids = [int(str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user))) for x in ids]
458
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
461
parent_ids = tuple(account_ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
462
#parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
463
import pdb;pdb.set_trace()
460
465
cr.execute('SELECT id, unit_amount ' \
461
466
'FROM account_analytic_analysis_summary_user ' \
463
468
'AND "user" IN %s',(parent_ids, tuple(user_ids),))
464
469
for sum_id, unit_amount in cr.fetchall():
465
470
res[sum_id] = unit_amount
467
res.setdefault(obj_id, 0.0)
468
for child_id in account_obj.search(cr, uid,
469
[('parent_id', 'child_of', [int(str(obj_id/max_user - (obj_id%max_user == 0 and 1 or 0)))])]):
470
if child_id != int(str(obj_id/max_user - (obj_id%max_user == 0 and 1 or 0))):
471
res[obj_id] += res.get((child_id * max_user) + obj_id -((obj_id/max_user - (obj_id%max_user == 0 and 1 or 0)) * max_user), 0.0)
472
# res.setdefault(obj_id, 0.0)
473
# for child_id in account_obj.search(cr, uid,
474
# [('parent_id', 'child_of', [int(str(obj_id/max_user - (obj_id%max_user == 0 and 1 or 0)))])]):
475
# if child_id != int(str(obj_id/max_user - (obj_id%max_user == 0 and 1 or 0))):
476
# res[obj_id] += res.get((child_id * max_user) + obj_id -((obj_id/max_user - (obj_id%max_user == 0 and 1 or 0)) * max_user), 0.0)
473
478
res[id] = round(res.get(id, 0.0), 2)
619
624
account_obj = self.pool.get('account.analytic.account')
620
625
account_ids = [int(str(int(x))[:-6]) for x in ids]
621
626
month_ids = [int(str(int(x))[-6:]) for x in ids]
622
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
627
parent_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
628
#parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
624
630
cr.execute('SELECT id, unit_amount ' \
625
631
'FROM account_analytic_analysis_summary_month ' \
627
633
'AND month_id IN %s ',(parent_ids, tuple(month_ids),))
628
634
for sum_id, unit_amount in cr.fetchall():
629
635
res[sum_id] = unit_amount
631
res.setdefault(obj_id, 0.0)
632
for child_id in account_obj.search(cr, uid,
633
[('parent_id', 'child_of', [int(str(int(obj_id))[:-6])])]):
634
if child_id != int(str(int(obj_id))[:-6]):
635
res[obj_id] += res.get(int(child_id * 1000000 + int(str(int(obj_id))[-6:])), 0.0)
637
# res.setdefault(obj_id, 0.0)
638
# for child_id in account_obj.search(cr, uid,
639
# [('parent_id', 'child_of', [int(str(int(obj_id))[:-6])])]):
640
# if child_id != int(str(int(obj_id))[:-6]):
641
# res[obj_id] += res.get(int(child_id * 1000000 + int(str(int(obj_id))[-6:])), 0.0)
637
643
res[id] = round(res.get(id, 0.0), 2)