Skip to content

Commit

Permalink
[MIG] account_fiscal_year_closing: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed Aug 1, 2024
1 parent 649ab1f commit 1ed9668
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 200 deletions.
24 changes: 14 additions & 10 deletions account_fiscal_year_closing/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Fiscal year closing
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4127392bb324718841b4c7a5e89af6dc051892f5a1711b5846ea44c04bc5dddc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ 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/builds?repo=OCA/account-closing&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module implements a generic fiscal year closing system for those
countries where closing/opening moves or other kind of closing operations are
Expand Down Expand Up @@ -103,8 +106,8 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-closing/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 <https://github.com/OCA/account-closing/issues/new?body=module:%20account_fiscal_year_closing%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-closing/issues/new?body=module:%20account_fiscal_year_closing%0Aversion:%2016.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 @@ -126,6 +129,7 @@ Contributors
* `CorporateHub <https://corporatehub.eu/>`__

* Alexey Pelykh <[email protected]>
* Giuseppe Borruso <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -140,6 +144,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 <https://github.com/OCA/account-closing/tree/14.0/account_fiscal_year_closing>`_ project on GitHub.
This module is part of the `OCA/account-closing <https://github.com/OCA/account-closing/tree/16.0/account_fiscal_year_closing>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_fiscal_year_closing/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="fiscalyear_closing_multi_company_rule" model="ir.rule">
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>

<record id="fiscalyear_closing_template_multi_company_rule" model="ir.rule">
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Giuseppe Borruso <[email protected]>
# @author: Giuseppe Borruso <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):

openupgrade.load_data(
env.cr,
"account_fiscal_year_closing",
"migrations/16.0.1.0.0/noupdate_changes.xml",
)
58 changes: 58 additions & 0 deletions account_fiscal_year_closing/migrations/16.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2023 Giuseppe Borruso <[email protected]>
# @author: Giuseppe Borruso <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def update_account_type(env, table):
openupgrade.logged_query(
env.cr,
f"""
ALTER TABLE {table}
ADD COLUMN IF NOT EXISTS account_type VARCHAR
""",
)
openupgrade.logged_query(
env.cr,
f"""
WITH account_type_map AS (
SELECT
res_id AS user_type_id,
CASE
WHEN name = 'data_account_type_receivable' THEN 'asset_receivable'
WHEN name = 'data_account_type_liquidity' THEN 'asset_cash'
WHEN name = 'data_account_type_current_assets' THEN 'asset_current'
WHEN name = 'data_account_type_non_current_assets' THEN 'asset_non_current'
WHEN name = 'data_account_type_fixed_assets' THEN 'asset_fixed'
WHEN name = 'data_account_type_expenses' THEN 'expense'
WHEN name = 'data_account_type_depreciation' THEN 'expense_depreciation'
WHEN name = 'data_account_type_direct_costs' THEN 'expense_direct_cost'
WHEN name = 'data_account_off_sheet' THEN 'off_balance'
WHEN name = 'data_account_type_payable' THEN 'liability_payable'
WHEN name = 'data_account_type_credit_card' THEN 'liability_credit_card'
WHEN name = 'data_account_type_prepayments' THEN 'asset_prepayments'
WHEN name = 'data_account_type_current_liabilities' THEN 'liability_current'
WHEN name = 'data_account_type_non_current_liabilities' THEN 'liability_non_current'
WHEN name = 'data_account_type_equity' THEN 'equity'
WHEN name = 'data_unaffected_earnings' THEN 'equity_unaffected'
WHEN name = 'data_account_type_revenue' THEN 'income'
WHEN name = 'data_account_type_other_income' THEN 'income_other'
ELSE ''
END AS account_type
FROM ir_model_data
WHERE module = 'account' AND model = 'account.account.type'
)
UPDATE {table} aa
SET account_type = atm.account_type
FROM account_type_map atm
WHERE atm.user_type_id = aa.user_type_id
""",
)


@openupgrade.migrate()
def migrate(env, version):

update_account_type(env, "account_fiscalyear_closing_type_template")
update_account_type(env, "account_fiscalyear_closing_type")
22 changes: 11 additions & 11 deletions account_fiscal_year_closing/models/account_fiscalyear_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def _default_company_id(self):
("posted", "Posted"),
("cancelled", "Cancelled"),
],
string="State",
readonly=True,
default="draft",
)
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -203,7 +202,7 @@ def onchange_template_id(self):
if not self.closing_template_id:
return
config_obj = self.env["account.fiscalyear.closing.config"]
tmpl = self.closing_template_id.with_context(force_company=self.company_id.id)
tmpl = self.closing_template_id.with_company(self.company_id)
self.check_draft_moves = tmpl.check_draft_moves
for tmpl_config in tmpl.move_config_ids:
self.move_config_ids += config_obj.new(self._prepare_config(tmpl_config))
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -551,15 +550,16 @@ 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 vals.get("dest_account_id", False):
vals["dest_account_id"] = vals["dest_account_id"][0]
res = super(AccountFiscalyearClosingMapping, self).create(vals_list)
return res

def write(self, vals):
if "dest_account_id" in vals:
if vals.get("dest_account_id", False):
vals["dest_account_id"] = vals["dest_account_id"][0]
res = super(AccountFiscalyearClosingMapping, self).write(vals)
return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
)
1 change: 1 addition & 0 deletions account_fiscal_year_closing/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* `CorporateHub <https://corporatehub.eu/>`__

* Alexey Pelykh <[email protected]>
* Giuseppe Borruso <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field name="global" eval="True" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>

<record id="fiscalyear_closing_template_multi_company_rule" model="ir.rule">
Expand All @@ -18,7 +18,7 @@
<field name="global" eval="True" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>

</odoo>
Loading

0 comments on commit 1ed9668

Please sign in to comment.