diff --git a/l10n_it_account/__init__.py b/l10n_it_account/__init__.py index 0a0612ae8e4d..ac06c2c0cff8 100644 --- a/l10n_it_account/__init__.py +++ b/l10n_it_account/__init__.py @@ -1,15 +1,48 @@ # 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 +MODEL = "account.tax" +OLD_MODEL = "account.tax.kind" +RENAMED_FIELDS = [ + ( + "law_reference", + "l10n_it_law_reference", + ), +] + 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() + openupgrade.logged_query( + env.cr, + sql.SQL(f""" + UPDATE + {MODEL.replace(".", "_")} + SET + l10n_it_exempt_reason = kind_id.code + FROM + {OLD_MODEL.replace(".", "_")} AS kind + WHERE + {MODEL.replace(".", "_")}.kind_id = kind.id + AND {MODEL.replace(".", "_")}.kind_id IS NOT NULL + """), + ) + + field_spec = [] + for renamed_field in RENAMED_FIELDS: + old_field, new_field = renamed_field + field_spec.append( + ( + MODEL, + MODEL.replace(".", "_"), + old_field, + new_field, + ) + ) + openupgrade.rename_fields( + env, + field_spec, + ) diff --git a/l10n_it_account/__manifest__.py b/l10n_it_account/__manifest__.py index f292e49f23ec..0e1815c20614 100644 --- a/l10n_it_account/__manifest__.py +++ b/l10n_it_account/__manifest__.py @@ -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)", @@ -21,25 +21,19 @@ "account_tax_balance", "date_range", "web", + "l10n_it", ], "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", ] }, - "external_dependencies": { - "python": [ - "xmlschema", - ], - }, "installable": True, "post_init_hook": "_l10n_it_account_post_init", } diff --git a/l10n_it_account/migrations/16.0.1.0.0/post-migrate_balance_sign.py b/l10n_it_account/migrations/16.0.1.0.0/post-migrate_balance_sign.py deleted file mode 100644 index 280e54502c90..000000000000 --- a/l10n_it_account/migrations/16.0.1.0.0/post-migrate_balance_sign.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2022 Simone Rubino - TAKOBI -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, installed_version): - # Assign the sign of the account type to the account - if openupgrade.table_exists(env.cr, "account_account_type"): - openupgrade.logged_query( - env.cr, - """ - UPDATE account_account - SET - account_balance_sign = aat.account_balance_sign - FROM - account_account_type aat - WHERE - aat.id = account_account.user_type_id - """, - ) - else: - env["account.account"].set_account_types_negative_sign() diff --git a/l10n_it_account/models/__init__.py b/l10n_it_account/models/__init__.py index 46df1f7f948d..bf09a2c3496a 100644 --- a/l10n_it_account/models/__init__.py +++ b/l10n_it_account/models/__init__.py @@ -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 diff --git a/l10n_it_account/models/account_account.py b/l10n_it_account/models/account_account.py deleted file mode 100644 index f299c91bcc89..000000000000 --- a/l10n_it_account/models/account_account.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2022 Simone Rubino - TAKOBI -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import _, api, fields, models -from odoo.exceptions import ValidationError - -ACCOUNT_TYPES_NEGATIVE_SIGN = [ - "equity_unaffected", - "equity", - "income", - "income_other", - "liability_payable", - "liability_credit_card", - "asset_prepayments", - "liability_current", - "liability_non_current", -] - - -class Account(models.Model): - _inherit = "account.account" - - account_balance_sign = fields.Integer( - default=1, - string="Balance sign", - ) - - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - if "account_balance_sign" not in vals and "account_type" in vals: - if vals["account_type"] in ACCOUNT_TYPES_NEGATIVE_SIGN: - vals["account_balance_sign"] = -1 - return super().create(vals_list) - - @api.model - def set_account_types_negative_sign(self): - for account_type in ACCOUNT_TYPES_NEGATIVE_SIGN: - account_ids = self.env["account.account"].search( - [("account_type", "=", account_type)] - ) - for account_id in account_ids: - account_id.with_context( - skip_check_balance_sign_coherence=True - ).account_balance_sign = -1 - - def check_balance_sign_value(self): - """ - Checks whether `account_balance_sign` gets a correct value of +1 or -1. - """ - if any(t.account_balance_sign not in (-1, 1) for t in self): - raise ValidationError(_("Balance sign's value can only be 1 or -1.")) - - @api.constrains("account_balance_sign") - def check_balance_sign_coherence(self): - """ - Checks whether changes upon `account_balance_sign` create incoherencies - in account groups' balance signs. - """ - self.check_balance_sign_value() - - acc_obj = self.env["account.account"] - key_val_dict = dict(self._fields["account_type"].selection) - for key in key_val_dict: - accounts = acc_obj.search( - [("account_type", "=", key)], - ) - # Avoid check upon empty recordset to make it faster - if accounts: - accounts.check_balance_sign_coherence_group() - - @api.constrains("group_id") - def check_balance_sign_coherence_group(self): - """ - Checks whether adding an account to (or removing it from) a group - creates incoherencies in account groups' balance signs. - """ - groups = self.mapped("group_id") - # Avoid check upon empty recordset to make it faster - if groups: - groups.check_balance_sign_coherence() - - def have_same_sign(self): - """ - Checks account' signs. - :return: True if there's nothing to check or there's only one account - to check; else, returns True or False according to whether every - account has the same value for `account_balance_sign` (if it's not 0). - """ - to_check = self.filtered(lambda a: a.account_balance_sign) - if len(to_check) <= 1: - return True - benchmark = to_check[0].account_balance_sign - return all(a.account_balance_sign == benchmark for a in to_check) diff --git a/l10n_it_account/models/account_group.py b/l10n_it_account/models/account_group.py deleted file mode 100644 index 27d671b4503f..000000000000 --- a/l10n_it_account/models/account_group.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2022 Simone Rubino - TAKOBI -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import _, api, fields, models -from odoo.exceptions import ValidationError - - -class AccountGroup(models.Model): - _inherit = "account.group" - - account_ids = fields.One2many( - comodel_name="account.account", - inverse_name="group_id", - string="Accounts", - ) - account_balance_sign = fields.Integer( - compute="_compute_account_balance_sign", - string="Balance sign", - ) - - @api.constrains("account_ids", "parent_id") - def check_balance_sign_coherence(self): - """ - Checks whether every group (plus parents and subgroups) have the same - balance sign. This is done by first retrieving every group's progenitor - and then checking, for each of them, the account types' for accounts - linked to such progenitor group and its subgroups. - """ - if self.env.context.get("skip_check_balance_sign_coherence"): - return - done_group_ids, progenitor_ids = [], [] - for group in self: - if group.id in done_group_ids: - continue - progenitor = group.get_group_progenitor() - progenitor_ids.extend(progenitor.ids) - done_group_ids.extend(progenitor.get_group_subgroups().ids) - - progenitors = self.browse(tuple(set(progenitor_ids))) - for progenitor in progenitors: - accounts = progenitor.get_group_accounts() - if not accounts.have_same_sign(): - raise ValidationError( - _("Incoherent balance signs for '{}' and its subgroups.").format( - progenitor.name_get()[0][-1] - ) - ) - - def _compute_account_balance_sign(self): - for group in self: - group.account_balance_sign = group.get_account_balance_sign() - - def get_account_balance_sign(self): - self.ensure_one() - progenitor = self.get_group_progenitor() - accounts = progenitor.get_group_accounts() - if accounts: - return accounts[0].account_balance_sign - return 1 - - def get_group_accounts(self): - """Retrieves every account from `self` and `self`'s subgroups.""" - return (self + self.get_group_subgroups()).mapped("account_ids") - - def get_group_progenitor(self): - self.ensure_one() - if not self.parent_id: - return self - return self.get_group_parents().filtered(lambda g: not g.parent_id) - - def get_group_parents(self): - """ - Retrieves every parent for group `self`. - :return: group's parents as recordset, or empty recordset if `self` - has no parents. If a recursion is found, an error is raised. - """ - self.ensure_one() - parent_ids = [] - parent = self.parent_id - while parent: - parent_ids.append(parent.id) - parent = parent.parent_id - return self.browse(parent_ids) - - def get_group_subgroups(self): - """Retrieves every subgroup for groups `self`.""" - subgroups_ids = self.search([("id", "child_of", self.ids)]) - return subgroups_ids diff --git a/l10n_it_account/models/res_lang.py b/l10n_it_account/models/res_lang.py deleted file mode 100644 index cce2e4a9f205..000000000000 --- a/l10n_it_account/models/res_lang.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2024 Sergio Zanchetta (PNLUG APS - Gruppo Odoo) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import models - - -class Lang(models.Model): - _inherit = "res.lang" - - def toggle_active(self): - res = super().toggle_active() - - if "it_IT" in [lang.code for lang in self.filtered(lambda L: L.active)]: - self.update_menu_finance_it_translation() - - return res - - def update_menu_finance_it_translation(self): - """In Odoo the inheritance mechanism is not yet implemented for menus. - Changing a menu item name doesn't create a new string to be translated - but overwrites the source string of the original module to which the menu - belongs to. This is a workaround that allows the translated string to be - modified in the same way. - """ - menu_finance_id = self.env["ir.model.data"]._xmlid_to_res_id( - "account.menu_finance" - ) - menu_finance = self.env["ir.ui.menu"].browse(menu_finance_id) - - field_name = menu_finance._fields["name"] - translations = field_name._get_stored_translations(menu_finance) - - translations["it_IT"] = "Contabilità" - self.env.cache.update_raw(menu_finance, field_name, [translations], dirty=True) - menu_finance.modified(["name"]) diff --git a/l10n_it_account/reports/account_reports_view.xml b/l10n_it_account/reports/account_reports_view.xml index 8c4d27b4deb1..ff24ec4d5010 100644 --- a/l10n_it_account/reports/account_reports_view.xml +++ b/l10n_it_account/reports/account_reports_view.xml @@ -55,18 +55,16 @@
-

- -

+


- - -
- TIN:
+ + - + -
+ TIN: +

@@ -83,21 +81,21 @@
@@ -107,7 +105,7 @@