forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
32 lines (25 loc) · 1.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
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo import SUPERUSER_ID, api
from odoo.tools.sql import column_exists, create_column
_logger = logging.getLogger(__name__)
def post_init_hook(cr, registry):
"""Post init hook to set compute the volume on pending move and pickings."""
env = api.Environment(cr, SUPERUSER_ID, {})
pickings = env["stock.picking"].search([("state", "not in", ["done", "cancel"])])
moves = env["stock.move"].search(
[
"|",
("state", "not in", ["done", "cancel"]),
("picking_id", "in", pickings.ids),
]
)
_logger.info("Compute volumes for %d moves", len(moves))
moves._compute_volume()
def pre_init_hook(cr):
"""Pre init create volume column on stock.picking and stock.move"""
if not column_exists(cr, "stock_move", "volume"):
create_column(cr, "stock_move", "volume", "numeric")
if not column_exists(cr, "stock_picking", "volume"):
create_column(cr, "stock_picking", "volume", "numeric")