-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
hooks.py
71 lines (66 loc) · 2.24 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright 2022 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
def post_init_hook(cr, registry):
# Material consumed on repair
cr.execute(
"""
update account_move_line as aml set repair_order_id = q.order_id
from (
select aml.id, ro.id as order_id
from account_move_line as aml
left join account_move as am on am.id = aml.move_id
left join stock_valuation_layer svl on svl.account_move_id = am.id
left join stock_move as sm on sm.id = svl.stock_move_id
left join repair_line as rl on rl.move_id = sm.id
left join repair_order as ro on rl.repair_id = ro.id
where ro.id is not null
) as q
where q.id = aml.id
"""
)
# Product Repaired
cr.execute(
"""
update account_move_line as aml set repair_order_id = q.order_id
from (
select aml.id, ro.id as order_id
from account_move_line as aml
left join account_move as am on am.id = aml.move_id
left join stock_valuation_layer svl on svl.account_move_id = am.id
left join stock_move as sm on sm.id = svl.stock_move_id
left join repair_order as ro on sm.id = ro.move_id
where ro.id is not null
) as q
where q.id = aml.id
"""
)
# Invoice Lines for Products Consumed
cr.execute(
"""
update account_move_line as aml set repair_order_id = q.order_id
from (
select aml.id, ro.id as order_id
from account_move_line as aml
left join account_move as am on am.id = aml.move_id
left join repair_line as rl on aml.id = rl.invoice_line_id
left join repair_order as ro on rl.repair_id = ro.id
where ro.id is not null
) as q
where q.id = aml.id
"""
)
# Invoice Lines for Fees
cr.execute(
"""
update account_move_line as aml set repair_order_id = q.order_id
from (
select aml.id, ro.id as order_id
from account_move_line as aml
left join account_move as am on am.id = aml.move_id
left join repair_fee as rf on aml.id = rf.invoice_line_id
left join repair_order as ro on rf.repair_id = ro.id
where ro.id is not null
) as q
where q.id = aml.id
"""
)