2023-08-04 11:10:11 +02:00
|
|
|
# Copyright 2019-23 ForgeFlow S.L.
|
2020-05-15 15:12:20 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
|
|
|
|
def post_init_hook(cr, registry):
|
|
|
|
|
2021-11-09 14:38:50 +01:00
|
|
|
"""INIT sale references in account move line"""
|
2020-05-15 15:12:20 +02:00
|
|
|
# FOR stock moves
|
2020-07-29 17:26:15 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2021-05-03 14:04:28 +02:00
|
|
|
UPDATE account_move_line aml SET sale_line_id = sm.sale_line_id
|
2020-05-15 15:12:20 +02:00
|
|
|
FROM account_move_line aml2
|
|
|
|
INNER JOIN stock_move sm ON
|
|
|
|
aml2.stock_move_id = sm.id
|
|
|
|
WHERE aml.id = aml2.id;
|
2020-07-29 17:26:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2020-05-15 15:12:20 +02:00
|
|
|
# FOR invoices
|
2020-07-29 17:26:15 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2021-05-03 14:04:28 +02:00
|
|
|
UPDATE account_move_line aml SET sale_line_id = sol.id
|
2020-05-15 15:12:20 +02:00
|
|
|
FROM account_move_line aml2
|
2021-05-03 14:04:28 +02:00
|
|
|
INNER JOIN account_move am ON
|
|
|
|
am.id = aml2.move_id
|
2020-05-15 15:12:20 +02:00
|
|
|
INNER JOIN sale_order_line_invoice_rel rel ON
|
2021-05-03 14:04:28 +02:00
|
|
|
rel.invoice_line_id = aml2.id
|
2020-05-15 15:12:20 +02:00
|
|
|
INNER JOIN sale_order_line sol ON
|
|
|
|
rel.order_line_id = sol.id
|
2020-05-18 15:34:53 +02:00
|
|
|
AND sol.product_id = aml2.product_id
|
2020-05-15 15:12:20 +02:00
|
|
|
WHERE aml.id = aml2.id;
|
2020-07-29 17:26:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2020-05-15 15:12:20 +02:00
|
|
|
|
|
|
|
# NOW we can fill the SO
|
2020-07-29 17:26:15 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2020-05-15 15:12:20 +02:00
|
|
|
UPDATE account_move_line aml
|
2021-05-03 14:04:28 +02:00
|
|
|
SET sale_order_id = sol.order_id
|
2020-05-15 15:12:20 +02:00
|
|
|
FROM sale_order_line AS sol
|
|
|
|
WHERE aml.sale_line_id = sol.id
|
2020-05-18 15:34:53 +02:00
|
|
|
RETURNING aml.move_id
|
2020-07-29 17:26:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2020-05-18 15:34:53 +02:00
|
|
|
|
|
|
|
# NOW we can fill the lines without invoice_id (Odoo put it very
|
|
|
|
# complicated)
|
|
|
|
|
2020-07-29 17:26:15 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2020-05-18 15:34:53 +02:00
|
|
|
UPDATE account_move_line aml
|
2021-05-03 14:04:28 +02:00
|
|
|
SET sale_order_id = so.id
|
|
|
|
FROM sale_order so
|
2020-05-18 15:34:53 +02:00
|
|
|
LEFT JOIN account_move_line aml2
|
2021-05-03 14:04:28 +02:00
|
|
|
ON aml2.sale_order_id = so.id
|
2020-05-18 15:34:53 +02:00
|
|
|
WHERE aml2.move_id = aml.move_id
|
2020-07-29 17:26:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2020-05-18 15:34:53 +02:00
|
|
|
|
2020-07-29 17:26:15 +02:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2020-05-18 15:34:53 +02:00
|
|
|
update account_move_line aml set sale_line_id = sol.id
|
|
|
|
FROM account_move_line aml2
|
|
|
|
INNER JOIN sale_order so ON
|
2021-05-03 14:04:28 +02:00
|
|
|
so.id = aml2.sale_order_id
|
2020-05-18 15:34:53 +02:00
|
|
|
INNER JOIN sale_order_line sol ON
|
|
|
|
so.id = sol.order_id
|
|
|
|
AND sol.product_id = aml2.product_id
|
|
|
|
WHERE aml.id = aml2.id;
|
2020-07-29 17:26:15 +02:00
|
|
|
"""
|
|
|
|
)
|