Skip to content

Commit

Permalink
[MIG] l10n_it_account: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati authored and Borruso committed Jan 31, 2025
1 parent 2294dbd commit f869c55
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 2,861 deletions.
30 changes: 15 additions & 15 deletions l10n_it_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ ITA - Contabilità base
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_account
:target: https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_account
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-l10n_it_account
:target: https://translation.odoo-community.org/projects/l10n-italy-18-0/l10n-italy-18-0-l10n_it_account
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -57,7 +57,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_account%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_account%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -73,23 +73,23 @@ Authors
Contributors
------------

- Davide Corio
- Lorenzo Battistini <[email protected]>
- Alex Comba <[email protected]>
- Sergio Zanchetta <https://github.com/primes2h>
- Gianmarco Conte - Dinamiche Aziendali Sr
<[email protected]>
- Marco Colombo - Phi S.r.l. <[email protected]>
- `TAKOBI <https://takobi.online>`__:
- Davide Corio
- Lorenzo Battistini <[email protected]>
- Alex Comba <[email protected]>
- Sergio Zanchetta <https://github.com/primes2h>
- Gianmarco Conte - Dinamiche Aziendali Sr
<[email protected]>
- Marco Colombo - Phi S.r.l. <[email protected]>
- `TAKOBI <https://takobi.online>`__:

- Simone Rubino <[email protected]>
- Simone Rubino <[email protected]>

Other credits
-------------

The development of this module has been financially supported by:

- Odoo Italia Network
- Odoo Italia Network

Maintainers
-----------
Expand All @@ -104,6 +104,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_account>`_ project on GitHub.
This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_account>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
12 changes: 0 additions & 12 deletions l10n_it_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import wizards
from . import tools
from odoo import api, SUPERUSER_ID


def _l10n_it_account_post_init(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["account.account"].set_account_types_negative_sign()

lang = env["res.lang"]
if lang._lang_get("it_IT"):
lang.update_menu_finance_it_translation()
9 changes: 3 additions & 6 deletions l10n_it_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"name": "ITA - Contabilità base",
"summary": "Modulo base usato come dipendenza di altri moduli contabili",
"version": "16.0.1.1.3",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "Hidden",
"author": "Agile Business Group, Abstract, Odoo Community Association (OCA)",
Expand All @@ -25,21 +25,18 @@
"data": [
"views/account_menuitem.xml",
"views/partner_view.xml",
"views/product_view.xml",
"views/res_config_settings_views.xml",
"reports/account_reports_view.xml",
"views/account_view.xml",
],
"assets": {
"web.report_assets_common": [
"l10n_it_account/static/src/css/*.css",
]
},
"installable": True,
"external_dependencies": {
"python": [
"xmlschema",
"openupgradelib",
],
},
"installable": True,
"post_init_hook": "_l10n_it_account_post_init",
}
24 changes: 0 additions & 24 deletions l10n_it_account/migrations/16.0.1.0.0/post-migrate_balance_sign.py

This file was deleted.

178 changes: 178 additions & 0 deletions l10n_it_account/migrations/18.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
from openupgradelib import openupgrade
from psycopg2 import sql

from odoo import SUPERUSER_ID, api

OLD_MODULES = [
"l10n_it_account_tax_kind",
"l10n_it_fatturapa",
"l10n_it_fiscalcode",
"l10n_it_ipa",
"l10n_it_rea",
]


def rename_fields(env, table, field_updates, condition=None):
"""Generic function to rename fields."""
set_clauses = sql.SQL(", ").join(
sql.SQL("{} = {}").format(sql.Identifier(target), sql.Identifier(source))
for target, source in field_updates.items()
)
query = sql.SQL("""
UPDATE {table}
SET {set_clauses}
""").format(table=sql.Identifier(table), set_clauses=set_clauses)
if condition:
query += sql.SQL(" WHERE {} ").format(sql.SQL(condition))
openupgrade.logged_query(env.cr, query)


def update_table(env, target_table, source_table, field_updates, condition):
"""Generic function to update fields in a table based on a join."""
set_clauses = sql.SQL(", ").join(
sql.SQL("{} = {}.{}").format(
sql.Identifier(target), sql.Identifier(source_table), sql.Identifier(source)
)
for target, source in field_updates.items()
)
query = sql.SQL("""
UPDATE {target_table}
SET {set_clauses}
FROM {source_table}
""").format(
target_table=sql.Identifier(target_table),
set_clauses=set_clauses,
source_table=sql.Identifier(source_table),
)
if condition:
query += sql.SQL(" WHERE {} ").format(sql.SQL(condition))
openupgrade.logged_query(env.cr, query)


def add_field_if_not_exists(env, table, field_name, field_type, module):
"""Helper function to add fields if they do not exist."""
if not openupgrade.column_exists(env.cr, table, field_name):
sql_type_mapping = {
"binary": "bytea",
"boolean": "bool",
"char": "varchar",
"date": "date",
"datetime": "timestamp",
"float": "numeric",
"html": "text",
"integer": "int4",
"many2many": False,
"many2one": "int4",
"many2one_reference": "int4",
"monetary": "numeric",
"one2many": False,
"reference": "varchar",
"selection": "varchar",
"text": "text",
"serialized": "text",
}
openupgrade.add_fields(
env,
[
(
field_name,
table.replace("_", "."),
table,
field_type,
sql_type_mapping[field_type],
module,
)
],
)


def _l10n_it_account_tax_kind_migration(env):
table = "account_tax"
add_field_if_not_exists(env, table, "l10n_it_law_reference", "char", "l10n_it")
rename_fields(env, table, {"l10n_it_law_reference": "law_reference"})

add_field_if_not_exists(env, table, "l10n_it_exempt_reason", "char", "l10n_it")
condition = "account_tax.kind_id = account_tax_kind.id"
condition += " AND account_tax.kind_id IS NOT NULL"
update_table(
env, table, "account_tax_kind", {"l10n_it_exempt_reason": "code"}, condition
)


def _l10n_it_fatturapa_migration(env):
table = "res_partner"
add_field_if_not_exists(env, table, "l10n_it_pa_index", "char", "l10n_it_edi")
add_field_if_not_exists(env, table, "l10n_it_pec_email", "char", "l10n_it_edi")
rename_fields(
env,
table,
{
"l10n_it_pa_index": "codice_destinatario",
"l10n_it_pec_email": "pec_destinatario",
},
)

table = "res_company"
add_field_if_not_exists(
env, table, "l10n_it_tax_representative_partner_id", "many2one", "l10n_it_edi"
)
rename_fields(
env,
table,
{"l10n_it_tax_representative_partner_id": "fatturapa_tax_representative"},
)


def _l10n_it_fiscalcode_migration(env):
table = "res_partner"
add_field_if_not_exists(env, table, "l10n_it_codice_fiscale", "char", "l10n_it_edi")
rename_fields(env, table, {"l10n_it_codice_fiscale": "fiscalcode"})


def _l10n_it_ipa_migration(env):
table = "res_partner"
add_field_if_not_exists(env, table, "l10n_it_pa_index", "char", "l10n_it_edi")
condition = "ipa_code IS NOT NULL"
rename_fields(env, table, {"l10n_it_pa_index": "ipa_code"}, condition=condition)


def _l10n_it_rea_migration(env):
table = "res_company"
add_field_if_not_exists(
env, table, "l10n_it_eco_index_office", "many2one", "l10n_it_edi"
)
add_field_if_not_exists(
env, table, "l10n_it_eco_index_number", "char", "l10n_it_edi"
)
add_field_if_not_exists(
env, table, "l10n_it_eco_index_share_capital", "float", "l10n_it_edi"
)
add_field_if_not_exists(
env, table, "l10n_it_eco_index_sole_shareholder", "selection", "l10n_it_edi"
)
add_field_if_not_exists(
env, table, "l10n_it_eco_index_liquidation_state", "selection", "l10n_it_edi"
)
condition = "res_company.partner_id = res_partner.id"
condition += " AND res_partner.rea_office IS NOT NULL"
update_table(
env,
table,
"res_partner",
{
"l10n_it_eco_index_office": "rea_office",
"l10n_it_eco_index_number": "rea_code",
"l10n_it_eco_index_share_capital": "rea_capital",
"l10n_it_eco_index_sole_shareholder": "rea_member_type",
"l10n_it_eco_index_liquidation_state": "rea_liquidation_state",
},
condition,
)


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
for module in OLD_MODULES:
migration_function = globals().get(f"_{module}_migration")
if openupgrade.is_module_installed(env.cr, module) and migration_function:
migration_function(env)
3 changes: 0 additions & 3 deletions l10n_it_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account_account
from . import account_group
from . import account_tax
from . import res_lang
Loading

0 comments on commit f869c55

Please sign in to comment.