Files
account-financial-tools/account_move_line_purchase_info/hooks.py
Jordi Ballester 84d19303da [FIX] account_move_line_purchase_info: migration and init hook
Add an init hook and a migration in order to make sure
that account move lines connected with stock moves get the
connecting purchase order line.
2023-12-31 19:50:57 +01:00

21 lines
582 B
Python

# Copyright 2022 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
def post_init_hook(cr, registry):
"""INIT purchase_line_id in acount move line"""
# FOR stock moves
cr.execute(
"""
UPDATE account_move_line aml SET purchase_line_id = sm.purchase_line_id
FROM account_move_line aml2
INNER JOIN account_move am
ON am.id = aml2.move_id
INNER JOIN stock_move sm ON
am.stock_move_id = sm.id
WHERE aml.id = aml2.id
AND sm.purchase_line_id IS NOT NULL;
"""
)