[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
This commit is contained in:
William Henrotin
2023-09-20 10:02:05 +00:00
parent fc716160d2
commit fc326082c8
3 changed files with 18 additions and 4 deletions
+6 -3
View File
@@ -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`.
+11
View File
@@ -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')
+1 -1
View File
@@ -130,7 +130,7 @@
<button name="action_assign" invisible="not show_check_availability" string="Check Availability" type="object" class="oe_highlight" groups="base.group_user" data-hotkey="w"/>
<button name="button_validate" invisible="state in ('waiting', 'confirmed', 'draft', 'done', 'cancel') or not show_validate" string="Validate" type="object" class="oe_highlight" groups="stock.group_stock_user" data-hotkey="v"/>
<button name="button_validate" invisible="state in ('draft', 'assigned', 'done', 'cancel') or not show_validate" string="Validate" type="object" groups="stock.group_stock_user" class="o_btn_validate" data-hotkey="v"/>
<button name="action_reset_draft" invisible="state in ('draft', 'done', 'cancel')" string="Set Draft" type="object" groups="stock.group_stock_user" class="o_highlight" data-hotkey="d"/>
<button name="action_reset_draft" invisible="state in ('draft', 'done', 'cancel') or not immediate_transfer" string="Plan" type="object" groups="stock.group_stock_user" class="o_highlight" data-hotkey="d"/>
<button name="action_set_quantities_to_reservation" invisible="not show_set_qty_button" string="Set quantities" type="object" groups="stock.group_stock_user" class="o_btn_validate" data-hotkey="g"/>
<button name="action_clear_quantities_to_zero" invisible="not show_clear_qty_button" string="Clear quantities" type="object" groups="stock.group_stock_user" class="o_btn_validate" data-hotkey="g"/>
<widget name="signature" string="Sign" highlight="1"