forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
32 lines (27 loc) · 1.01 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 2022-2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo.tools.sql import column_exists, create_column
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
if not column_exists(cr, "stock_valuation_layer", "accounting_date"):
_logger.info("Creating column 'accounting_date' in stock_valuation_layer.")
create_column(cr, "stock_valuation_layer", "accounting_date", "date")
_logger.info("Updating accounting_date with account_move.date.")
cr.execute(
"""
UPDATE stock_valuation_layer svl
SET accounting_date = am.date
FROM account_move am
WHERE svl.account_move_id = am.id
AND am.state = 'posted'
"""
)
_logger.info("Updating 'account_date' with stock_valuation_layer.create_date.")
cr.execute(
"""
UPDATE stock_valuation_layer svl
SET accounting_date = svl.create_date::date
WHERE svl.accounting_date IS NULL
"""
)