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

Analytics added to fiscal years.

--HG--
branch : 13.0
parent 2dfa8a4d4fa5
Pipeline #14685 passed with stages
in 3 minutes and 19 seconds
[analytic_structure]
pulluri = https://orus.io/xcg/odoo-modules/analytic_structure
layout = ../analytic_structure
track = 13.0.1.0.0
......@@ -2,6 +2,11 @@
Changelog
=========
13.0.1.2.0
----------
Optionally, also bind each fiscalyear to an analytic code
13.0.1.1.1
----------
......
......@@ -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": "13.0.1.1.1",
"version": "13.0.1.2.1",
"category": "Accounting/Accounting",
"author": "XCG Consulting",
"website": "https://odoo.consulting/",
"depends": ["account"],
"depends": ["account", "analytic_structure"],
"data": [
"security/ir.model.access.csv",
"security/record_rules.xml",
......
......@@ -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
dimension.
"""
self.ensure_one()
# Find the analytic dimension bound to this model.
dimension = self.env.ref(
".account_fiscalyear_analytic_dimension_id",
raise_if_not_found=False,
)
if not dimension:
return
# Find out whether the dimension is used in the spcified model.
model_dim = (
self.env["analytic.structure"]
.get_dimensions(model)
.get(dimension.id)
)
if not model_dim:
return
# Find the analytic code bound to this model.
anc = self.analytic_id
if not anc:
return
return {"a%s_id" % model_dim: anc.id}
code = fields.Char(
string="Code",
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