189
189
- state is in vals
190
190
- state is different from draft (validated or done)
192
195
if context is None:
194
197
res = super(msf_budget, self).write(cr, uid, ids, vals, context=context)
195
198
if context.get('sync_update_execution', False) and vals.get('state', False) and vals.get('state') != 'draft':
196
199
# Update parent budget
197
200
self.update_parent_budgets(cr, uid, ids, context=context)
202
budget = self.browse(cr, uid, ids, context=context)[0]
203
if budget.type == 'normal' and vals.get('state') == 'done': # do not process for view accounts
204
ala_obj = self.pool.get('account.analytic.account')
206
cc_parent_ids = ala_obj._get_parent_of(cr, uid, budget.cost_center_id.id, context=context)
207
# exclude the cc of the current budget line
208
parent_cc_ids = [x for x in cc_parent_ids if x != budget.cost_center_id.id]
209
# find all ccs which have the same parent
210
all_cc_ids = ala_obj.search(cr, uid, [('parent_id','in',parent_cc_ids)], context=context)
211
# remove parent ccs from the list
212
peer_cc_ids = [x for x in all_cc_ids if x not in parent_cc_ids]
213
# find peer budget lines based on cc
214
peer_budget_ids = self.search(cr, uid, [('cost_center_id','in',peer_cc_ids),('decision_moment_id','=',budget.decision_moment_id.id),('fiscalyear_id','=',budget.fiscalyear_id.id),'!',('id','=',budget.id)],context=context)
215
peer_budgets = self.browse(cr, uid, peer_budget_ids, context=context)
218
for peer in peer_budgets:
219
if peer.state != 'done':
222
parent_ids = self.search(cr, uid, [('cost_center_id', 'in', parent_cc_ids),('decision_moment_id','=',budget.decision_moment_id.id),('fiscalyear_id','=',budget.fiscalyear_id.id),'!',('state','=','done')],context=context)
223
self.write(cr, uid, parent_ids, {'state': 'done'},context=context)
200
226
def update(self, cr, uid, ids, context=None):