-
-
Notifications
You must be signed in to change notification settings - Fork 695
/
quick_add_location.py
79 lines (72 loc) · 2.64 KB
/
quick_add_location.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# coding: utf-8
# © 2017 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models, api, fields
class QuickAddProductLocation(models.TransientModel):
_name = "quick.add.product.location"
def _default_putaway(self):
""" Overridable method
"""
return self.env.ref(
"stock_putaway_product.product_putaway_per_product_wh",
raise_if_not_found=False,
)
putaway_id = fields.Many2one(
comodel_name="product.putaway",
string="Put Away Method",
required=True,
default=lambda self: self._default_putaway(),
)
fixed_location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True
)
product_ids = fields.Many2many(
comodel_name="product.product", string="Products", required=True
)
@api.model
def default_get(self, fields):
res = super(QuickAddProductLocation, self).default_get(fields)
product_ids = self.env.context.get("active_ids")
if product_ids:
res["product_ids"] = product_ids
return res
@api.multi
def apply_location(self):
self.ensure_one()
products = {}
for product in self.product_ids:
products.setdefault(
product.product_tmpl_id, self.env["product.product"].browse()
)
products[product.product_tmpl_id] |= product
# Remove existing putaway locations
self.env["stock.product.putaway.strategy"].search(
[
("putaway_id", "=", self.putaway_id.id),
("product_product_id", "in", self.product_ids._ids),
]
).unlink()
for template in products:
products[template].write(
{
"product_putaway_ids": [
(
0,
0,
{
"putaway_id": self.putaway_id.id,
"product_tmpl_id": template.id,
"fixed_location_id": self.fixed_location_id.id,
},
)
]
}
)
product_names = ", ".join([x.name for x in self.product_ids])
return {
"name": _("Updated products putaway: %s" % product_names),
"type": "ir.actions.act_window",
"res_id": self.env.ref("product.product_normal_action").id,
"view_mode": "tree,form",
"res_model": "product.product",
}