Skip to content

Commit 8c90fc1

Browse files
R1D1CUL0USamoyaux
authored andcommitted
[IMP] {stock, mrp, repair}: allow picking_type change after confirm
Allow to change the picking type of picking, MO, RO even after they are confirmed. task-4104915 closes odoo#176456 Related: odoo/upgrade#6370 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
1 parent f3c7e6d commit 8c90fc1

File tree

7 files changed

+49
-43
lines changed

7 files changed

+49
-43
lines changed

addons/mrp/views/mrp_production_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@
530530
<page string="Miscellaneous" name="miscellaneous">
531531
<group>
532532
<group>
533-
<field name="picking_type_id" readonly="state != 'draft'"/>
533+
<field name="picking_type_id" readonly="state not in ('draft', 'confirmed')"/>
534534
<field name="location_src_id" groups="stock.group_stock_multi_locations" options="{'no_create': True}" readonly="state != 'draft'"/>
535535
<field name="location_src_id" groups="!stock.group_stock_multi_locations" invisible="1"/>
536536
<field name="warehouse_id" invisible="1"/>

addons/repair/views/repair_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
</page>
182182
<page string="Miscellaneous" name="page_miscellaneous">
183183
<group>
184-
<field name="picking_type_id" options="{'no_create': True}" readonly="state != 'draft'"/>
184+
<field name="picking_type_id" options="{'no_create': True}" readonly="state in ('done', 'cancel')"/>
185185
</group>
186186
<group string="Locations" groups="stock.group_stock_multi_locations" name="locations">
187187
<field name="location_id" readonly="state != 'draft'" options="{'no_create': True}"/>

addons/stock/models/stock_move.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,15 @@ def write(self, vals):
708708
move_to_check_location.procure_method = 'make_to_stock'
709709
move_to_check_location.move_orig_ids = [Command.clear()]
710710
ml.unlink()
711+
if 'location_id' in vals or 'location_dest_id' in vals:
712+
wh_by_moves = defaultdict(self.env['stock.move'].browse)
713+
for move in self:
714+
move_warehouse = move.location_id.warehouse_id or move.location_dest_id.warehouse_id
715+
if move_warehouse == move.warehouse_id:
716+
continue
717+
wh_by_moves[move_warehouse] |= move
718+
for warehouse, moves in wh_by_moves.items():
719+
moves.warehouse_id = warehouse.id
711720
if move_to_confirm:
712721
move_to_confirm._action_assign()
713722
if receipt_moves_to_reassign:

addons/stock/models/stock_picking.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ def _default_picking_type_id(self):
628628
picking_type_entire_packs = fields.Boolean(related='picking_type_id.show_entire_packs')
629629
use_create_lots = fields.Boolean(related='picking_type_id.use_create_lots')
630630
use_existing_lots = fields.Boolean(related='picking_type_id.use_existing_lots')
631-
hide_picking_type = fields.Boolean(compute='_compute_hide_picking_type')
632631
partner_id = fields.Many2one(
633632
'res.partner', 'Contact',
634633
check_company=True, index='btree_not_null')
@@ -711,11 +710,6 @@ def _compute_has_deadline_issue(self):
711710
for picking in self:
712711
picking.has_deadline_issue = picking.date_deadline and picking.date_deadline < picking.scheduled_date or False
713712

714-
@api.depends('state')
715-
def _compute_hide_picking_type(self):
716-
for picking in self:
717-
picking.hide_picking_type = picking.state != "draft" and picking.ids and 'default_picking_type_id' in picking.env.context
718-
719713
@api.depends('move_ids.delay_alert_date')
720714
def _compute_delay_alert_date(self):
721715
delay_alert_date_data = self.env['stock.move']._read_group([('id', 'in', self.move_ids.ids), ('delay_alert_date', '!=', False)], ['picking_id'], ['delay_alert_date:max'])
@@ -929,7 +923,7 @@ def _compute_show_allocation(self):
929923
@api.depends('picking_type_id', 'partner_id')
930924
def _compute_location_id(self):
931925
for picking in self:
932-
if picking.state != 'draft' or picking.return_id:
926+
if picking.state in ('cancel', 'done') or picking.return_id:
933927
continue
934928
picking = picking.with_company(picking.company_id)
935929
if picking.picking_type_id:
@@ -1086,7 +1080,7 @@ def create(self, vals_list):
10861080
return pickings
10871081

10881082
def write(self, vals):
1089-
if vals.get('picking_type_id') and any(picking.state != 'draft' for picking in self):
1083+
if vals.get('picking_type_id') and any(picking.state in ('done', 'cancel') for picking in self):
10901084
raise UserError(_("Changing the operation type of this record is forbidden at this point."))
10911085
# set partner as a follower and unfollow old partner
10921086
if vals.get('partner_id'):

addons/stock/tests/test_packing.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,34 +1728,6 @@ def test_change_package_location(self):
17281728
with self.assertRaises(UserError):
17291729
pack_1.location_id = self.shelf1
17301730

1731-
def test_compute_hide_picking_type_multiple_records(self):
1732-
"""
1733-
Create two pickings and compute their respective hide picking types together.
1734-
"""
1735-
picking1 = self.env['stock.picking'].create({
1736-
'location_id': self.stock_location.id,
1737-
'location_dest_id': self.customer_location.id,
1738-
'picking_type_id': self.env.ref('stock.picking_type_out').id,
1739-
})
1740-
self.env['stock.move'].create({
1741-
'name': self.productA.name,
1742-
'product_id': self.productA.id,
1743-
'product_uom_qty': 10,
1744-
'product_uom': self.productA.uom_id.id,
1745-
'picking_id': picking1.id,
1746-
'location_id': self.stock_location.id,
1747-
'location_dest_id': self.customer_location.id,
1748-
})
1749-
picking1.action_confirm()
1750-
picking2 = self.env['stock.picking'].create({
1751-
'location_id': self.stock_location.id,
1752-
'location_dest_id': self.customer_location.id,
1753-
'picking_type_id': self.env.ref('stock.picking_type_out').id,
1754-
})
1755-
(picking1 | picking2).with_context(default_picking_type_id=self.ref('stock.picking_type_out'))._compute_hide_picking_type()
1756-
self.assertTrue(picking1.hide_picking_type)
1757-
self.assertFalse(picking2.hide_picking_type)
1758-
17591731
def test_action_split_transfer(self):
17601732
""" Check Split Picking if quantity `0 <= done < demand`
17611733
"""

addons/stock/tests/test_warehouse.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from odoo import Command
44
from odoo.addons.stock.tests.common import TestStockCommon
55
from odoo.tests import Form
6-
from odoo.exceptions import UserError
7-
from odoo.tools import mute_logger
86

97

108
class TestWarehouse(TestStockCommon):
@@ -818,3 +816,37 @@ def test_location_warehouse(self):
818816
test_warehouse.sequence = 100
819817
location._compute_warehouse_id()
820818
self.assertEqual(location.warehouse_id, test_warehouse)
819+
820+
def test_location_updates_wh(self):
821+
warehouse_A = self.env['stock.warehouse'].create({
822+
'name': 'Warehouse X',
823+
'code': 'WH_X',
824+
'delivery_steps': 'pick_pack_ship'
825+
})
826+
warehouse_B = self.env['stock.warehouse'].create({
827+
'name': 'Warehouse Y',
828+
'code': 'WH_Y',
829+
'delivery_steps': 'pick_pack_ship'
830+
})
831+
picking_out = self.env['stock.picking'].create({
832+
'partner_id': self.partner.id,
833+
'picking_type_id': warehouse_A.pick_type_id.id,
834+
'location_id': warehouse_A.lot_stock_id.id,
835+
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
836+
})
837+
customer_move = self.env['stock.move'].create({
838+
'name': self.product.name,
839+
'product_id': self.product.id,
840+
'product_uom_qty': 1,
841+
'product_uom': self.product.uom_id.id,
842+
'picking_id': picking_out.id,
843+
'location_id': warehouse_A.lot_stock_id.id,
844+
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
845+
})
846+
picking_form = Form(picking_out)
847+
picking_form.picking_type_id = warehouse_B.pick_type_id
848+
picking_form.save()
849+
self.assertEqual(customer_move.warehouse_id, warehouse_B)
850+
self.assertEqual(picking_out.picking_type_id, warehouse_B.pick_type_id)
851+
picking_out.button_validate()
852+
self.assertEqual(customer_move.move_dest_ids.warehouse_id, warehouse_B)

addons/stock/views/stock_picking_views.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,8 @@
222222
</div>
223223
<field name="partner_id" nolabel="1" readonly="state in ['cancel', 'done']" placeholder="e.g. Lumber Inc"/>
224224
<field name="picking_type_id" options="{'no_open': True}"
225-
invisible="hide_picking_type"
226-
readonly="state != 'draft' and id"
227-
domain="context.get('restricted_picking_type_code') and [('code', '=', context.get('restricted_picking_type_code'))] or [(1,'=',1)]"/>
225+
readonly="state in ('done', 'cancel')"
226+
domain="[('code', 'in', ('incoming', 'outgoing', 'internal'))]" />
228227
<field name="location_id" groups="!stock.group_stock_multi_locations" invisible="1" readonly="state == 'done'"/>
229228
<field name="location_dest_id" groups="!stock.group_stock_multi_locations" invisible="1" readonly="state == 'done'"/>
230229
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations" invisible="picking_type_code == 'incoming'" readonly="state == 'done'"/>

0 commit comments

Comments
 (0)