-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF]stock_auto_move: fix action_assign()
**Use case**: doing a reception operation in two steps where the moves on the second step are set to be automatic (using the push rule in this case), and the reception is done partially. **Expected Result**: When doing a first reception step partially a back order is created, and we expect the second step to have a back order for the remaining qty as well. **Current behavior**: The correct move is processed automatically but no backorder is created. The reason for that behavior is we processing the move directly (i.e calling `action_done` of the `stock.move`) without going through the normal process (i.e processing the second step picking). **The solution to the problem**: The processing the of the automatic stock move should follow the same behavior as done from the user interface. I've added a new function in `stock.picking` model called `_transfer_pickings_with_auto_move` to simulate the same behavior this function is called inside the `action_assign` of the stock move instead of calling the `action_done` of the move.
- Loading branch information
Showing
5 changed files
with
273 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- coding: utf-8 -*- | ||
from . import stock_move | ||
from . import procurement_rule | ||
from . import procurement_order | ||
from . import stock_location_path | ||
from . import stock_pack_operation | ||
from . import stock_picking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models | ||
|
||
|
||
class StockPackOperation(models.Model): | ||
|
||
_inherit = 'stock.pack.operation' | ||
|
||
@api.multi | ||
def _auto_fill_pack_lot_ids_qty(self): | ||
""" | ||
This method automatically fills quantites of the lots | ||
used in operations and also update the qty done on | ||
those operations. | ||
This method is meant to be used with automatic moves. | ||
""" | ||
operations = self.filtered( | ||
lambda o: o.pack_lot_ids and o.product_id and | ||
not o.package_id and not o.result_package_id) | ||
for operation in operations: | ||
for pack_lot in operations.mapped('pack_lot_ids'): | ||
if not pack_lot.qty: | ||
pack_lot.qty = pack_lot.qty_todo | ||
operation.qty_done = operation.product_qty | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models | ||
|
||
|
||
class StockPicking(models.Model): | ||
|
||
_inherit = 'stock.picking' | ||
|
||
@api.model | ||
def _transfer_pickings_with_auto_move(self, auto_moves_by_pickings): | ||
"""This function is meant to simulate what a user would normally | ||
transfer a picking from the user interface either partial processing | ||
or full processing. | ||
@params auto_moves_by_pickings: dict of moves grouped by pickings | ||
{stock.picking(id): stock.move(id1, id2, id3 ...), ...} | ||
""" | ||
for picking in auto_moves_by_pickings: | ||
if len(picking.move_lines) == len(auto_moves_by_pickings[picking]): | ||
# Create immediate transfer wizard so it will fill the qty_done | ||
# on the auto move linked operation | ||
wizard = self.env['stock.immediate.transfer'].create( | ||
{'pick_id': picking.id}) | ||
wizard.process() | ||
else: | ||
# create back order with the auto moves | ||
backorder = picking.copy( | ||
default={ | ||
'name': '/', | ||
'move_lines': [], | ||
'backorder_id': picking.id}) | ||
# move the operations related to the auto moves to the new | ||
# picking | ||
auto_moves_by_pickings[picking].write( | ||
{'picking_id': backorder.id}) | ||
auto_moves_by_pickings[picking].mapped( | ||
'linked_move_operation_ids.operation_id').write({ | ||
'picking_id': backorder.id}) | ||
backorder.action_confirm() | ||
backorder.with_context( | ||
no_check_auto_moves=True).action_assign() | ||
|
||
# Create immediate transfer wizard so it will fill the qty_done | ||
# on the auto move linked operation | ||
wizard = self.env['stock.immediate.transfer'].create( | ||
{'pick_id': backorder.id}) | ||
wizard.process() | ||
|
||
return | ||
|
||
@api.multi | ||
def _add_pack_ops_serials(self): | ||
""" For pickings with operations matching certain condition, this | ||
method select automatically the lots to be used in the transfer. | ||
The conditions are: | ||
- The tracking on the operation product has to be set to serial. | ||
- The qty to process is set. | ||
""" | ||
for rec in self: | ||
if not all([m.auto_move for m in rec.move_lines]): | ||
continue | ||
auto_select_ops = rec.pack_operation_ids.filtered( | ||
lambda op: | ||
op.product_id.tracking != 'none' and | ||
op.pack_lot_ids and op.qty_done) | ||
for operation in auto_select_ops: | ||
selected_lots = \ | ||
list(operation.pack_lot_ids)[:int(operation.qty_done)] | ||
for lot in selected_lots: | ||
lot.do_plus() | ||
|
||
@api.multi | ||
def do_transfer(self): | ||
self._add_pack_ops_serials() | ||
return super(StockPicking, self).do_transfer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters