-
-
Notifications
You must be signed in to change notification settings - Fork 689
/
__init__.py
98 lines (83 loc) · 2.94 KB
/
__init__.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from . import models
from . import wizard
from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade
def rename_old_italian_module(cr):
if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi"):
return
openupgrade.update_module_names(
cr,
[
("l10n_it_corrispettivi", "account_receipt_sale"),
],
merge_modules=True,
)
if openupgrade.column_exists(
cr, "account_move", "old_invoice_id"
) and openupgrade.column_exists(cr, "account_invoice", "corrispettivo"):
# l10n_it_corrispettivi handled sale receipts only
openupgrade.logged_query(
cr,
"UPDATE account_move m "
"SET move_type = 'out_receipt' "
"FROM account_invoice i "
"WHERE i.corrispettivo = true AND i.id = m.old_invoice_id",
)
if openupgrade.column_exists(cr, "account_journal", "corrispettivi"):
openupgrade.logged_query(
cr,
"UPDATE account_journal "
"SET receipts = true "
"WHERE corrispettivi = true",
)
if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi_sale"):
return
openupgrade.update_module_names(
cr,
[
("l10n_it_corrispettivi_sale", "account_receipt_sale"),
],
merge_modules=True,
)
def invert_receipt_refund_quantity(env):
"""Receipt Refunds are the same as normal Receipts
but with inverted Quantities."""
openupgrade.logged_query(
env.cr,
"UPDATE account_move_line l "
"SET quantity = -quantity "
"FROM account_move m "
"WHERE m.id = l.move_id "
"AND m.move_type IN ('out_receipt', 'in_receipt') "
"AND m.amount_total_signed < 0 "
"AND l.exclude_from_invoice_tab = false "
"AND (l.display_type NOT IN ('line_section', 'line_note') "
" OR display_type IS NULL) "
"AND l.quantity > 0",
)
def migrate_corrispettivi_data(cr, registry):
"""
Populate the new columns with data from corrispettivi modules.
"""
if openupgrade.column_exists(cr, "sale_order", "corrispettivi"):
openupgrade.logged_query(
cr,
"UPDATE sale_order " "SET receipts = true " "WHERE corrispettivi = true",
)
if openupgrade.column_exists(cr, "account_fiscal_position", "corrispettivi"):
openupgrade.logged_query(
cr,
"UPDATE account_fiscal_position "
"SET receipts = true "
"WHERE corrispettivi = true",
)
if openupgrade.column_exists(cr, "res_partner", "use_corrispettivi"):
openupgrade.logged_query(
cr,
"UPDATE res_partner "
"SET use_receipts = true "
"WHERE use_corrispettivi = true",
)
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
invert_receipt_refund_quantity(env)