Skip to content

Commit 5555024

Browse files
[OU-ADD] account
1 parent e7e2180 commit 5555024

4 files changed

Lines changed: 757 additions & 4 deletions

File tree

docsource/modules170-180.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Module coverage 17.0 -> 18.0
66
+---------------------------------------------------+----------------------+-------------------------------------------------+
77
| Module | Status + Extra Information |
88
+===================================================+======================+=================================================+
9-
| account | | |
9+
| account | Done | |
1010
+---------------------------------------------------+----------------------+-------------------------------------------------+
11-
| |del| account_audit_trail | |Merged into account. |
11+
| |del| account_audit_trail | Done |Merged into account. |
1212
+---------------------------------------------------+----------------------+-------------------------------------------------+
1313
| account_check_printing | | |
1414
+---------------------------------------------------+----------------------+-------------------------------------------------+
@@ -24,11 +24,11 @@ Module coverage 17.0 -> 18.0
2424
+---------------------------------------------------+----------------------+-------------------------------------------------+
2525
| account_fleet | | |
2626
+---------------------------------------------------+----------------------+-------------------------------------------------+
27-
| |del| account_lock | |Merged into account. |
27+
| |del| account_lock | Done |Merged into account. |
2828
+---------------------------------------------------+----------------------+-------------------------------------------------+
2929
| account_payment | | |
3030
+---------------------------------------------------+----------------------+-------------------------------------------------+
31-
| |del| account_payment_term | |Merged into account. |
31+
| |del| account_payment_term | Done |Merged into account. |
3232
+---------------------------------------------------+----------------------+-------------------------------------------------+
3333
| account_peppol | | |
3434
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from openupgradelib import openupgrade, openupgrade_180
5+
6+
7+
def replace_period_lock_date(env):
8+
openupgrade.logged_query(
9+
env.cr,
10+
"""
11+
UPDATE res_company
12+
SET sale_lock_date = period_lock_date, purchase_lock_date = period_lock_date
13+
WHERE period_lock_date IS NOT NULL""",
14+
)
15+
16+
17+
def link_payments_to_moves(env):
18+
openupgrade.logged_query(
19+
env.cr,
20+
"""
21+
INSERT INTO account_move__account_payment (invoice_id, payment_id)
22+
SELECT (am.id, ap.id)
23+
FROM account_payment ap
24+
JOIN account_move am ON ap.move_id = am.id
25+
""",
26+
)
27+
28+
29+
def convert_company_dependent(env):
30+
openupgrade_180.convert_company_dependent(
31+
env, "account.cash.rounding", "loss_account_id"
32+
)
33+
openupgrade_180.convert_company_dependent(
34+
env, "account.cash.rounding", "profit_account_id"
35+
)
36+
openupgrade_180.convert_company_dependent(
37+
env, "product.category", "property_account_expense_categ_id"
38+
)
39+
openupgrade_180.convert_company_dependent(
40+
env, "product.category", "property_account_income_categ_id"
41+
)
42+
openupgrade_180.convert_company_dependent(
43+
env, "product.template", "property_account_expense_id"
44+
)
45+
openupgrade_180.convert_company_dependent(
46+
env, "product.template", "property_account_income_id"
47+
)
48+
openupgrade_180.convert_company_dependent(env, "res.partner", "credit_limit")
49+
openupgrade_180.convert_company_dependent(
50+
env, "res.partner", "property_account_payable_id"
51+
)
52+
openupgrade_180.convert_company_dependent(
53+
env, "res.partner", "property_account_position_id"
54+
)
55+
openupgrade_180.convert_company_dependent(
56+
env, "res.partner", "property_account_receivable_id"
57+
)
58+
openupgrade_180.convert_company_dependent(
59+
env, "res.partner", "property_payment_term_id"
60+
)
61+
openupgrade_180.convert_company_dependent(
62+
env, "res.partner", "property_supplier_payment_term_id"
63+
)
64+
openupgrade_180.convert_company_dependent(env, "res.partner", "trust")
65+
66+
67+
def fill_res_partner_property_x_payment_method_line_id(env):
68+
if not openupgrade.column_exists(
69+
env.cr, "account_move", "preferred_payment_method_id"
70+
):
71+
return
72+
# having account_check_printing module
73+
env.cr.execute(
74+
"""
75+
SELECT id FROM ir_model_fields
76+
WHERE model = 'res.partner'
77+
AND name = 'property_payment_method_id'"""
78+
)
79+
old_field_id = env.cr.fetchone()[0]
80+
openupgrade.logged_query(
81+
env.cr,
82+
f"""
83+
UPDATE res_partner
84+
SET property_outbound_payment_method_line_id=ir_property_by_company.value
85+
FROM (
86+
SELECT
87+
SPLIT_PART(ip.res_id, ',', 2)::integer res_id,
88+
JSON_OBJECT_AGG(ip.company_id, sub.id) value
89+
FROM ir_property ip
90+
JOIN LATERAL (
91+
SELECT *
92+
FROM account_payment_method_line apml ON
93+
apml.payment_method_id = SPLIT_PART(
94+
ip.value_reference, ',', 2)::integer
95+
LIMIT 1
96+
) as sub
97+
WHERE ip.fields_id={old_field_id} AND ip.res_id IS NOT NULL
98+
AND ip.company_id IS NOT NULL AND sub.id IS NOT NULL
99+
GROUP BY res_id
100+
) ir_property_by_company
101+
WHERE res_partner.id=ir_property_by_company.res_id
102+
""",
103+
)
104+
env.cr.execute(
105+
f"""
106+
SELECT ip.company_id, sub.id FROM ir_property ip
107+
JOIN LATERAL (
108+
SELECT *
109+
FROM account_payment_method_line apml ON
110+
apml.payment_method_id = SPLIT_PART(
111+
ip.value_reference, ',', 2)::integer
112+
LIMIT 1
113+
) as sub
114+
WHERE ip.fields_id={old_field_id} AND res_id IS NULL AND sub.id IS NOT NULL
115+
"""
116+
)
117+
for company_id, value in env.cr.fetchall():
118+
env["ir.default"].set(
119+
"res.partner",
120+
"property_outbound_payment_method_line_id",
121+
value,
122+
company_id=company_id,
123+
)
124+
125+
126+
@openupgrade.migrate()
127+
def migrate(env, version):
128+
replace_period_lock_date(env)
129+
link_payments_to_moves(env)
130+
openupgrade.m2o_to_x2m(
131+
env.cr, env["account.account"], "account_account", "company_ids", "company_id"
132+
)
133+
convert_company_dependent(env)
134+
fill_res_partner_property_x_payment_method_line_id(env)
135+
openupgrade.load_data(env, "account", "18.0.1.3/noupdate_changes.xml")
136+
openupgrade.delete_record_translations(
137+
env.cr, "account", ["email_template_edi_invoice"]
138+
)
139+
openupgrade.delete_record_translations(
140+
env.cr,
141+
"account",
142+
["account_payment_method_manual_in", "account_payment_method_manual_out"],
143+
["name"],
144+
)
145+
openupgrade.delete_record_translations(
146+
env.cr,
147+
"account",
148+
[
149+
"onboarding_onboarding_step_chart_of_accounts",
150+
"onboarding_onboarding_step_company_data",
151+
"onboarding_onboarding_step_fiscal_year",
152+
],
153+
["title"],
154+
)
155+
openupgrade.delete_records_safely_by_xml_id(
156+
env,
157+
[
158+
"account.default_followup_trust",
159+
"account.account_move_send_rule_group_invoice",
160+
"account.account_root_comp_rule",
161+
"count.onboarding_onboarding_account_invoice",
162+
"account.onboarding_onboarding_step_bank_account",
163+
"account.onboarding_onboarding_step_create_invoice",
164+
"account.onboarding_onboarding_step_default_taxes",
165+
"account.onboarding_onboarding_step_setup_bill",
166+
],
167+
)

0 commit comments

Comments
 (0)