Skip to content

Commit 2d4a3de

Browse files
[OU-ADD] account
1 parent b8d149e commit 2d4a3de

4 files changed

Lines changed: 739 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+
)
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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
5+
6+
field_renames = [
7+
(
8+
"account.move",
9+
"account_move",
10+
"l10n_dk_currency_rate_at_transaction",
11+
"invoice_currency_rate",
12+
),
13+
("account.move", "account_move", "payment_id", "origin_payment_id"),
14+
("account.move", "account_move", "reversal_move_id", "reversal_move_ids"),
15+
("account.move", "account_move", "send_and_print_values", "sending_data"),
16+
("account.payment", "account_payment", "destination_journal_id", "journal_id"),
17+
]
18+
19+
_new_columns = [
20+
("account.bank.statement.line", "company_id", "many2one"),
21+
("account.bank.statement.line", "journal_id", "many2one"),
22+
("account.journal", "autocheck_on_post", "boolean", True),
23+
("account.move", "amount_untaxed_in_currency_signed", "float"),
24+
("account.move", "checked", "boolean"),
25+
("account.move", "preferred_payment_method_line_id", "many2one"),
26+
("account.reconcile.model", "counterpart_type", "selection", "general"),
27+
("account.tax", "price_include_override", "selection", "tax_excluded"),
28+
("account.payment", "name", "char"),
29+
("account.payment", "date", "date"),
30+
("account.payment", "memo", "char"),
31+
("account.payment", "state", "selection"),
32+
("account.payment", "is_sent", "boolean"),
33+
]
34+
35+
36+
def rename_selection_option(env):
37+
openupgrade.logged_query(
38+
env.cr,
39+
"""
40+
UPDATE account_account
41+
SET internal_group = 'off'
42+
WHERE internal_group = 'off_balance'""",
43+
)
44+
openupgrade.logged_query(
45+
env.cr,
46+
"""
47+
UPDATE account_report
48+
SET default_opening_date_filter = 'last_' || substr(
49+
default_opening_date_filter, 10)
50+
WHERE left(default_opening_date_filter, 9) = 'previous_'""",
51+
)
52+
openupgrade.logged_query(
53+
env.cr,
54+
"""
55+
UPDATE account_report_expression
56+
SET date_scope = 'strict_range'
57+
WHERE date_scope = 'normal'""",
58+
)
59+
openupgrade.logged_query(
60+
env.cr,
61+
"""
62+
UPDATE account_tax
63+
SET price_include_override = 'tax_included'
64+
WHERE price_include""",
65+
)
66+
67+
68+
def update_account_move_amount_untaxed_in_currency_signed(env):
69+
openupgrade.logged_query(
70+
env.cr,
71+
"""
72+
UPDATE account_move
73+
SET amount_untaxed_in_currency_signed = CASE
74+
WHEN move_type IN ('out_invoice', 'in_refund', 'out_receipt')
75+
THEN COALESCE(amount_untaxed, 0.0)
76+
ELSE (-1) * COALESCE(amount_untaxed, 0.0) END""",
77+
)
78+
79+
80+
def update_account_move_checked(env):
81+
openupgrade.logged_query(
82+
env.cr,
83+
"""
84+
UPDATE account_move
85+
SET checked = TRUE
86+
WHERE to_check IS DISTINCT FROM TRUE""",
87+
)
88+
89+
90+
def fill_account_move_preferred_payment_method_line_id(env):
91+
if openupgrade.column_exists(env.cr, "account_move", "preferred_payment_method_id"):
92+
# having account_check_printing module
93+
openupgrade.logged_query(
94+
env.cr,
95+
"""
96+
UPDATE account_move am
97+
SET preferred_payment_method_line_id = COALESCE(apml.id, apml2.id)
98+
FROM account_payment_method apm
99+
LEFT JOIN account_payment_method_line apml ON
100+
apml.payment_method_id = apm.id AND apml.journal_id = am.journal_id
101+
LEFT JOIN account_payment_method_line apml2 ON
102+
apml2.payment_method_id = apm.id AND apml2.journal_id IS NULL
103+
WHERE am.preferred_payment_method_id = apm.id""",
104+
)
105+
106+
107+
def adapt_account_move_sending_data(env):
108+
# sp_partner_id -> author_partner_id:
109+
openupgrade.logged_query(
110+
env.cr,
111+
"""
112+
UPDATE account_move
113+
SET sending_data = jsonb_set(sending_data::jsonb - 'sp_partner_id',
114+
'{author_partner_id}', sending_data::jsonb->'sp_partner_id')
115+
WHERE sending_data IS NOT NULL AND sending_data::jsonb ? 'sp_partner_id'""",
116+
)
117+
# sp_user_id -> author_user_id:
118+
openupgrade.logged_query(
119+
env.cr,
120+
"""
121+
UPDATE account_move
122+
SET sending_data = jsonb_set(sending_data::jsonb - 'sp_user_id',
123+
'{author_user_id}', sending_data::jsonb->'sp_user_id')
124+
WHERE sending_data IS NOT NULL AND sending_data::jsonb ? 'sp_user_id'""",
125+
)
126+
# mail_template_id -> mail_template:
127+
env.cr.execute(
128+
"""
129+
SELECT id, sending_data::jsonb->'mail_template_id' as mail_template_id
130+
FROM account_move
131+
WHERE sending_data IS NOT NULL AND sending_data::jsonb ? 'mail_template_id'""",
132+
)
133+
for move_id, mail_template_id in env.cr.fetchall():
134+
mail_template = env.ref(mail_template_id)
135+
openupgrade.logged_query(
136+
env.cr,
137+
f"""
138+
UPDATE account_move
139+
SET sending_data = jsonb_set(sending_data::jsonb - 'mail_template_id',
140+
'{{mail_template}}', {mail_template})
141+
WHERE id = {move_id}""",
142+
)
143+
# send_mail: True -> 'sending_methods': {"email"}:
144+
openupgrade.logged_query(
145+
env.cr,
146+
"""
147+
UPDATE account_move
148+
SET sending_data = jsonb_set(sending_data::jsonb - 'send_mail',
149+
'{sending_methods}', '{"email"}'::jsonb)
150+
WHERE sending_data IS NOT NULL
151+
AND sending_data::jsonb @> '{"send_mail": True}'::jsonb""",
152+
)
153+
154+
155+
def fill_account_payment(env):
156+
openupgrade.logged_query(
157+
env.cr,
158+
"""
159+
UPDATE account_payment ap
160+
SET memo = am.ref,
161+
state= CASE WHEN am.state = 'cancel' THEN 'canceled',
162+
WHEN am.payment_state = 'paid' THEN 'paid',
163+
WHEN am.state = 'posted' THEN 'in_process',
164+
ELSE am.state END,
165+
is_sent = am.is_move_sent,
166+
name = CASE WHEN am.name != '/' THEN am.name,
167+
ELSE 'Draft Payment',
168+
date = ap.create_date::date,
169+
journal_id = CASE WHEN ap.journal_id IS NULL
170+
AND aj.type in ('bank', 'cash', 'credit')
171+
THEN am.journal_id ELSE ap.journal_id END
172+
FROM account_move am
173+
LEFT JOIN account_journal aj ON am.journal_id = aj.id
174+
WHERE ap.move_id = am.id""",
175+
)
176+
177+
178+
@openupgrade.migrate()
179+
def migrate(env, version):
180+
openupgrade.rename_fields(env, field_renames)
181+
openupgrade.add_columns(env, _new_columns)
182+
update_account_move_amount_untaxed_in_currency_signed(env)
183+
update_account_move_checked(env)
184+
fill_account_move_preferred_payment_method_line_id(env)
185+
adapt_account_move_sending_data(env)
186+
rename_selection_option(env)
187+
fill_account_payment(env)
188+
openupgrade.convert_field_to_html(
189+
env.cr,
190+
"account_tax",
191+
"description",
192+
"description",
193+
verbose=False,
194+
translate=True,
195+
)

0 commit comments

Comments
 (0)