Commit 22385189 authored by damien.habets's avatar damien.habets

Analytics added to fiscal years.

branch : 13.0
parent 2dfa8a4d4fa5
Pipeline #14685 passed with stages
in 3 minutes and 19 seconds
pulluri =
layout = ../analytic_structure
track =
......@@ -2,6 +2,11 @@
Optionally, also bind each fiscalyear to an analytic code
......@@ -19,3 +19,8 @@ may however set in advance.
This module also adds a transaction date in accounting documents.
Inspired from what used to be available in previous Odoo versions.
Optionally, also bind each fiscalyear to an analytic code; enable by adding
into the ``[analytic]`` section of the Odoo conf file::
; Enable bound fiscalyear analytics (account_period module).
bound_fiscalyear_dimension = 1
......@@ -22,11 +22,11 @@
"name": "Accounting Periods",
"license": "AGPL-3",
"summary": "Add period accounting concept",
"version": "",
"version": "",
"category": "Accounting/Accounting",
"author": "XCG Consulting",
"website": "",
"depends": ["account"],
"depends": ["account", "analytic_structure"],
"data": [
......@@ -21,21 +21,67 @@ import logging
from dateutil.relativedelta import relativedelta
from odoo import SUPERUSER_ID, _, api, fields, models
from odoo import SUPERUSER_ID, _, api, fields, models, tools
from odoo.exceptions import ValidationError
from odoo.addons.analytic_structure.MetaAnalytic import MetaAnalytic
_logger = logging.getLogger(__name__)
class AccountFiscalyear(models.Model):
class AccountFiscalyear(models.Model, metaclass=MetaAnalytic):
"""Account fiscal year defined an accounting year.
_name = "account.fiscalyear"
_description = "Fiscal year"
_analytic = True
_order = "date_start, id"
# Each fiscalyear may be bound to an analytic code.
# By default this feature is disabled; add the following setting to enable:
# [analytic]
# bound_fiscalyear_dimension = 1
if int(tools.config.get_misc("analytic", "bound_fiscalyear_dimension", 0)):
_dimension = {
"code_name": "year",
"code_description": "year",
"required": False, # Various default fiscalyear don't need one.
def get_bound_analytics(self, model):
"""Get the analytic code bound to this model, ready to be fed into the
specified model, when the latter contains a corresponding analytic
# Find the analytic dimension bound to this model.
dimension = self.env.ref(
if not dimension:
# Find out whether the dimension is used in the spcified model.
model_dim = (
if not model_dim:
# Find the analytic code bound to this model.
anc = self.analytic_id
if not anc:
return {"a%s_id" % model_dim:}
code = fields.Char(
help="Unique code of this fiscal year.",
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment