summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Baes <arb@odoo.com>2019-10-22 11:35:00 +0000
committerSimon Lejeune <sle@openerp.com>2019-10-23 07:39:30 +0000
commit3e9a74aed41b3d90fbccb962b19fca83b30d925c (patch)
treeb90cc1a6338097a4051a12270a2ffa3d06e5b4e3
parentd128200f1827b80d3f4c04b53dc187b2d73bbe73 (diff)
[REF] stock: action_done cleaning
* rewrite the docstring * rename pick -> picking * rename ops -> move_line * remove commented code task-1938108
-rw-r--r--addons/stock/models/stock_picking.py70
1 files changed, 27 insertions, 43 deletions
diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py
index 7d37fd119b7..ed66fa74998 100644
--- a/addons/stock/models/stock_picking.py
+++ b/addons/stock/models/stock_picking.py
@@ -648,60 +648,44 @@ class Picking(models.Model):
return True
def action_done(self):
- """Changes picking state to done by processing the Stock Moves of the Picking
+ """Call `_action_done` on the `stock.move` of the `stock.picking` in `self`.
+ This method makes sure every `stock.move.line` is linked to a `stock.move` by either
+ linking them to an existing one or a newly created one.
- Normally that happens when the button "Done" is pressed on a Picking view.
- @return: True
+ If the context key `cancel_backorder` is present, backorders won't be created.
+
+ :return: True
+ :rtype: bool
"""
self._check_company()
todo_moves = self.mapped('move_lines').filtered(lambda self: self.state in ['draft', 'waiting', 'partially_available', 'assigned', 'confirmed'])
- # Check if there are ops not linked to moves yet
- for pick in self:
- if pick.owner_id:
- pick.move_lines.write({'restrict_partner_id': pick.owner_id.id})
- pick.move_line_ids.write({'owner_id': pick.owner_id.id})
-
- # # Explode manually added packages
- # for ops in pick.move_line_ids.filtered(lambda x: not x.move_id and not x.product_id):
- # for quant in ops.package_id.quant_ids: #Or use get_content for multiple levels
- # self.move_line_ids.create({'product_id': quant.product_id.id,
- # 'package_id': quant.package_id.id,
- # 'result_package_id': ops.result_package_id,
- # 'lot_id': quant.lot_id.id,
- # 'owner_id': quant.owner_id.id,
- # 'product_uom_id': quant.product_id.uom_id.id,
- # 'product_qty': quant.qty,
- # 'qty_done': quant.qty,
- # 'location_id': quant.location_id.id, # Could be ops too
- # 'location_dest_id': ops.location_dest_id.id,
- # 'picking_id': pick.id
- # }) # Might change first element
- # # Link existing moves or add moves when no one is related
- for ops in pick.move_line_ids.filtered(lambda x: not x.move_id):
- # Search move with this product
- moves = pick.move_lines.filtered(lambda x: x.product_id == ops.product_id)
+ for picking in self:
+ if picking.owner_id:
+ picking.move_lines.write({'restrict_partner_id': picking.owner_id.id})
+ picking.move_line_ids.write({'owner_id': picking.owner_id.id})
+ for move_line in picking.move_line_ids.filtered(lambda x: not x.move_id):
+ moves = picking.move_lines.filtered(lambda x: x.product_id == move_line.product_id)
moves = sorted(moves, key=lambda m: m.quantity_done < m.product_qty, reverse=True)
if moves:
- ops.move_id = moves[0].id
+ move_line.move_id = moves[0].id
else:
new_move = self.env['stock.move'].create({
- 'name': _('New Move:') + ops.product_id.display_name,
- 'product_id': ops.product_id.id,
- 'product_uom_qty': ops.qty_done,
- 'product_uom': ops.product_uom_id.id,
- 'description_picking': ops.description_picking,
- 'location_id': pick.location_id.id,
- 'location_dest_id': pick.location_dest_id.id,
- 'picking_id': pick.id,
- 'picking_type_id': pick.picking_type_id.id,
- 'restrict_partner_id': pick.owner_id.id,
- 'company_id': pick.company_id.id,
- })
- ops.move_id = new_move.id
+ 'name': _('New Move:') + move_line.product_id.display_name,
+ 'product_id': move_line.product_id.id,
+ 'product_uom_qty': move_line.qty_done,
+ 'product_uom': move_line.product_uom_id.id,
+ 'description_picking': move_line.description_picking,
+ 'location_id': picking.location_id.id,
+ 'location_dest_id': picking.location_dest_id.id,
+ 'picking_id': picking.id,
+ 'picking_type_id': picking.picking_type_id.id,
+ 'restrict_partner_id': picking.owner_id.id,
+ 'company_id': picking.company_id.id,
+ })
+ move_line.move_id = new_move.id
new_move._action_confirm()
todo_moves |= new_move
- #'qty_done': ops.qty_done})
todo_moves._action_done(cancel_backorder=self.env.context.get('cancel_backorder'))
self.write({'date_done': fields.Datetime.now()})
self._send_confirmation_email()