diff --git a/account_fiscal_month/README.rst b/account_fiscal_month/README.rst new file mode 100644 index 000000000..8f95ad698 --- /dev/null +++ b/account_fiscal_month/README.rst @@ -0,0 +1,55 @@ +.. 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 Month +==================== + +This module simply provides a date range type marked as 'Fiscal month'. + +Installation +============ + +Just Install it. + +Configuration +============= + +No configuration needed. + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Benjamin Willig + +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. diff --git a/account_fiscal_month/__init__.py b/account_fiscal_month/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_fiscal_month/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_fiscal_month/__manifest__.py b/account_fiscal_month/__manifest__.py new file mode 100644 index 000000000..c8fac9fff --- /dev/null +++ b/account_fiscal_month/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Fiscal Month', + 'summary': """ + Provide a fiscal month date range type""", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': 'https://www.acsone.eu', + 'depends': [ + 'account', + 'date_range', + ], + 'data': [ + 'data/date_range_type.xml', + 'views/date_range_type.xml', + ], +} diff --git a/account_fiscal_month/data/date_range_type.xml b/account_fiscal_month/data/date_range_type.xml new file mode 100644 index 000000000..8a7dfb4a3 --- /dev/null +++ b/account_fiscal_month/data/date_range_type.xml @@ -0,0 +1,13 @@ + + + + + + + Fiscal month + + + + + diff --git a/account_fiscal_month/models/__init__.py b/account_fiscal_month/models/__init__.py new file mode 100644 index 000000000..55f0021bf --- /dev/null +++ b/account_fiscal_month/models/__init__.py @@ -0,0 +1,2 @@ +from . import date_range_type +from . import res_company diff --git a/account_fiscal_month/models/date_range_type.py b/account_fiscal_month/models/date_range_type.py new file mode 100644 index 000000000..03ea690c8 --- /dev/null +++ b/account_fiscal_month/models/date_range_type.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class DateRangeType(models.Model): + + _inherit = 'date.range.type' + + fiscal_month = fields.Boolean(string="Is fiscal month?", readonly=True) + + @api.multi + def unlink(self): + date_range_type_fm = self.env.ref( + 'account_fiscal_month.date_range_fiscal_month') + if date_range_type_fm.id in self.ids: + raise UserError(_("You can't delete date range type: " + "Fiscal month")) + return super(DateRangeType, self).unlink() diff --git a/account_fiscal_month/models/res_company.py b/account_fiscal_month/models/res_company.py new file mode 100644 index 000000000..140acd606 --- /dev/null +++ b/account_fiscal_month/models/res_company.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ResCompany(models.Model): + + _inherit = 'res.company' + + @api.multi + def find_daterange_fm(self, date_str): + self.ensure_one() + fm_id = self.env.ref('account_fiscal_month.date_range_fiscal_month') + return self.env['date.range'].search([ + ('type_id', '=', fm_id.id), + ('date_start', '<=', date_str), + ('date_end', '>=', date_str), + ('company_id', '=', self.id), + ]) diff --git a/account_fiscal_month/static/description/icon.png b/account_fiscal_month/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_fiscal_month/static/description/icon.png differ diff --git a/account_fiscal_month/tests/__init__.py b/account_fiscal_month/tests/__init__.py new file mode 100644 index 000000000..d36402d52 --- /dev/null +++ b/account_fiscal_month/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_fiscal_month diff --git a/account_fiscal_month/tests/test_account_fiscal_month.py b/account_fiscal_month/tests/test_account_fiscal_month.py new file mode 100644 index 000000000..4ab5c070f --- /dev/null +++ b/account_fiscal_month/tests/test_account_fiscal_month.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.fields import Date +from odoo.tests.common import TransactionCase + + +class TestAccountFiscalMonth(TransactionCase): + + def setUp(self): + super(TestAccountFiscalMonth, self).setUp() + self.DateRangeObj = self.env['date.range'] + + self.company = self.env.ref('base.main_company') + self.date_range_type_month = self.env.ref( + 'account_fiscal_month.date_range_fiscal_month') + + self.date_range_january_2017 = self.DateRangeObj.create({ + 'name': "January 2017", + 'date_start': '2017-01-01', + 'date_end': '2017-01-31', + 'type_id': self.date_range_type_month.id, + 'company_id': self.company.id, + }) + self.date_range_january_no_comp_2017 = self.DateRangeObj.create({ + 'name': "January 2017", + 'date_start': '2017-01-01', + 'date_end': '2017-01-31', + 'type_id': self.date_range_type_month.id, + 'company_id': False, + }) + + def test_01_delete_type_fiscal_month(self): + with self.assertRaises(UserError): + self.date_range_type_month.unlink() + + def test_02_search_date_range(self): + january_2017_1st = Date.from_string('2017-01-01') + date_ranges = self.company.find_daterange_fm(january_2017_1st) + + self.assertEquals(len(date_ranges), 1) + self.assertEquals(date_ranges[0], self.date_range_january_2017) diff --git a/account_fiscal_month/views/date_range_type.xml b/account_fiscal_month/views/date_range_type.xml new file mode 100644 index 000000000..67b59302a --- /dev/null +++ b/account_fiscal_month/views/date_range_type.xml @@ -0,0 +1,33 @@ + + + + + + + date.range.type.form (in account_fiscal_month) + date.range.type + + + + + + + + + + + + date.range.type.tree (in account_fiscal_month) + date.range.type + + + + + + + + + + + diff --git a/setup/account_fiscal_month/odoo/__init__.py b/setup/account_fiscal_month/odoo/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/account_fiscal_month/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/account_fiscal_month/odoo/addons/__init__.py b/setup/account_fiscal_month/odoo/addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/account_fiscal_month/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/account_fiscal_month/odoo/addons/account_fiscal_month b/setup/account_fiscal_month/odoo/addons/account_fiscal_month new file mode 120000 index 000000000..3317a65e3 --- /dev/null +++ b/setup/account_fiscal_month/odoo/addons/account_fiscal_month @@ -0,0 +1 @@ +../../../../account_fiscal_month \ No newline at end of file diff --git a/setup/account_fiscal_month/setup.py b/setup/account_fiscal_month/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_fiscal_month/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)