~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to msf_budget/msf_budget.py

  • Committer: jf
  • Date: 2014-09-26 13:26:18 UTC
  • mfrom: (2210.11.4 unifield-wm)
  • Revision ID: jfb@tempo-consulting.fr-20140926132618-c3pj04ujhhhj62o5
UTP-1197 [IMP] Consolidation budget status automatic updates
lp:~unifield-team/unifield-wm/UTP-1197

Show diffs side-by-side

added added

removed removed

Lines of Context:
189
189
          - state is in vals
190
190
          - state is different from draft (validated or done)
191
191
        """
 
192
 
 
193
        if not ids:
 
194
            return True
192
195
        if context is None:
193
196
            context = {}
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)
 
201
 
 
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')
 
205
            # get parent cc
 
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)
 
216
 
 
217
            all_done = True
 
218
            for peer in peer_budgets:
 
219
                if peer.state != 'done':
 
220
                    all_done = False
 
221
            if all_done == True:
 
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)
198
224
        return res
199
225
 
200
226
    def update(self, cr, uid, ids, context=None):