~elbati/stock-logistic-flows/adding_stock_move_backorder_7

« back to all changes in this revision

Viewing changes to picking_dispatch/picking_dispatch.py

  • Committer: Alexandre Fayolle @ camptocamp
  • Date: 2012-08-07 13:07:00 UTC
  • Revision ID: alexandre.fayolle@camptocamp.com-20120807130700-pbc0g0noga2xrx6b
[MRG] from 6.1
(lp:c2c-addons/6.1  rev 28.3.27)

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        return True
111
111
 
112
112
    def action_done(self, cr, uid, ids, context=None):
 
113
        if not ids:
 
114
            return True
113
115
        move_obj = self.pool.get('stock.move')
114
116
        move_ids = move_obj.search(cr, uid, [('dispatch_id', 'in', ids)], context=context)
115
117
        return move_obj.action_partial_move(cr, uid, move_ids, context)
116
118
 
 
119
    def check_finished(self, cr, uid, ids, context):
 
120
        """set the dispatch to finished if all the moves are finished"""
 
121
        if not ids:
 
122
            return True
 
123
        finished = []
 
124
        for dispatch in self.browse(cr, uid, ids, context=context):
 
125
            if all(move.state in ('cancel', 'done') for move in dispatch.move_ids):
 
126
                finished.append(dispatch.id)
 
127
        _logger.debug('set state to done for picking.dispatch %s', finished)
 
128
        self.write(cr, uid, finished, {'state': 'done'}, context)
 
129
        return finished
 
130
 
117
131
    def action_cancel(self, cr, uid, ids, context=None):
118
132
        move_obj = self.pool.get('stock.move')
119
133
        move_ids = move_obj.search(cr, uid, [('dispatch_id', 'in', ids)], context=context)
128
142
        now = datetime.now().date()
129
143
        for obj in self.browse(cr, uid, ids, context):
130
144
            date = datetime.strptime(obj.date, '%Y-%m-%d').date()
131
 
            if date < now:
 
145
            if now < date:
132
146
                raise except_osv(_('Error'),
133
147
                                 _('This dispatch cannot be processed until %s') % obj.date)
134
148
 
158
172
        # so the difference between the original set of moves and the complete_moves is the
159
173
        # set of unprocessed moves
160
174
        unprocessed_move_ids = set(ids) - set(complete_move_ids)
 
175
        _logger.debug('partial stock.moves: complete_move_ids %s, unprocessed_move_ids %s', complete_move_ids, unprocessed_move_ids)
161
176
        # unprocessed moves are still linked to the dispatch : this dispatch must not be marked as Done
162
177
        unfinished_dispatch_ids = {}
163
178
        for move in move_obj.browse(cr, uid, list(unprocessed_move_ids), context=context):
164
179
            if not move.dispatch_id:
165
180
                continue
166
181
            unfinished_dispatch_ids[move.dispatch_id.id] = None # value will be set later to a new dispatch
167
 
        finished_dispatches = {}
 
182
        maybe_finished_dispatches = {}
168
183
        for move in move_obj.browse(cr, uid, complete_move_ids, context=context):
169
184
            if not move.dispatch_id:
170
185
                continue
180
195
                                                      })
181
196
                    unfinished_dispatch_ids[dispatch_id] = new_dispatch_id
182
197
                dispatch_id = unfinished_dispatch_ids[dispatch_id]
183
 
            finished_dispatches.setdefault(dispatch_id, []).append(move.id)
184
 
        for dispatch_id, move_ids in finished_dispatches.iteritems():
 
198
            maybe_finished_dispatches.setdefault(dispatch_id, []).append(move.id)
 
199
        for dispatch_id, move_ids in maybe_finished_dispatches.iteritems():
185
200
            move_obj.write(cr, uid, move_ids, {'dispatch_id': dispatch_id})
186
 
        if finished_dispatches:
187
 
            _logger.debug('set state to done for picking.dispatch %s', list(finished_dispatches))
188
 
            dispatch_obj.write(cr, uid, list(finished_dispatches),  {'state': 'done'}, context)
 
201
        dispatch_obj.check_finished(cr, uid, list(maybe_finished_dispatches), context)
189
202
        return complete_move_ids
190
203
 
191
204
 
226
239
        for move in self.browse(cr, uid, ids, context=context):
227
240
            if move.dispatch_id:
228
241
                dispatches.add(move.dispatch_id.id)
229
 
        for dispatch in dispatch_obj.browse(cr, uid, list(dispatches), context=context):
230
 
            if any(move.state not in ('cancel', 'done') for move in dispatch.move_ids):
231
 
                dispatches.remove(dispatch.id)
232
 
        if dispatches:
233
 
            _logger.debug('set state to done for picking.dispatch %s', list(dispatches))
234
 
            dispatch_obj.write(cr, uid, list(dispatches), {'state': 'done'}, context)
 
242
        dispatch_obj.check_finished(cr, uid, list(dispatches), context)
235
243
        return status
236
244
 
237
245