From fc326082c8d1764813e313a1406e5edebeb983f4 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Fri, 18 Aug 2023 10:28:15 +0200 Subject: [PATCH] [FIX] stock: hide reset to draft button when no needed Only immediate transfers should have the ability to reset the state to draft. Also rewording it as "Plan" as the goal of this button is to left the stock move to be done later and impact the forecast Task: 3256447 Part-of: odoo/odoo#124409 --- addons/stock/models/stock_picking.py | 9 ++++++--- addons/stock/tests/test_picking.py | 11 +++++++++++ addons/stock/views/stock_picking_views.xml | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 5b2df0413af..45081119d69 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -932,9 +932,12 @@ class Picking(models.Model): picking_to_reset = self.filtered(lambda p: p.state not in ('done', 'cancel')) picking_to_reset.do_unreserve() picking_to_reset.immediate_transfer = False - picking_to_reset.move_ids.quantity_done = 0 - picking_to_reset.move_ids.move_line_ids.unlink() - picking_to_reset.move_ids.state = 'draft' + if picking_to_reset.move_ids: + picking_to_reset.move_ids.quantity_done = 0 + picking_to_reset.move_ids.move_line_ids.unlink() + picking_to_reset.move_ids.state = 'draft' + else: + picking_to_reset.state = 'draft' def _action_done(self): """Call `_action_done` on the `stock.move` of the `stock.picking` in `self`. diff --git a/addons/stock/tests/test_picking.py b/addons/stock/tests/test_picking.py index e40d26d1231..52893107433 100644 --- a/addons/stock/tests/test_picking.py +++ b/addons/stock/tests/test_picking.py @@ -22,3 +22,14 @@ class TestPicking(common.TransactionCase): }) self.assertEqual( er.exception.args[0], f'Sequences {operation_type_1.sequence_id.name} already exist.') + + def test_empty_picking_draft(self): + """ test an empty still can be reset to draft """ + picking = self.env['stock.picking'].create({ + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_dest_id': self.env.ref('stock.stock_location_stock').id, + }) + self.assertFalse(picking.move_ids) + picking.action_reset_draft() + self.assertEqual(picking.state, 'draft') diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index 2c0304b2d64..026757c4953 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -130,7 +130,7 @@