forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
32 lines (24 loc) · 998 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
31
32
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def __find_origin_moves(moves):
all_moves = moves
for move in moves:
if move.move_orig_ids:
all_moves |= __find_origin_moves(move.move_orig_ids)
return all_moves
def __fill_related(moves, line_id):
for move in moves:
moves_to_write = move
if move.move_orig_ids:
moves_to_write |= __find_origin_moves(move.move_orig_ids)
moves_to_write.write({"related_sale_line_id": line_id.id})
def _fill_in_related_sale_line(env):
"""Update related_sale_line_id on recursive moves"""
moves = env["stock.move"].search([("sale_line_id", "!=", False)])
for move in moves:
__fill_related(move.move_orig_ids, move.sale_line_id)
def post_init_hook(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
_fill_in_related_sale_line(env)