[ADD] add module "account_fiscal_year"
This commit is contained in:
parent
f9ddfe348f
commit
8c7d7661d9
78
account_fiscal_year/README.rst
Normal file
78
account_fiscal_year/README.rst
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
===================
|
||||||
|
Account Fiscal Year
|
||||||
|
===================
|
||||||
|
|
||||||
|
This module extends date.range.type to add fiscal_year flag.
|
||||||
|
|
||||||
|
Override official res_company.compute_fiscal_year_dates to get the
|
||||||
|
fiscal year date start / date end for any given date.
|
||||||
|
That methods first looks for a date range of type fiscal year that
|
||||||
|
encloses the give date.
|
||||||
|
If it does not find it, it falls back on the standard Odoo
|
||||||
|
technique based on the day/month of end of fiscal year.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Just install it
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
Nothing
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
|
||||||
|
|
||||||
|
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
|
||||||
|
.. branch is "8.0" for example
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
* ...
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues
|
||||||
|
<https://github.com/OCA/{project_repo}/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.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Images
|
||||||
|
------
|
||||||
|
|
||||||
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Damien Crier <damien.crier@camptocamp.com>
|
||||||
|
* ...
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
To contribute to this module, please visit https://odoo-community.org.
|
6
account_fiscal_year/__init__.py
Normal file
6
account_fiscal_year/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import models
|
30
account_fiscal_year/__openerp__.py
Normal file
30
account_fiscal_year/__openerp__.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
{
|
||||||
|
'name': 'Account Fiscal Year',
|
||||||
|
'version': '9.0.0.1.0',
|
||||||
|
'category': 'Accounting',
|
||||||
|
'author': 'Camptocamp SA,'
|
||||||
|
'Odoo Community Association (OCA)',
|
||||||
|
'website': 'http://www.camptocamp.com',
|
||||||
|
'depends': [
|
||||||
|
'account',
|
||||||
|
'date_range'
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'data/date_range_type.xml',
|
||||||
|
'views/date_range_type.xml',
|
||||||
|
],
|
||||||
|
'test': [
|
||||||
|
],
|
||||||
|
'demo': [
|
||||||
|
],
|
||||||
|
'qweb': [
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
'application': True,
|
||||||
|
'auto_install': False,
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
}
|
10
account_fiscal_year/data/date_range_type.xml
Normal file
10
account_fiscal_year/data/date_range_type.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data noupdate="0">
|
||||||
|
<record id="fiscalyear" model="date.range.type">
|
||||||
|
<field name="name">Fiscal Year</field>
|
||||||
|
<field name="allow_overlap" eval="False"/>
|
||||||
|
<field name="fiscal_year" eval="True"/>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
8
account_fiscal_year/models/__init__.py
Normal file
8
account_fiscal_year/models/__init__.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import date_range
|
||||||
|
from . import date_range_type
|
||||||
|
from . import res_company
|
25
account_fiscal_year/models/date_range.py
Normal file
25
account_fiscal_year/models/date_range.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from openerp import models
|
||||||
|
from openerp.tools import (DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
|
class DateRange(models.Model):
|
||||||
|
_inherit = 'date.range'
|
||||||
|
|
||||||
|
def find_daterange_fy_start(self, date):
|
||||||
|
"""
|
||||||
|
try to find a date range with type 'fiscalyear'
|
||||||
|
with @param:date <= date_start
|
||||||
|
"""
|
||||||
|
fy_id = self.env.ref('account_fiscal_year.fiscalyear')
|
||||||
|
date_str = date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
s_args = [
|
||||||
|
('type_id', '=', fy_id.id),
|
||||||
|
('date_start', '<=', date_str),
|
||||||
|
('company_id', '=', self.company_id.id),
|
||||||
|
]
|
||||||
|
date_range = self.env['date.range'].search(s_args)
|
||||||
|
return date_range.date_start
|
12
account_fiscal_year/models/date_range_type.py
Normal file
12
account_fiscal_year/models/date_range_type.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from openerp import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class DateRangeType(models.Model):
|
||||||
|
_inherit = "date.range.type"
|
||||||
|
|
||||||
|
fiscal_year = fields.Boolean(string='Is fiscal year ?', default=False)
|
45
account_fiscal_year/models/res_company.py
Normal file
45
account_fiscal_year/models/res_company.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from openerp import models, fields, api
|
||||||
|
from openerp.tools import (DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
|
class ResCompany(models.Model):
|
||||||
|
_inherit = 'res.company'
|
||||||
|
|
||||||
|
def find_daterange_fy(self, date):
|
||||||
|
"""
|
||||||
|
try to find a date range with type 'fiscalyear'
|
||||||
|
with @param:date contained in its date_start/date_end interval
|
||||||
|
"""
|
||||||
|
fy_id = self.env.ref('account_fiscal_year.fiscalyear')
|
||||||
|
date_str = date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
s_args = [
|
||||||
|
('type_id', '=', fy_id.id),
|
||||||
|
('date_start', '<=', date_str),
|
||||||
|
('date_end', '>=', date_str),
|
||||||
|
('company_id', '=', self.id),
|
||||||
|
]
|
||||||
|
date_range = self.env['date.range'].search(s_args)
|
||||||
|
return date_range
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def compute_fiscalyear_dates(self, date):
|
||||||
|
""" Computes the start and end dates of the fiscalyear where the given
|
||||||
|
'date' belongs to
|
||||||
|
@param date: a datetime object
|
||||||
|
@returns: a dictionary with date_from and date_to
|
||||||
|
"""
|
||||||
|
self = self[0]
|
||||||
|
date_range = self.find_daterange_fy(date)
|
||||||
|
if date_range:
|
||||||
|
# do stuff and override 'normal' behaviour
|
||||||
|
return {
|
||||||
|
'date_from': fields.Date.from_string(date_range[0].date_start),
|
||||||
|
'date_to': fields.Date.from_string(date_range[0].date_end),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# fall back to standard Odoo computation
|
||||||
|
return super(ResCompany, self).compute_fiscalyear_dates(date)
|
6
account_fiscal_year/tests/__init__.py
Normal file
6
account_fiscal_year/tests/__init__.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import test_account_fiscal_year
|
54
account_fiscal_year/tests/test_account_fiscal_year.py
Normal file
54
account_fiscal_year/tests/test_account_fiscal_year.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Damien Crier
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
import openerp.tests.common as common
|
||||||
|
from openerp import fields
|
||||||
|
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
|
||||||
|
DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
|
def to_odoo_datetime(date):
|
||||||
|
return date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
|
def to_odoo_date(date):
|
||||||
|
return date.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
|
class TestAccountFiscalYear(common.TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestAccountFiscalYear, self).setUp()
|
||||||
|
self.today_date = fields.Date.from_string(fields.Date.today())
|
||||||
|
self.company = self.env.ref('base.main_company')
|
||||||
|
|
||||||
|
def test_example(self):
|
||||||
|
demo_date_range = self.env['date.range'].create(
|
||||||
|
{'name': 'FY%s' % (self.today_date.year),
|
||||||
|
'date_start': '%s-01-01' % self.today_date.year,
|
||||||
|
'date_end': '%s-12-31' % self.today_date.year,
|
||||||
|
'type_id': self.env.ref('account_fiscal_year.fiscalyear').id,
|
||||||
|
'company_id': self.company.id,
|
||||||
|
'active': True})
|
||||||
|
result = self.company.compute_fiscalyear_dates(self.today_date)
|
||||||
|
self.assertEqual(to_odoo_datetime(result['date_from']),
|
||||||
|
demo_date_range.date_start)
|
||||||
|
self.assertEqual(to_odoo_datetime(result['date_to']),
|
||||||
|
demo_date_range.date_end)
|
||||||
|
|
||||||
|
def test_example2(self):
|
||||||
|
demo_date_range = self.env['date.range'].create(
|
||||||
|
{'name': 'FY%s' % (self.today_date.year),
|
||||||
|
'date_start': '%s-03-01' % self.today_date.year,
|
||||||
|
'date_end': '%s-12-31' % self.today_date.year,
|
||||||
|
'type_id': self.env.ref('account_fiscal_year.fiscalyear').id,
|
||||||
|
'company_id': self.company.id,
|
||||||
|
'active': True})
|
||||||
|
result = self.company.compute_fiscalyear_dates(self.today_date)
|
||||||
|
if to_odoo_date(self.today_date) >= demo_date_range.date_start:
|
||||||
|
self.assertEqual(to_odoo_datetime(result['date_from']),
|
||||||
|
demo_date_range.date_start)
|
||||||
|
self.assertEqual(to_odoo_datetime(result['date_to']),
|
||||||
|
demo_date_range.date_end)
|
27
account_fiscal_year/views/date_range_type.xml
Normal file
27
account_fiscal_year/views/date_range_type.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="view_date_range_type_fiscalyear_tree" model="ir.ui.view">
|
||||||
|
<field name="name">date.range.type.tree</field>
|
||||||
|
<field name="model">date.range.type</field>
|
||||||
|
<field name="inherit_id" ref="date_range.view_date_range_type_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="allow_overlap" position="after">
|
||||||
|
<field name="fiscal_year"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="view_date_range_type_fiscalyear_form_view" model="ir.ui.view">
|
||||||
|
<field name="name">date.range.type.form</field>
|
||||||
|
<field name="model">date.range.type</field>
|
||||||
|
<field name="inherit_id" ref="date_range.view_date_range_type_form_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="allow_overlap" position="after">
|
||||||
|
<field name="fiscal_year"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user