Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| Module | Status + Extra Information |
+===================================================+======================+=================================================+
| account | | |
| account |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| account_check_printing | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down Expand Up @@ -36,7 +36,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| account_update_tax_tags | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| analytic | | |
| analytic |Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |new| api_doc | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down Expand Up @@ -768,7 +768,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| mrp_subcontracting_repair | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| onboarding | | |
| onboarding |Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| partner_autocomplete | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
57 changes: 57 additions & 0 deletions openupgrade_scripts/scripts/account/19.0.1.4/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from openupgradelib import openupgrade


def account_move_line_is_storno(env):
"""
Compute is_storno on lines of companies with storno accounting
"""
lines_to_recompute = env["account.move.line"].search(
[("company_id.account_storno", "=", True)]
)
lines_to_recompute._compute_is_storno()


def res_company(env):
"""
Set fields expense_account_id, income_account_id, price_difference_account_id
from localization if not set elsewhere and the localization sets it
"""
for company in env["res.company"].search([]):
AccountChartTemplate = env["account.chart.template"].with_context(
default_company_id=company.id,
allowed_company_ids=company.ids,
tracking_disable=True,
delay_account_group_sync=True,
lang="en_US",
chart_template_load=True,
)
if company.chart_template not in AccountChartTemplate._template_register:
openupgrade.logger.error(
"chart template %s unknown (not yet migrated?)",
company.chart_template,
)
continue
template_data = AccountChartTemplate._get_chart_template_data(
company.chart_template
)
company_template_data = {
company_id: {
key: value
for key, value in company_data.items()
if key
in (
"expense_account_id",
"income_account_id",
"price_difference_account_id",
)
and not company[key]
}
for company_id, company_data in template_data["res.company"].items()
}
AccountChartTemplate._load_data({"res.company": company_template_data})


@openupgrade.migrate()
def migrate(env, version):
account_move_line_is_storno(env)
res_company(env)
202 changes: 202 additions & 0 deletions openupgrade_scripts/scripts/account/19.0.1.4/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import re

from openupgradelib import openupgrade

from odoo.orm.commands import Command


def account_reconcile_model(env):
"""
Apply changes to account.reconcile.model
"""
env.cr.execute(
"""
UPDATE account_reconcile_model
SET trigger='auto_reconcile'
WHERE auto_reconcile
"""
)


def account_reconcile_model_partner_mapping(env):
"""
Model account.reconcile.model.partner.mapping is folded into
account.reconcile.model.line, so create a new model per partner
mapping, merge regexes from partner mapping and model if any
"""
link_column = openupgrade.get_legacy_name("partner_mapping_id")
env.cr.execute(
"ALTER TABLE account_reconcile_model "
f"ADD COLUMN IF NOT EXISTS {link_column} int "
)
env.cr.execute(
"""
SELECT
model_id,
array_agg(id),
array_agg(partner_id),
array_agg(payment_ref_regex),
array_agg(narration_regex)
FROM account_reconcile_model_partner_mapping mapping
GROUP BY model_id
"""
)
AccountReconcileModel = env["account.reconcile.model"]
ResPartner = env["res.partner"]

for (
reconcile_model_id,
mapping_ids,
partner_ids,
payment_ref_regexes,
narration_regexes,
) in env.cr.fetchall():
reconcile_model = AccountReconcileModel.browse(reconcile_model_id)
match_regex_lookahead = ""
if reconcile_model.match_label_param:
if reconcile_model.match_label == "contains":
match_regex_lookahead = (
f"(?=.*{re.escape(reconcile_model.match_label_param)}.*)"
)
elif reconcile_model.match_label == "not_contains":
match_regex_lookahead = (
f"(?!{re.escape(reconcile_model.match_label_param)})"
)
elif reconcile_model.match_label == "match_regex":
match_regex_lookahead = f"(?={reconcile_model.match_label_param})"

for mapping_id, partner_id, payment_ref_regex, narration_regex in zip(
mapping_ids,
partner_ids,
payment_ref_regexes,
narration_regexes,
strict=True,
):
partner = ResPartner.browse(partner_id)
match_regex = "|".join(
map(
lambda x: f"({x})",
filter(None, [payment_ref_regex, narration_regex]),
)
)
new_reconcile_model = reconcile_model.copy(
{
"name": reconcile_model.name + f" ({partner.name})",
"match_label": "match_regex",
"match_label_param": match_regex_lookahead + match_regex,
"line_ids": [
Command.create(
{
"partner_id": partner_id,
}
),
],
}
)
env.cr.execute(
f"""
UPDATE account_reconcile_model
SET {link_column} = {mapping_id}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the use of this link_column field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to know which model was created by a partner mapping. whenever the oca version of the reconciliation is done, we'll probably want to undo this, or differently, so it seems prudent to me to know where this comes from

WHERE id = {new_reconcile_model.id}
"""
)


def account_account_active(env):
"""
Set active flag from deprecated
"""
env.cr.execute("UPDATE account_account SET active = FALSE where deprecated")


def fiscal_position_tax_ids(env):
"""
Fill account.fiscal.position#tax_ids from previous account.fiscal.position.tax
table
"""
env.cr.execute(
"""
INSERT INTO account_fiscal_position_account_tax_rel
(account_fiscal_position_id, account_tax_id)
SELECT DISTINCT position_id, tax_dest_id FROM account_fiscal_position_tax
WHERE tax_dest_id IS NOT NULL
"""
)


def account_tax_original_tax_ids(env):
"""
Fill account.tax#original_tax_ids from previous account.fiscal.position.tax table
"""
env.cr.execute(
"""
INSERT INTO account_tax_alternatives
(dest_tax_id, src_tax_id)
SELECT DISTINCT tax_dest_id, tax_src_id FROM account_fiscal_position_tax
WHERE tax_dest_id IS NOT NULL AND tax_src_id IS NOT NULL
"""
)


def account_full_reconcile_exchange_move_id(env):
"""
account.full.reconcile#exchange_move_id has been scrapped, clone a partial
reconciliation and link the exchange move to it
"""
env.cr.execute(
"""
SELECT id, exchange_move_id
FROM account_full_reconcile
WHERE exchange_move_id IS NOT NULL
"""
)
AccountFullReconcile = env["account.full.reconcile"]

for full_reconcile_id, exchange_move_id in env.cr.fetchall():
AccountFullReconcile.browse(full_reconcile_id).partial_reconcile_ids[-1:].copy(
{
"exchange_move_id": exchange_move_id,
"full_reconcile_id": full_reconcile_id,
}
)


def account_move_line_no_followup(env):
"""
Set no_followup = True on lines of journals of type 'general'
"""
env.cr.execute(
"""
UPDATE account_move_line
SET no_followup=True
FROM account_journal
WHERE
account_move_line.journal_id=account_journal.id AND
account_journal.type = 'general'
"""
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "account", "19.0.1.4/noupdate_changes.xml")
openupgrade.delete_record_translations(
env.cr,
"account",
[
"email_template_edi_credit_note",
"email_template_edi_invoice",
"mail_template_data_payment_receipt",
],
["body_html"],
)
account_reconcile_model(env)
account_reconcile_model_partner_mapping(env)
account_account_active(env)
fiscal_position_tax_ids(env)
account_tax_original_tax_ids(env)
account_full_reconcile_exchange_move_id(env)
account_move_line_no_followup(env)
Loading