From fcc0404f84c5de79da33098f51aaf9be04ea8195 Mon Sep 17 00:00:00 2001
From: Pierre Masereel <pim@odoo.com>
Date: Mon, 2 Oct 2017 13:18:05 +0200
Subject: [PATCH] [FIX] stock: stock move edition

This commit fine tune the appearance of the show detials icon as well as
the editability of the quantity done directly through the move line.

- if no product is selected, don't allow to fill quantity done
- if the selected product requires the show details icon, don't allow to
  fill quantity done and directly display it
---
 addons/stock/models/stock_move.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py
index b340688bac41..7bfa320bb507 100644
--- a/addons/stock/models/stock_move.py
+++ b/addons/stock/models/stock_move.py
@@ -182,7 +182,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'\
+                    and (move.state != 'draft' or (not self._context.get('planned_picking') 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:
@@ -206,13 +206,17 @@ class StockMove(models.Model):
                 move.is_initial_demand_editable = False
 
     @api.multi
-    @api.depends('state', 'picking_id')
+    @api.depends('state', 'picking_id', 'product_id')
     def _compute_is_quantity_done_editable(self):
         for move in self:
-            if self._context.get('planned_picking') and move.picking_id.state == 'draft':
+            if not move.product_id:
+                move.is_quantity_done_editable = False
+            elif self._context.get('planned_picking') 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
+            elif move.show_details_visible:
+                move.is_quantity_done_editable = False
             else:
                 move.is_quantity_done_editable = True
 
-- 
GitLab