forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
30 lines (25 loc) · 976 Bytes
/
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
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo.tools import sql
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
"""Initialise the commercial_partner_id field on stock.picking"""
if not sql.column_exists(cr, "stock_picking", "commercial_partner_id"):
_logger.info("Create column commercial_partner_id on stock_picking")
cr.execute(
"""
ALTER TABLE stock_picking ADD COLUMN commercial_partner_id integer;
"""
)
_logger.info("Init commercial_partner_id on stock_picking")
cr.execute(
"""
UPDATE stock_picking
SET commercial_partner_id = res_partner.commercial_partner_id
FROM res_partner
WHERE
stock_picking.partner_id = res_partner.id;
"""
)
_logger.info(f"{cr.rowcount} rows updated in stock_picking")