From 4e1edbd5b2289ef5e1be684516cf9a5b201eef8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Fri, 14 Dec 2018 10:42:31 +0100 Subject: [PATCH] [MIG] account_move_fiscal_year: Migration to v12 --- account_move_fiscal_year/README.rst | 71 ++- account_move_fiscal_year/__init__.py | 1 + account_move_fiscal_year/__manifest__.py | 2 +- account_move_fiscal_year/models/__init__.py | 3 + .../models/account_move.py | 21 +- .../models/account_move_line.py | 2 +- .../models/res_company.py | 21 + account_move_fiscal_year/readme/CONFIGURE.rst | 2 + .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 1 + account_move_fiscal_year/readme/INSTALL.rst | 2 + account_move_fiscal_year/readme/USAGE.rst | 3 + .../static/description/index.html | 435 ++++++++++++++++++ account_move_fiscal_year/tests/__init__.py | 2 + .../tests/test_account_move_fiscal_year.py | 25 +- 15 files changed, 541 insertions(+), 52 deletions(-) create mode 100644 account_move_fiscal_year/models/res_company.py create mode 100644 account_move_fiscal_year/readme/CONFIGURE.rst create mode 100644 account_move_fiscal_year/readme/CONTRIBUTORS.rst create mode 100644 account_move_fiscal_year/readme/DESCRIPTION.rst create mode 100644 account_move_fiscal_year/readme/INSTALL.rst create mode 100644 account_move_fiscal_year/readme/USAGE.rst create mode 100644 account_move_fiscal_year/static/description/index.html diff --git a/account_move_fiscal_year/README.rst b/account_move_fiscal_year/README.rst index 8deaa31ff..6ffaf6469 100644 --- a/account_move_fiscal_year/README.rst +++ b/account_move_fiscal_year/README.rst @@ -1,62 +1,93 @@ -.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - ======================== Account Move Fiscal Year ======================== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/12.0/account_move_fiscal_year + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-12-0/account-financial-tools-12-0-account_move_fiscal_year + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + Display the fiscal year on journal entries/items. +**Table of contents** + +.. contents:: + :local: + 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/11.0 + +Go to Invoicing -> Configuration -> Date Ranges -> Fiscal Years to create a new +Fiscal Year. 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. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* ACSONE SA/NV Contributors ------------- +~~~~~~~~~~~~ + * Benjamin Willig -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_fiscal_year/__init__.py b/account_move_fiscal_year/__init__.py index 0650744f6..02179fb04 100644 --- a/account_move_fiscal_year/__init__.py +++ b/account_move_fiscal_year/__init__.py @@ -1 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/account_move_fiscal_year/__manifest__.py b/account_move_fiscal_year/__manifest__.py index 5469683ec..e75026781 100644 --- a/account_move_fiscal_year/__manifest__.py +++ b/account_move_fiscal_year/__manifest__.py @@ -5,7 +5,7 @@ 'name': 'Account Move Fiscal Year', 'summary': """ Display the fiscal year on journal entries/item""", - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'license': 'AGPL-3', 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/account-financial-tools', diff --git a/account_move_fiscal_year/models/__init__.py b/account_move_fiscal_year/models/__init__.py index 0d5ab6a2f..db01e5d7d 100644 --- a/account_move_fiscal_year/models/__init__.py +++ b/account_move_fiscal_year/models/__init__.py @@ -1,2 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import account_move from . import account_move_line +from . import res_company diff --git a/account_move_fiscal_year/models/account_move.py b/account_move_fiscal_year/models/account_move.py index bcf86c541..3a5964bc6 100644 --- a/account_move_fiscal_year/models/account_move.py +++ b/account_move_fiscal_year/models/account_move.py @@ -10,20 +10,14 @@ 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(), + comodel_name='account.fiscal.year', string="Fiscal year", 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) + date = fields.Date.to_date(rec.date) company = rec.company_id rec.date_range_fy_id =\ company and company.find_daterange_fy(date) or False @@ -35,17 +29,14 @@ class AccountMove(models.Model): 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) + date_ranges = self.env['account.fiscal.year'].search(date_range_domain) - domain = [] + domain = [('id', '=', -1)] for date_range in date_ranges: domain = expression.OR([domain, [ '&', - '&', - ('date', '>=', date_range.date_start), - ('date', '<=', date_range.date_end), + ('date', '>=', date_range.date_from), + ('date', '<=', date_range.date_to), '|', ('company_id', '=', False), ('company_id', '=', date_range.company_id.id), diff --git a/account_move_fiscal_year/models/account_move_line.py b/account_move_fiscal_year/models/account_move_line.py index 25b0f9563..9b398a667 100644 --- a/account_move_fiscal_year/models/account_move_line.py +++ b/account_move_fiscal_year/models/account_move_line.py @@ -9,5 +9,5 @@ class AccountMoveLine(models.Model): _inherit = 'account.move.line' date_range_fy_id = fields.Many2one( - related='move_id.date_range_fy_id', readonly=True, + related='move_id.date_range_fy_id', store=True, copy=False) diff --git a/account_move_fiscal_year/models/res_company.py b/account_move_fiscal_year/models/res_company.py new file mode 100644 index 000000000..9b228a2e3 --- /dev/null +++ b/account_move_fiscal_year/models/res_company.py @@ -0,0 +1,21 @@ +# Author: Damien Crier +# Copyright 2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models + + +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 + """ + fiscalyear = self.env['account.fiscal.year'].search([ + ('company_id', '=', self.id), + ('date_from', '<=', date), + ('date_to', '>=', date), + ], limit=1) + + return fiscalyear diff --git a/account_move_fiscal_year/readme/CONFIGURE.rst b/account_move_fiscal_year/readme/CONFIGURE.rst new file mode 100644 index 000000000..5090ddf53 --- /dev/null +++ b/account_move_fiscal_year/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ + +You just need to create date ranges associated to 'Fiscal Year' type. \ No newline at end of file diff --git a/account_move_fiscal_year/readme/CONTRIBUTORS.rst b/account_move_fiscal_year/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..25156d806 --- /dev/null +++ b/account_move_fiscal_year/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ + +* Benjamin Willig diff --git a/account_move_fiscal_year/readme/DESCRIPTION.rst b/account_move_fiscal_year/readme/DESCRIPTION.rst new file mode 100644 index 000000000..dbc00857b --- /dev/null +++ b/account_move_fiscal_year/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Display the fiscal year on journal entries/items. \ No newline at end of file diff --git a/account_move_fiscal_year/readme/INSTALL.rst b/account_move_fiscal_year/readme/INSTALL.rst new file mode 100644 index 000000000..cb7efc18b --- /dev/null +++ b/account_move_fiscal_year/readme/INSTALL.rst @@ -0,0 +1,2 @@ + +You need to install account_fiscal_year. \ No newline at end of file diff --git a/account_move_fiscal_year/readme/USAGE.rst b/account_move_fiscal_year/readme/USAGE.rst new file mode 100644 index 000000000..e2886e4b8 --- /dev/null +++ b/account_move_fiscal_year/readme/USAGE.rst @@ -0,0 +1,3 @@ + +Go to Invoicing -> Configuration -> Date Ranges -> Fiscal Years to create a new +Fiscal Year. \ No newline at end of file diff --git a/account_move_fiscal_year/static/description/index.html b/account_move_fiscal_year/static/description/index.html new file mode 100644 index 000000000..52ab0e33e --- /dev/null +++ b/account_move_fiscal_year/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Account Move Fiscal Year + + + +
+

Account Move Fiscal Year

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runbot

+

Display the fiscal year on journal entries/items.

+

Table of contents

+ +
+

Installation

+

You need to install account_fiscal_year.

+
+
+

Configuration

+

You just need to create date ranges associated to ‘Fiscal Year’ type.

+
+
+

Usage

+

Go to Invoicing -> Configuration -> Date Ranges -> Fiscal Years to create a new +Fiscal Year.

+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_move_fiscal_year/tests/__init__.py b/account_move_fiscal_year/tests/__init__.py index 5353d3de2..68147ab8b 100644 --- a/account_move_fiscal_year/tests/__init__.py +++ b/account_move_fiscal_year/tests/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + 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 index 8e7f297f3..10402be1b 100644 --- a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py +++ b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py @@ -12,7 +12,7 @@ class TestAccountMoveFiscalYear(TransactionCase): 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.DateRangeObj = self.env['account.fiscal.year'] self.bank_journal = self.AccountJournalObj.search([ ('type', '=', 'bank') @@ -36,21 +36,16 @@ class TestAccountMoveFiscalYear(TransactionCase): '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, + 'date_from': '2017-01-01', + 'date_to': '2017-12-31', }) 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, + 'date_from': '2018-01-01', + 'date_to': '2018-12-31', }) def create_account_move(self, date_str): @@ -72,7 +67,7 @@ class TestAccountMoveFiscalYear(TransactionCase): }) def test_01_account_move_date_range_fy_id_compute(self): - january_1st = Date.from_string('2017-01-01') + january_1st = Date.to_date('2017-01-01') move = self.create_account_move(january_1st) self.assertEquals( @@ -83,16 +78,16 @@ class TestAccountMoveFiscalYear(TransactionCase): for line in move.line_ids ]), msg="All lines period should be 2017") - january_2019 = Date.from_string('2019-01-01') + january_2019 = Date.to_date('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') + january_2017 = Date.to_date('2017-01-01') + january_2018 = Date.to_date('2018-01-01') + january_2019 = Date.to_date('2019-01-01') move_2017 = self.create_account_move(january_2017) move_2018 = self.create_account_move(january_2018)