From 92f8abbecbe35d9a6c3919aa995b84a2f11be359 Mon Sep 17 00:00:00 2001 From: Borruso Date: Wed, 14 Jun 2023 17:03:20 +0200 Subject: [PATCH] [MIG] account_fiscal_year_closing: Migration to 16.0 --- account_fiscal_year_closing/README.rst | 15 ++-- account_fiscal_year_closing/__manifest__.py | 2 +- .../migrations/16.0.1.0.0/pre-migration.py | 58 +++++++++++++ .../models/account_fiscalyear_closing.py | 18 ++-- .../account_fiscalyear_closing_abstract.py | 27 +++++- .../readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 9 +- .../tests/test_account_fiscal_year_closing.py | 83 ++++++++++--------- ...ount_fiscalyear_closing_template_views.xml | 4 +- .../account_fiscalyear_closing_views.xml | 4 +- ...unt_fiscal_year_closing_unbalanced_move.py | 5 +- 11 files changed, 154 insertions(+), 72 deletions(-) create mode 100644 account_fiscal_year_closing/migrations/16.0.1.0.0/pre-migration.py diff --git a/account_fiscal_year_closing/README.rst b/account_fiscal_year_closing/README.rst index c326e39350f..7bcaa453efe 100644 --- a/account_fiscal_year_closing/README.rst +++ b/account_fiscal_year_closing/README.rst @@ -14,14 +14,14 @@ Fiscal year closing :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--closing-lightgray.png?logo=github - :target: https://github.com/OCA/account-closing/tree/14.0/account_fiscal_year_closing + :target: https://github.com/OCA/account-closing/tree/16.0/account_fiscal_year_closing :alt: OCA/account-closing .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/account-closing-14-0/account-closing-14-0-account_fiscal_year_closing + :target: https://translation.odoo-community.org/projects/account-closing-16-0/account-closing-16-0-account_fiscal_year_closing :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/89/14.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/account-closing&target_branch=16.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -104,7 +104,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -126,6 +126,7 @@ Contributors * `CorporateHub `__ * Alexey Pelykh +* Giuseppe Borruso Maintainers ~~~~~~~~~~~ @@ -140,6 +141,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/account-closing `_ project on GitHub. +This module is part of the `OCA/account-closing `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_fiscal_year_closing/__manifest__.py b/account_fiscal_year_closing/__manifest__.py index c242d660f43..6a9a4fef599 100644 --- a/account_fiscal_year_closing/__manifest__.py +++ b/account_fiscal_year_closing/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Fiscal year closing", "summary": "Generic fiscal year closing wizard", - "version": "14.0.1.0.1", + "version": "16.0.1.0.0", "category": "Accounting & Finance", "website": "https://github.com/OCA/account-closing", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/account_fiscal_year_closing/migrations/16.0.1.0.0/pre-migration.py b/account_fiscal_year_closing/migrations/16.0.1.0.0/pre-migration.py new file mode 100644 index 00000000000..f7ce4e1bdff --- /dev/null +++ b/account_fiscal_year_closing/migrations/16.0.1.0.0/pre-migration.py @@ -0,0 +1,58 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +def update_account_type(env, model, new_type, old_type): + openupgrade.logged_query( + env.cr, + """ + UPDATE %(model)s + SET account_type = '%(new_type)s' + WHERE id in ( + SELECT id + WHERE account_type_id = %(old_type)s + ) + """ + % { + "model": model, + "new_type": new_type, + "old_type": old_type, + }, + ) + + +@openupgrade.migrate() +def migrate(env, version): + + all_account_type = [ + ("asset_receivable", env("account.data_account_type_receivable").id), + ("asset_cash", env("account.data_account_type_liquidity").id), + ("asset_current", env("account.data_account_type_current_assets").id), + ("asset_non_current", env("account.data_account_type_non_current_assets").id), + ("asset_fixed", env("account.data_account_type_fixed_assets").id), + ("expense", env("account.data_account_type_expenses").id), + ("expense_depreciation", env("account.data_account_type_depreciation").id), + ("expense_direct_cost", env("account.data_account_type_direct_costs").id), + ("off_balance", env("account.data_account_off_sheet").id), + ("liability_payable", env("account.data_account_type_payable").id), + ("liability_credit_card", env("account.data_account_type_credit_card").id), + ("asset_prepayments", env("account.data_account_type_prepayments").id), + ("liability_current", env("account.data_account_type_current_liabilities").id), + ( + "liability_non_current", + env("account.data_account_type_non_current_liabilities").id, + ), + ("equity", env("account.data_account_type_equity").id), + ("equity_unaffected", env("account.data_unaffected_earnings").id), + ("income", env("account.data_account_type_revenue").id), + ("income_other", env("account.data_account_type_other_income").id), + ] + + for new_type, old_type in all_account_type: + update_account_type( + env, "account_fiscalyear_closing_type_template", new_type, old_type + ) + update_account_type(env, "account_fiscalyear_closing_type", new_type, old_type) diff --git a/account_fiscal_year_closing/models/account_fiscalyear_closing.py b/account_fiscal_year_closing/models/account_fiscalyear_closing.py index 3393971387e..a96faf4a16c 100644 --- a/account_fiscal_year_closing/models/account_fiscalyear_closing.py +++ b/account_fiscal_year_closing/models/account_fiscalyear_closing.py @@ -65,7 +65,6 @@ def _default_company_id(self): ("posted", "Posted"), ("cancelled", "Cancelled"), ], - string="State", readonly=True, default="draft", ) @@ -150,7 +149,7 @@ def _prepare_mapping(self, tmpl_mapping): @api.model def _prepare_type(self, tmpl_type): return { - "account_type_id": tmpl_type.account_type_id, + "account_type": tmpl_type.account_type, "closing_type": tmpl_type.closing_type, } @@ -387,7 +386,7 @@ class AccountFiscalyearClosingConfig(models.Model): string="Closing types", ) date = fields.Date(string="Move date") - enabled = fields.Boolean(string="Enabled", default=True) + enabled = fields.Boolean(default=True) journal_id = fields.Many2one(required=True) move_id = fields.Many2one(comodel_name="account.move", string="Move") @@ -416,7 +415,7 @@ def closing_type_get(self, account): self.ensure_one() closing_type = self.closing_type_default closing_types = self.closing_type_ids.filtered( - lambda r: r.account_type_id == account.user_type_id + lambda r: r.account_type == account.account_type ) if closing_types: closing_type = closing_types[0].closing_type @@ -551,11 +550,12 @@ class AccountFiscalyearClosingMapping(models.Model): string="Destination account", ) - @api.model - def create(self, vals): - if "dest_account_id" in vals: - vals["dest_account_id"] = vals["dest_account_id"][0] - res = super(AccountFiscalyearClosingMapping, self).create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if "dest_account_id" in vals: + vals["dest_account_id"] = vals["dest_account_id"][0] + res = super(AccountFiscalyearClosingMapping, self).create(vals_list) return res def write(self, vals): diff --git a/account_fiscal_year_closing/models/account_fiscalyear_closing_abstract.py b/account_fiscal_year_closing/models/account_fiscalyear_closing_abstract.py index 2da426baef5..97e7914bd54 100644 --- a/account_fiscal_year_closing/models/account_fiscalyear_closing_abstract.py +++ b/account_fiscal_year_closing/models/account_fiscalyear_closing_abstract.py @@ -30,7 +30,7 @@ class AccountFiscalyearClosingConfigAbstract(models.AbstractModel): _order = "sequence asc, id asc" name = fields.Char(string="Description", required=True) - sequence = fields.Integer(string="Sequence", index=True, default=1) + sequence = fields.Integer(index=True, default=1) code = fields.Char(string="Unique code", required=True) inverse = fields.Char( string="Inverse config", @@ -81,8 +81,27 @@ class AccountFiscalyearClosingTypeAbstract(models.AbstractModel): required=True, default="unreconciled", ) - account_type_id = fields.Many2one( - comodel_name="account.account.type", - string="Account type", + account_type = fields.Selection( + selection=[ + ("asset_receivable", "Receivable"), + ("asset_cash", "Bank and Cash"), + ("asset_current", "Current Assets"), + ("asset_non_current", "Non-current Assets"), + ("asset_prepayments", "Prepayments"), + ("asset_fixed", "Fixed Assets"), + ("liability_payable", "Payable"), + ("liability_credit_card", "Credit Card"), + ("liability_current", "Current Liabilities"), + ("liability_non_current", "Non-current Liabilities"), + ("equity", "Equity"), + ("equity_unaffected", "Current Year Earnings"), + ("income", "Income"), + ("income_other", "Other Income"), + ("expense", "Expenses"), + ("expense_depreciation", "Depreciation"), + ("expense_direct_cost", "Cost of Revenue"), + ("off_balance", "Off-Balance Sheet"), + ], + string="Type", required=True, ) diff --git a/account_fiscal_year_closing/readme/CONTRIBUTORS.rst b/account_fiscal_year_closing/readme/CONTRIBUTORS.rst index 782fb139658..6458bf51d09 100644 --- a/account_fiscal_year_closing/readme/CONTRIBUTORS.rst +++ b/account_fiscal_year_closing/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * `CorporateHub `__ * Alexey Pelykh +* Giuseppe Borruso diff --git a/account_fiscal_year_closing/static/description/index.html b/account_fiscal_year_closing/static/description/index.html index 7c45f53e7cf..decc065de75 100644 --- a/account_fiscal_year_closing/static/description/index.html +++ b/account_fiscal_year_closing/static/description/index.html @@ -3,7 +3,7 @@ - + Fiscal year closing