forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-migrate.py
74 lines (67 loc) · 2.03 KB
/
post-migrate.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
72
73
74
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from openupgradelib import openupgrade
@openupgrade.logging()
def compute_purchase_line_discount(env):
purchase_lines_to_compute = env["purchase.order.line"].search(
[
"|",
"|",
("discount1", "!=", 0),
("discount2", "!=", 0),
("discount3", "!=", 0),
]
)
for line in purchase_lines_to_compute:
discount = line._get_aggregated_multiple_discounts(
[line[x] for x in ["discount1", "discount2", "discount3"]]
)
rounded_discount = line._fields["discount"].convert_to_column(discount, line)
openupgrade.logged_query(
env.cr,
"""
UPDATE prochase_order_line
SET discount = %s
WHERE id = %s;
""",
tuple(
[
rounded_discount,
line.id,
]
),
)
@openupgrade.logging()
def compute_supplierinfo_line_discount(env):
supplierinfo_lines_to_compute = env["product.supplierinfo"].search(
[
"|",
"|",
("discount1", "!=", 0),
("discount2", "!=", 0),
("discount3", "!=", 0),
]
)
for line in supplierinfo_lines_to_compute:
discount = line._get_aggregated_multiple_discounts(
[line[x] for x in ["discount1", "discount2", "discount3"]]
)
rounded_discount = line._fields["discount"].convert_to_column(discount, line)
openupgrade.logged_query(
env.cr,
"""
UPDATE product_supplierinfo
SET discount = %s
WHERE id = %s;
""",
tuple(
[
rounded_discount,
line.id,
]
),
)
@openupgrade.migrate()
def migrate(env, version):
compute_purchase_line_discount(env)
compute_supplierinfo_line_discount(env)