diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 69db0b8fb52..843681a6f04 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -184,7 +184,7 @@ class StockMove(models.Model): has_package = move.move_line_ids.mapped('package_id') | move.move_line_ids.mapped('result_package_id') consignment_enabled = self.user_has_groups('stock.group_tracking_owner') if move.picking_id.picking_type_id.show_operations is False\ - and (move.state != 'draft' or (not self._context.get('planned_picking') and move.state == 'draft'))\ + and (move.state != 'draft' or (move.picking_id.immediate_transfer and move.state == 'draft'))\ and (multi_locations_enabled or move.has_tracking != 'none' or len(move.move_line_ids) > 1 or has_package or consignment_enabled): move.show_details_visible = True else: @@ -200,7 +200,7 @@ class StockMove(models.Model): @api.depends('state', 'picking_id') def _compute_is_initial_demand_editable(self): for move in self: - if self._context.get('planned_picking'): + if not move.picking_id.immediate_transfer: move.is_initial_demand_editable = True elif not move.picking_id.is_locked and move.state != 'done' and move.picking_id: move.is_initial_demand_editable = True @@ -213,7 +213,7 @@ class StockMove(models.Model): for move in self: if not move.product_id: move.is_quantity_done_editable = False - elif self._context.get('planned_picking') and move.picking_id.state == 'draft': + elif not move.picking_id.immediate_transfer and move.picking_id.state == 'draft': move.is_quantity_done_editable = False elif move.picking_id.is_locked and move.state in ('done', 'cancel'): move.is_quantity_done_editable = False diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 17ba50a3975..b481051a182 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -303,6 +303,7 @@ class Picking(models.Model): show_operations = fields.Boolean(compute='_compute_show_operations') show_lots_text = fields.Boolean(compute='_compute_show_lots_text') has_tracking = fields.Boolean(compute='_compute_has_tracking') + immediate_transfer = fields.Boolean() _sql_constraints = [ ('name_uniq', 'unique(name, company_id)', 'Reference must be unique per company!'), @@ -319,7 +320,7 @@ class Picking(models.Model): picking.show_operations = True continue if picking.picking_type_id.show_operations: - if (picking.state == 'draft' and not self.env.context.get('planned_picking')) or picking.state != 'draft': + if (picking.state == 'draft' and picking.immediate_transfer) or picking.state != 'draft': picking.show_operations = True else: picking.show_operations = False @@ -437,7 +438,7 @@ class Picking(models.Model): for picking in self: if not picking.move_lines: picking.show_mark_as_todo = False - elif self._context.get('planned_picking') and picking.state == 'draft': + elif not (picking.immediate_transfer) and picking.state == 'draft': picking.show_mark_as_todo = True elif picking.state != 'draft' or not picking.id: picking.show_mark_as_todo = False @@ -448,7 +449,7 @@ class Picking(models.Model): @api.depends('state', 'is_locked') def _compute_show_validate(self): for picking in self: - if self._context.get('planned_picking') and picking.state == 'draft': + if not (picking.immediate_transfer) and picking.state == 'draft': picking.show_validate = False elif picking.state not in ('draft', 'waiting', 'confirmed', 'assigned') or not picking.is_locked: picking.show_validate = False @@ -562,19 +563,7 @@ class Picking(models.Model): # call `_action_assign` on every confirmed move which location_id bypasses the reservation self.filtered(lambda picking: picking.location_id.usage in ('supplier', 'inventory', 'production') and picking.state == 'confirmed')\ .mapped('move_lines')._action_assign() - if self.env.context.get('planned_picking') and len(self) == 1: - action = self.env.ref('stock.action_picking_form') - result = action.read()[0] - result['res_id'] = self.id - result['context'] = { - 'search_default_picking_type_id': [self.picking_type_id.id], - 'default_picking_type_id': self.picking_type_id.id, - 'contact_display': 'partner_address', - 'planned_picking': False, - } - return result - else: - return True + return True @api.multi def action_assign(self): @@ -793,9 +782,8 @@ class Picking(models.Model): @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() + for picking in self.filtered(lambda picking: picking.immediate_transfer and picking.state not in ('done', 'cancel') and picking.move_lines): + picking.action_confirm() def _get_overprocessed_stock_moves(self): self.ensure_one() diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index fc7b7577270..40d8ed02c3f 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -3549,6 +3549,7 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'immediate_transfer': True, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index c522bf08b7e..d3f36d17173 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -283,8 +283,9 @@ - - + + + @@ -303,8 +304,8 @@ - - + +