forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock_split_picking.py
57 lines (46 loc) · 1.83 KB
/
stock_split_picking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2020 Hunki Enterprises BV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class StockSplitPicking(models.TransientModel):
_name = "stock.split.picking"
_description = "Split a picking"
mode = fields.Selection(
[
("quantity", "Quantities"),
("move", "One picking per move"),
("selection", "Select move lines to split off"),
],
required=True,
default="quantity",
)
picking_ids = fields.Many2many(
"stock.picking",
default=lambda self: self._default_picking_ids(),
)
move_ids = fields.Many2many("stock.move")
def _default_picking_ids(self):
return self.env["stock.picking"].browse(self.env.context.get("active_ids", []))
def action_apply(self):
return getattr(self, "_apply_%s" % self[:1].mode)()
def _apply_quantity(self):
return self.mapped("picking_ids").split_process()
def _apply_move(self):
"""Create new pickings for every move line, keep first
move line in original picking
"""
new_pickings = self.env["stock.picking"]
for picking in self.mapped("picking_ids"):
for move in picking.move_ids[1:]:
new_pickings += picking._split_off_moves(move)
return self._picking_action(new_pickings)
def _apply_selection(self):
"""Create one picking for all selected moves"""
moves = self.mapped("move_ids")
new_picking = moves.mapped("picking_id")._split_off_moves(moves)
return self._picking_action(new_picking)
def _picking_action(self, pickings):
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.action_picking_tree_all",
)
action["domain"] = [("id", "in", pickings.ids)]
return action