From 27c95fa2c0ad7d71723652a326dbb82b4dce85ac Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Fri, 27 Oct 2023 14:19:04 +0200 Subject: [PATCH] [FIX] stock: remove 'set' and 'clear' quantities buttons Thanks to ref https://github.com/odoo/odoo/pull/137864, the quantity on stock move can be emptied or fill with the unreserve/reserve mechanism. Those two buttons becomes useless closes odoo/odoo#140116 Signed-off-by: Arnold Moyaux (arm) --- .../tests/test_subcontracting.py | 6 +++--- .../tests/test_subcontracting_account.py | 2 +- addons/stock/models/stock_move.py | 2 +- addons/stock/models/stock_picking.py | 13 ++----------- addons/stock/tests/test_move2.py | 2 +- addons/stock/tests/test_stock_flow.py | 6 ++---- addons/stock/views/stock_picking_views.xml | 3 --- .../models/stock_picking_batch.py | 15 ++------------- .../views/stock_picking_batch_views.xml | 4 ---- 9 files changed, 12 insertions(+), 41 deletions(-) diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index b73ed92bf29..0aff3178749 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -890,7 +890,7 @@ class TestSubcontractingTracking(TransactionCase): move.quantity = nb_finished_product picking_receipt = picking_form.save() picking_receipt.action_confirm() - picking_receipt.action_clear_quantities_to_zero() + picking_receipt.do_unreserve() # We shouldn't be able to call the 'record_components' button self.assertEqual(picking_receipt.display_action_record_components, 'hide') @@ -1331,7 +1331,7 @@ class TestSubcontractingSerialMassReceipt(TransactionCase): # Receive for quantity in quantities: # Receive finished products - picking_receipt.action_clear_quantities_to_zero() + picking_receipt.do_unreserve() Form(self.env['stock.assign.serial'].with_context( default_move_id=picking_receipt.move_ids[0].id, default_next_serial_number=self.env['stock.lot']._get_next_serial(picking_receipt.company_id, picking_receipt.move_ids[0].product_id) or 'sn#1', @@ -1361,7 +1361,7 @@ class TestSubcontractingSerialMassReceipt(TransactionCase): move.product_uom_qty = quantity picking_receipt = picking_form.save() picking_receipt.action_confirm() - picking_receipt.action_clear_quantities_to_zero() + picking_receipt.do_unreserve() # Receive finished products Form(self.env['stock.assign.serial'].with_context( default_move_id=picking_receipt.move_ids[0].id, diff --git a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py index a0ac489befb..dc7fe1ee3dd 100644 --- a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py +++ b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py @@ -243,7 +243,7 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): # Mimic the extra cost on the po line picking_receipt.move_ids.price_unit = 50 picking_receipt.action_confirm() - picking_receipt.action_clear_quantities_to_zero() + picking_receipt.do_unreserve() # We should be able to call the 'record_components' button self.assertTrue(picking_receipt.display_action_record_components) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 89ca2751915..cef54a2a222 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -788,7 +788,7 @@ Please change the quantity done or the rounding precision of your unit of measur def _do_unreserve(self): moves_to_unreserve = OrderedSet() for move in self: - if move.state == 'cancel' or (move.state == 'done' and move.scrapped): + if move.state == 'cancel' or (move.state == 'done' and move.scrapped) or move.picked: # We may have cancelled move in an open picking in a "propagate_cancel" scenario. # We may have done move in an open picking in a scrap scenario. continue diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 8d18df23de4..db79409515d 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -517,6 +517,7 @@ class Picking(models.Model): ('available', 'Available'), ('expected', 'Expected'), ('late', 'Late')], compute='_compute_products_availability') + # To remove in Master show_set_qty_button = fields.Boolean(compute='_compute_show_qty_button') show_clear_qty_button = fields.Boolean(compute='_compute_show_qty_button') @@ -529,17 +530,10 @@ class Picking(models.Model): ('name_uniq', 'unique(name, company_id)', 'Reference must be unique per company!'), ] - @api.depends('move_ids.product_uom_qty', 'move_ids.quantity') + @api.depends() def _compute_show_qty_button(self): self.show_set_qty_button = False self.show_clear_qty_button = False - for picking in self: - if picking.state in ['draft', 'done', 'cancel']: - continue - if any(float_is_zero(m.quantity, precision_rounding=m.product_uom.rounding) and not float_is_zero(m.product_uom_qty, precision_rounding=m.product_uom.rounding) for m in picking.move_ids): - picking.show_set_qty_button = True - elif any(not float_is_zero(m.quantity, precision_rounding=m.product_uom.rounding) for m in picking.move_ids): - picking.show_clear_qty_button = True def _compute_has_tracking(self): for picking in self: @@ -1164,9 +1158,6 @@ class Picking(models.Model): } return True - def action_clear_quantities_to_zero(self): - self.move_ids.filtered(lambda m: not m.picked)._do_unreserve() - def _pre_action_done_hook(self): for picking in self: if all(not move.picked for move in picking.move_ids): diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index bf52f01b894..e973a243eb9 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -2433,7 +2433,7 @@ class TestStockUOM(TestStockCommon): 'location_dest_id': self.stock_location }) picking_in.action_confirm() - picking_in.action_clear_quantities_to_zero() + picking_in.do_unreserve() self.assertEqual(move.product_uom_qty, 60.00, 'Wrong T_GT quantity') self.assertEqual(move.product_qty, 134400.00, 'Wrong T_LBS quantity') diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 67f0435a15f..ea6b6512322 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -2213,12 +2213,10 @@ class TestStockFlow(TestStockCommon): self.assertEqual(move_a.quantity, 10) self.assertEqual(move_b.quantity, 10) - # test clear qty button without manual change - self.assertTrue(picking_in.show_clear_qty_button) - picking_in.action_clear_quantities_to_zero() + # test unreserve button without manual change + picking_in.do_unreserve() self.assertEqual(move_a.quantity, 0) self.assertEqual(move_b.quantity, 0) - self.assertFalse(picking_in.show_clear_qty_button) # test set qty button with manual change move_a.quantity = 5 diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index 8c2d804ab24..03334fc6220 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -139,8 +139,6 @@ - -
@@ -148,7 +146,6 @@