diff --git a/account_move_fiscal_year/README.rst b/account_move_fiscal_year/README.rst new file mode 100644 index 00000000..764e6bed --- /dev/null +++ b/account_move_fiscal_year/README.rst @@ -0,0 +1,62 @@ +.. 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 Move Fiscal Year +======================== + +Display the fiscal year on journal entries/items. + +Installation +============ + +You need to install account_fiscal_year. + +Configuration +============= + +You just need to create date ranges associated to 'Fiscal Year' type. + +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/92/10.0 + +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_move_fiscal_year/__init__.py b/account_move_fiscal_year/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_move_fiscal_year/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_fiscal_year/__manifest__.py b/account_move_fiscal_year/__manifest__.py new file mode 100644 index 00000000..62bfb930 --- /dev/null +++ b/account_move_fiscal_year/__manifest__.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). + +{ + 'name': 'Account Move Fiscal Year', + 'summary': """ + Display the fiscal year on journal entries/item""", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/account-financial-tools', + 'depends': [ + 'account_fiscal_year', + ], + 'data': [ + 'views/account_move.xml', + 'views/account_move_line.xml', + ], + 'demo': [ + ], +} diff --git a/account_move_fiscal_year/models/__init__.py b/account_move_fiscal_year/models/__init__.py new file mode 100644 index 00000000..0d5ab6a2 --- /dev/null +++ b/account_move_fiscal_year/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move +from . import account_move_line diff --git a/account_move_fiscal_year/models/account_move.py b/account_move_fiscal_year/models/account_move.py new file mode 100644 index 00000000..48208dd2 --- /dev/null +++ b/account_move_fiscal_year/models/account_move.py @@ -0,0 +1,53 @@ +# -*- 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.osv import expression + + +class AccountMove(models.Model): + + _inherit = 'account.move' + + date_range_fy_id = fields.Many2one( + comodel_name='date.range', string="Fiscal year", + domain=lambda self: self._get_date_range_fy_domain(), + compute='_compute_date_range_fy', search='_search_date_range_fy') + + @api.model + def _get_date_range_fy_domain(self): + fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear') + return "[('type_id', '=', %d)]" % fiscal_year_type.id + + @api.multi + @api.depends('date', 'company_id') + def _compute_date_range_fy(self): + for rec in self: + date = fields.Date.from_string(rec.date) + company = rec.company_id + rec.date_range_fy_id = company.find_daterange_fy(date) + + @api.model + def _search_date_range_fy(self, operator, value): + if operator in ('=', '!=', 'in', 'not in'): + date_range_domain = [('id', operator, value)] + else: + date_range_domain = [('name', operator, value)] + + fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear') + date_range_domain.append(('type_id', '=', fiscal_year_type.id)) + date_ranges = self.env['date.range'].search(date_range_domain) + + domain = [] + for date_range in date_ranges: + domain = expression.OR([domain, [ + '&', + '&', + ('date', '>=', date_range.date_start), + ('date', '<=', date_range.date_end), + '|', + ('company_id', '=', False), + ('company_id', '=', date_range.company_id.id), + ]]) + return domain diff --git a/account_move_fiscal_year/models/account_move_line.py b/account_move_fiscal_year/models/account_move_line.py new file mode 100644 index 00000000..876f124a --- /dev/null +++ b/account_move_fiscal_year/models/account_move_line.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountMoveLine(models.Model): + + _inherit = 'account.move.line' + + date_range_fy_id = fields.Many2one( + related='move_id.date_range_fy_id', readonly=True) diff --git a/account_move_fiscal_year/static/description/icon.png b/account_move_fiscal_year/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_move_fiscal_year/static/description/icon.png differ diff --git a/account_move_fiscal_year/tests/__init__.py b/account_move_fiscal_year/tests/__init__.py new file mode 100644 index 00000000..5353d3de --- /dev/null +++ b/account_move_fiscal_year/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_fiscal_year diff --git a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py new file mode 100644 index 00000000..59fabd0b --- /dev/null +++ b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.fields import Date +from odoo.tests.common import TransactionCase + + +class TestAccountMoveFiscalYear(TransactionCase): + + def setUp(self): + super(TestAccountMoveFiscalYear, self).setUp() + self.AccountObj = self.env['account.account'] + self.AccountJournalObj = self.env['account.journal'] + self.AccountMoveObj = self.env['account.move'] + self.DateRangeObj = self.env['date.range'] + + self.bank_journal = self.AccountJournalObj.search([ + ('type', '=', 'bank') + ], limit=1) + + self.account_type_recv = self.env.ref( + 'account.data_account_type_receivable') + self.account_type_rev = self.env.ref( + 'account.data_account_type_revenue') + + self.account_recv = self.AccountObj.create({ + 'code': 'RECV_DR', + 'name': "Receivable (test)", + 'reconcile': True, + 'user_type_id': self.account_type_recv.id, + }) + self.account_sale = self.AccountObj.create({ + 'code': 'SALE_DR', + 'name': "Receivable (sale)", + 'reconcile': True, + 'user_type_id': self.account_type_rev.id, + }) + + self.date_range_type_year = self.env.ref( + 'account_fiscal_year.fiscalyear') + + self.date_range_2017 = self.DateRangeObj.create({ + 'name': "2017", + 'date_start': '2017-01-01', + 'date_end': '2017-12-31', + 'type_id': self.date_range_type_year.id, + }) + + self.date_range_2018 = self.DateRangeObj.create({ + 'name': "2018", + 'date_start': '2018-01-01', + 'date_end': '2018-12-31', + 'type_id': self.date_range_type_year.id, + }) + + def create_account_move(self, date_str): + return self.AccountMoveObj.create({ + 'journal_id': self.bank_journal.id, + 'date': date_str, + 'line_ids': [ + (0, 0, { + 'name': "Debit", + 'debit': 1000, + 'account_id': self.account_recv.id, + }), + (0, 0, { + 'name': "Credit", + 'credit': 1000, + 'account_id': self.account_sale.id, + }), + ] + }) + + def test_01_account_move_date_range_fy_id_compute(self): + january_1st = Date.from_string('2017-01-01') + move = self.create_account_move(january_1st) + + self.assertEquals( + move.date_range_fy_id, self.date_range_2017, + msg="Move period should be 2017") + self.assertTrue(all([ + line.date_range_fy_id == self.date_range_2017 + for line in move.line_ids + ]), msg="All lines period should be 2017") + + january_2019 = Date.from_string('2019-01-01') + move = self.create_account_move(january_2019) + self.assertFalse( + bool(move.date_range_fy_id), + msg="Move shouldn't have any date range") + + def test_02_account_move_date_range_fy_id_search(self): + january_2017 = Date.from_string('2017-01-01') + january_2018 = Date.from_string('2018-01-01') + january_2019 = Date.from_string('2019-01-01') + + move_2017 = self.create_account_move(january_2017) + move_2018 = self.create_account_move(january_2018) + move_2019 = self.create_account_move(january_2019) + + moves = self.AccountMoveObj.search([ + ('date_range_fy_id', 'ilike', '2017'), + ]) + + self.assertTrue(all([ + move_2017 in moves, + move_2018 not in moves, + move_2019 not in moves, + ]), msg="There should be only moves in 2017") + + moves = self.AccountMoveObj.search([ + ('date_range_fy_id', '=', self.date_range_2017.id), + ]) + + self.assertTrue(all([ + move_2017 in moves, + move_2018 not in moves, + move_2019 not in moves, + ])) + + moves = self.AccountMoveObj.search([ + ('date_range_fy_id', 'in', ( + self.date_range_2017.id, + self.date_range_2018.id + )), + ]) + + self.assertTrue(all([ + move_2017 in moves, + move_2018 in moves, + move_2019 not in moves, + ])) diff --git a/account_move_fiscal_year/views/account_move.xml b/account_move_fiscal_year/views/account_move.xml new file mode 100644 index 00000000..6fcb1e8c --- /dev/null +++ b/account_move_fiscal_year/views/account_move.xml @@ -0,0 +1,49 @@ + + + + + + + account.move.form (in account_move_fiscal_year) + account.move + + + + + + + + + + + + + account.move.search (in account_move_fiscal_year) + account.move + + + + + + + + + + + + + account.move.tree (in account_move_fiscal_year) + account.move + + + + + + + + + + + + diff --git a/account_move_fiscal_year/views/account_move_line.xml b/account_move_fiscal_year/views/account_move_line.xml new file mode 100644 index 00000000..6f218c35 --- /dev/null +++ b/account_move_fiscal_year/views/account_move_line.xml @@ -0,0 +1,49 @@ + + + + + + + account.move.line.form (in account_move_fiscal_year) + account.move.line + + + + + + + + + + + + + account.move.line.search (in account_move_fiscal_year) + account.move.line + + + + + + + + + + + + + account.move.line.tree (in account_move_fiscal_year) + account.move.line + + + + + + + + + + + +