Files
odoo_source/addons/stock/wizard/stock_immediate_transfer.py
T
Simon Lejeune 7ed86b53cd [FIX] stock: immediate transfer and unreserved move
Before the patch, validating a picking where one of its move do not
have any quantity done nor quantity reserved resulted in the complete
validation of the said move. This doesn't make sense and does not do
what the help in the wizard indicate (process only *reserved* quantities).

We also use this patch to clarify what the tests on this workflow is
doing (test_immediate_validate_*). We completely replace the 3 as it was
testing the `force_assign` mechanism, which methods are still present in
v11 but unused. Instead this test is now testing the failing flow this
commit is fixing.

We thus adapt the `process` method of the immediate transfer to only
process the move lines (move line = reservation). We also fix a case
where nothing is reserved and nothing is done. In this case, the
backorder wizard should not opens but instead an UserError telling the
user to either cancel or process something. The testcase for this flow
is test_immediate_validate_7.

With these changes, the test `test_04_create_picking_update_saleorderline`
was failing because one of the items in the so lines was a stockable
product without stock. So before this patch, everything was processed,
now there's a backorder wizard. We complete the patch and duplicate it
with enough products in stock, so that the backorder wizard is not
needed.

opw-815056
opw-808126
2018-02-20 14:42:44 +01:00

38 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo.exceptions import UserError
class StockImmediateTransfer(models.TransientModel):
_name = 'stock.immediate.transfer'
_description = 'Immediate Transfer'
pick_ids = fields.Many2many('stock.picking', 'stock_picking_transfer_rel')
def process(self):
pick_to_backorder = self.env['stock.picking']
pick_to_do = self.env['stock.picking']
for picking in self.pick_ids:
# If still in draft => confirm and assign
if picking.state == 'draft':
picking.action_confirm()
if picking.state != 'assigned':
picking.action_assign()
if picking.state != 'assigned':
raise UserError(_("Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually."))
for move in picking.move_lines:
for move_line in move.move_line_ids:
move_line.qty_done = move_line.product_uom_qty
if picking._check_backorder():
pick_to_backorder |= picking
continue
pick_to_do |= picking
# Process every picking that do not require a backorder, then return a single backorder wizard for every other ones.
if pick_to_do:
pick_to_do.action_done()
if pick_to_backorder:
return pick_to_backorder.action_generate_backorder_wizard()
return False