From d58fb4d38c3f42568f0133df9cb12fb17b4a742a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 19 Sep 2017 14:31:29 -0700 Subject: [PATCH] [IMP] stock: reduce steps required to process a stock.picking When pickings are created or modified they will be automatically 'Marked as todo'. Draft pickings can still be created through the 'Planned transfer' link on the stock.picking.type kanban card. --- addons/stock/models/stock_move.py | 4 ++-- addons/stock/models/stock_picking.py | 13 ++++++++++++- addons/stock/views/stock_picking_views.xml | 11 +++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c85a47aeb57..043f4adacf2 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -189,9 +189,9 @@ class StockMove(models.Model): @api.depends('state', 'picking_id') def _compute_is_initial_demand_editable(self): for move in self: - if move.state == 'draft': + if self._context.get('planned_picking'): move.is_initial_demand_editable = True - elif move.state != 'done' and move.picking_id and not move.picking_id.is_locked: + elif not move.picking_id.is_locked and move.state != 'done' and move.picking_id: move.is_initial_demand_editable = True else: move.is_initial_demand_editable = False diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index e4fe78c4d6a..defeb0ffdc0 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -403,7 +403,9 @@ class Picking(models.Model): if len(move) == 3: move[2]['location_id'] = vals['location_id'] move[2]['location_dest_id'] = vals['location_dest_id'] - return super(Picking, self).create(vals) + res = super(Picking, self).create(vals) + res._autoconfirm_picking() + return res @api.multi def write(self, vals): @@ -416,6 +418,8 @@ class Picking(models.Model): after_vals['location_dest_id'] = vals['location_dest_id'] if after_vals: self.mapped('move_lines').filtered(lambda move: not move.scrapped).write(after_vals) + if vals.get('move_lines'): + self._autoconfirm_picking() return res @api.multi @@ -641,6 +645,13 @@ class Picking(models.Model): quantity_done[pack.product_id.id] += pack.qty_done return any(quantity_done[x] < quantity_todo.get(x, 0) for x in quantity_done) + @api.multi + def _autoconfirm_picking(self): + if not self._context.get('planned_picking'): + for picking in self.filtered(lambda picking: picking.state not in ('done', 'cancel') and picking.move_lines): + picking.action_confirm() + + @api.multi def _create_backorder(self, backorder_moves=[]): """ Move all non-done lines into a new backorder picking. If the key 'do_only_split' is given in the context, then move all lines not in context.get('split', []) instead of all non-done lines. """ diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index b486957fc30..b6c64f36af3 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -204,7 +204,7 @@