forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 5
/
hooks.py
59 lines (54 loc) · 2.07 KB
/
hooks.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
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo.tools import sql
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
"""Initialize picking_kind field based on location_id and location_dest_id"""
if not sql.column_exists(cr, "stock_picking", "picking_kind"):
_logger.info("Create picking_kind column")
cr.execute(
"""
ALTER TABLE stock_picking
ADD COLUMN picking_kind character varying;
"""
)
_logger.info("Initialize picking_kind field")
cr.execute(
"""
UPDATE stock_picking
SET picking_kind = (
CASE
WHEN
origin.usage = 'supplier'
AND destination.usage = 'customer'
THEN 'drop_shipping'
WHEN
origin.usage = 'customer'
AND destination.usage = 'supplier'
THEN 'drop_shipping_return'
WHEN
origin.usage = 'customer'
AND destination.usage != 'customer'
THEN 'customer_return'
WHEN
origin.usage != 'customer'
AND destination.usage = 'customer'
THEN 'customer_out'
WHEN
origin.usage = 'supplier'
AND destination.usage != 'supplier'
THEN 'supplier_in'
WHEN
origin.usage != 'supplier'
AND destination.usage = 'supplier'
THEN 'supplier_return'
ELSE NULL
END
)
FROM stock_location origin, stock_location destination
WHERE stock_picking.location_id = origin.id
AND stock_picking.location_dest_id = destination.id
"""
)
_logger.info(f"{cr.rowcount} rows updated")