From 0f1d08b5b180d281b2b6f786fb4940f4b116e15c Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Tue, 20 Apr 2021 12:48:13 +0000 Subject: [PATCH] [FIX] stock: add button to remove lines in SN detailed operations form Currently there is an action_assign_serial_show_details button within the detailed operations form of a serial tracked product move. Unfortunately there is no way to undo the assigning/creating of move lines from this action (including via clicking the "Discard" button). This can lead to a lot of manual work (e.g. 500 SNs produced instead of 50) to remove unwanted move lines. To remedy this, we add in a button to unlink all of the move's move lines whenever the Assign Serial Numbers button is visible. closes odoo/odoo#71831 Task: 2426281 X-original-commit: a6191c43001f961c20b5b4d32e1fcb218df69d17 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_move.py | 13 +++++++++++++ addons/stock/views/stock_move_views.xml | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index ae94b3fe03c..1697bd347e8 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -656,6 +656,19 @@ class StockMove(models.Model): self._generate_serial_numbers() return self.action_show_details() + def action_clear_lines_show_details(self): + """ Unlink `self.move_line_ids` before returning `self.action_show_details`. + Useful for if a user creates too many SNs by accident via action_assign_serial_show_details + since there's no way to undo the action. + """ + self.ensure_one() + if self.picking_type_id.show_reserved: + move_lines = self.move_line_ids + else: + move_lines = self.move_line_nosuggest_ids + move_lines.unlink() + return self.action_show_details() + def action_assign_serial(self): """ Opens a wizard to assign SN's name on each move lines. """ diff --git a/addons/stock/views/stock_move_views.xml b/addons/stock/views/stock_move_views.xml index ba74279d4f9..f343047a841 100644 --- a/addons/stock/views/stock_move_views.xml +++ b/addons/stock/views/stock_move_views.xml @@ -165,6 +165,12 @@ title="Assign Serial Numbers"> Assign Serial Numbers +