Skip to content

Commit

Permalink
[REF]stock_auto_move: fix action_action()
Browse files Browse the repository at this point in the history
**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
zakiuu committed Sep 29, 2017
1 parent 9f8dc2f commit 038637d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions stock_auto_move/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +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
2 changes: 1 addition & 1 deletion stock_auto_move/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def action_assign(self, no_prepare=False):
todo_pickings = moves.mapped('picking_id')
# We create packing operations to keep packing if any
todo_pickings.do_prepare_partial()
moves.action_done()
todo_pickings._transfer_pickings_with_auto_move()

@api.multi
def action_done(self):
Expand Down
27 changes: 27 additions & 0 deletions stock_auto_move/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- 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.multi
def _transfer_pickings_with_auto_move(self):
"""This function is meant to simulate what a user would normally
transfer a picking from the user interface either partial processing
or full processing."""
for picking in self:
res = picking.do_new_transfer()
if res:
if not res.get('res_model') or not res.get('res_id'):
continue
wizard = self.env[res.get('res_model')].browse(
res.get('res_id'))
wizard.process()
else:
continue
return

0 comments on commit 038637d

Please sign in to comment.