Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stock_picking_force_assign/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "AGPL-3",
"depends": [
"stock",
"purchase",
],
"data": [
"security/stock_picking_force_assign_security.xml",
Expand Down
8 changes: 8 additions & 0 deletions stock_picking_force_assign/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _force_assign_find_moves(self):
precision_digits=result._fields['product_qty'].digits,
)

stock_available = False
for move in self.mapped('move_lines'):
if move.state == 'cancel':
continue
Expand All @@ -55,6 +56,7 @@ def _force_assign_find_moves(self):
move.availability
)
if float_compare(demand, 0) <= 0:
stock_available = True
continue
candidates = self.env['stock.move'].search([
('id', 'not in', result.ids),
Expand All @@ -63,6 +65,8 @@ def _force_assign_find_moves(self):
('product_id', '=', move.product_id.id),
('state', 'in', ('partially_available', 'assigned')),
], order='write_date asc')
if candidates and not stock_available:
stock_available = True

for candidate in candidates:
if float_compare(demand, 0) > 0:
Expand All @@ -78,6 +82,10 @@ def _force_assign_find_moves(self):
move.product_id.name, demand
)
)
if not stock_available:
raise exceptions.UserError(_(
'There is no sufficient stock in this location to reserve '
'stock for this order.'))
return result

def _unchain_waiting(self, link_template):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
class TestStockPickingForceAssign(TransactionCase):
def setUp(self, *args, **kwargs):
super().setUp(*args, **kwargs)
self.location = self.env.ref('stock.stock_location_stock')
route_buy = self.env['stock.location.route'].create({
'name': 'Buy',
'rule_ids': [(0, 0, {
'name': 'Buy',
'action': 'buy',
'action': 'pull',
'picking_type_id': self.env.ref('stock.picking_type_in').id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_id': self.location.id,
})]
})
route_mto = self.env.ref('stock.route_warehouse0_mto')
self.product = self.env['product.product'].create({
'name': 'stockable',
'type': 'product',
})
self.product = self.product = self.env.ref('product.product_delivery_01')
self.product2 = self.product.copy({
'name': 'stockable-mto',
'purchase_ok': True,
Expand All @@ -37,7 +35,7 @@ def setUp(self, *args, **kwargs):
self.assigned_picking = self.env['stock.picking'].create({
'name': 'Picking to unassign',
'picking_type_id': self.env.ref('stock.picking_type_out').id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_id': self.location.id,
'location_dest_id':
self.env.ref('stock.stock_location_customers').id,
'move_lines': [(0, 0, {
Expand Down Expand Up @@ -90,11 +88,14 @@ def test_happy_flow(self):

def test_on_done_picking(self):
""" Test force assigning a done picking """
self.env['ir.config_parameter'].set_param(
'stock_picking_force_assign.allow_partial', True)
self.waiting_picking.action_assign()
self.assigned_picking.move_line_ids.qty_done = 42
self.assigned_picking.action_done()
self.assertEqual(self.assigned_picking.state, 'done')
with self.assertRaises(UserError):
with self.assertRaisesRegex(
UserError, 'There is no sufficient stock in this location'):
self.waiting_picking.action_force_assign_pickings()

def test_partial(self):
Expand Down
2 changes: 1 addition & 1 deletion stock_split_picking/views/stock_partial_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="arch" type="xml">
<field name ="state" position="before">
<button name="%(stock_split_picking.action_stock_split_picking)s"
states="draft,confirmed,assigned"
states="draft,waiting,confirmed,assigned"
string="Split"
groups="stock.group_stock_user"
type="action"/>
Expand Down