diff --git a/account_financial_report_webkit/README.rst b/account_financial_report_webkit/README.rst index f58645d7..caecc09d 100644 --- a/account_financial_report_webkit/README.rst +++ b/account_financial_report_webkit/README.rst @@ -165,6 +165,7 @@ Contributors * Nicolas Bessi * Guewen Baconnier * David Dufresne +* Luc De Meyer Maintainer ---------- diff --git a/account_financial_report_webkit/__openerp__.py b/account_financial_report_webkit/__openerp__.py index 98c42008..d77c80a5 100644 --- a/account_financial_report_webkit/__openerp__.py +++ b/account_financial_report_webkit/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## { 'name': 'Financial Reports - Webkit', - 'version': '8.0.1.2.0', + 'version': '8.0.1.2.1', 'author': ( "Camptocamp," "Savoir-faire Linux," diff --git a/account_financial_report_webkit/tests/__init__.py b/account_financial_report_webkit/tests/__init__.py index ccb19038..4bc79b53 100644 --- a/account_financial_report_webkit/tests/__init__.py +++ b/account_financial_report_webkit/tests/__init__.py @@ -1,5 +1,10 @@ # -*- coding: utf-8 -*- -# © 2016 Savoir-faire Linux -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import test_account_move_line +from . import test_general_leger +from . import test_partner_ledger +from . import test_trial_balance +from . import test_partner_balance +from . import test_open_invoices +from . import test_aged_open_invoices +from . import test_aged_partner_balance +from . import test_journal diff --git a/account_financial_report_webkit/tests/test_aged_open_invoices.py b/account_financial_report_webkit/tests/test_aged_open_invoices.py new file mode 100644 index 00000000..359361fe --- /dev/null +++ b/account_financial_report_webkit/tests/test_aged_open_invoices.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from datetime import datetime +from .test_common import TestCommon + + +class TestOpenInvoices(TestCommon): + + def _getReportModel(self): + return 'aged.open.invoices.webkit' + + def _getReportName(self): + return 'account.account_aged_open_invoices_webkit' + + def _getBaseFilters(self): + return {'until_date': '%s-12-31' % (datetime.now().year)} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_aged_partner_balance.py b/account_financial_report_webkit/tests/test_aged_partner_balance.py new file mode 100644 index 00000000..96eb7d52 --- /dev/null +++ b/account_financial_report_webkit/tests/test_aged_partner_balance.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestAgedPartnerBalance(TestCommon): + + def _getReportModel(self): + return 'account.aged.trial.balance.webkit' + + def _getReportName(self): + return 'account.account_aged_trial_balance_webkit' + + def _getBaseFilters(self): + fy_id = self.model._get_current_fiscalyear() + vals = self.model.onchange_fiscalyear(fiscalyear=fy_id)['value'] + vals.update({'fiscalyear_id': fy_id}) + return vals + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_common.py b/account_financial_report_webkit/tests/test_common.py new file mode 100644 index 00000000..f005fbd5 --- /dev/null +++ b/account_financial_report_webkit/tests/test_common.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.tests.common import TransactionCase + + +class TestCommon(TransactionCase): + """ Common tests for all reports """ + + def setUp(self): + super(TestCommon, self).setUp() + self.model = self.env[self._getReportModel()] + self.report_name = self._getReportName() + wiz_vals = {'chart_account_id': self.env.ref('account.chart0').id} + wiz_vals.update(self._getBaseFilters()) + self.report = self.model.create(wiz_vals) + + def common_test_01_generation_report(self): + """ Check if report is correctly generated """ + + # Check if returned report action is correct + report_action = self.report.check_report() + self.assertDictContainsSubset( + {'type': 'ir.actions.report.xml', + 'report_name': self.report_name}, + report_action) + + def _getReportModel(self): + """ + :return: the report model name + """ + raise NotImplementedError() + + def _getReportName(self): + """ + :return: the xls report name + """ + raise NotImplementedError() + + def _getBaseFilters(self): + """ + :return: the minimum required filters to generate report + """ + raise NotImplementedError() diff --git a/account_financial_report_webkit/tests/test_general_leger.py b/account_financial_report_webkit/tests/test_general_leger.py new file mode 100644 index 00000000..16f7a720 --- /dev/null +++ b/account_financial_report_webkit/tests/test_general_leger.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestGeneralLedger(TestCommon): + + def _getReportModel(self): + return 'general.ledger.webkit' + + def _getReportName(self): + return 'account.account_report_general_ledger_webkit' + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_journal.py b/account_financial_report_webkit/tests/test_journal.py new file mode 100644 index 00000000..931b161b --- /dev/null +++ b/account_financial_report_webkit/tests/test_journal.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestGeneralLedger(TestCommon): + + def _getReportModel(self): + return 'print.journal.webkit' + + def _getReportName(self): + return 'account.account_report_print_journal_webkit' + + def _getBaseFilters(self): + fy_id = self.model._get_fiscalyear() + vals = self.model.onchange_filter( + filter='filter_period', fiscalyear_id=fy_id)['value'] + vals.update({'fiscalyear_id': fy_id}) + return vals + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_open_invoices.py b/account_financial_report_webkit/tests/test_open_invoices.py new file mode 100644 index 00000000..527a2257 --- /dev/null +++ b/account_financial_report_webkit/tests/test_open_invoices.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from datetime import datetime +from .test_common import TestCommon + + +class TestOpenInvoices(TestCommon): + + def _getReportModel(self): + return 'open.invoices.webkit' + + def _getReportName(self): + return 'account.account_report_open_invoices_webkit' + + def _getBaseFilters(self): + return {'until_date': '%s-12-31' % (datetime.now().year)} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_partner_balance.py b/account_financial_report_webkit/tests/test_partner_balance.py new file mode 100644 index 00000000..1864de41 --- /dev/null +++ b/account_financial_report_webkit/tests/test_partner_balance.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestPartnerBalance(TestCommon): + + def _getReportModel(self): + return 'partner.balance.webkit' + + def _getReportName(self): + return 'account.account_report_partner_balance_webkit' + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_partner_ledger.py b/account_financial_report_webkit/tests/test_partner_ledger.py new file mode 100644 index 00000000..97a050b7 --- /dev/null +++ b/account_financial_report_webkit/tests/test_partner_ledger.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestPartnerLedger(TestCommon): + + def _getReportModel(self): + return 'partners.ledger.webkit' + + def _getReportName(self): + return 'account.account_report_partners_ledger_webkit' + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/tests/test_trial_balance.py b/account_financial_report_webkit/tests/test_trial_balance.py new file mode 100644 index 00000000..19546acb --- /dev/null +++ b/account_financial_report_webkit/tests/test_trial_balance.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common import TestCommon + + +class TestTrialBalance(TestCommon): + + def _getReportModel(self): + return 'trial.balance.webkit' + + def _getReportName(self): + return 'account.account_report_trial_balance_webkit' + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit/wizard/__init__.py b/account_financial_report_webkit/wizard/__init__.py index 341da9a8..cf2b2645 100644 --- a/account_financial_report_webkit/wizard/__init__.py +++ b/account_financial_report_webkit/wizard/__init__.py @@ -1,25 +1,4 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi. Copyright Camptocamp SA -# Copyright (C) 2012 SYLEAM Info Services () -# Sebastien LANGE -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# -*- coding: utf-8 -*- from . import balance_common from . import general_ledger_wizard from . import partners_ledger_wizard @@ -29,3 +8,6 @@ from . import open_invoices_wizard from . import aged_open_invoices_wizard from . import print_journal from . import aged_partner_balance_wizard +# uncomment import infra when running Odoo without +# PR https://github.com/odoo/odoo/pull/14891 +# from . import account_common_report_fix diff --git a/account_financial_report_webkit/wizard/account_common_report_fix.py b/account_financial_report_webkit/wizard/account_common_report_fix.py new file mode 100644 index 00000000..285faabe --- /dev/null +++ b/account_financial_report_webkit/wizard/account_common_report_fix.py @@ -0,0 +1,121 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +""" +Bypass of bug in Odoo: +The financial reports do not work on first and last day of the Fiscal Year. +This fix can be removed after merge of +PR https://github.com/odoo/odoo/pull/14891. +""" +import logging +import time +from openerp import api, fields, models +_logger = logging.getLogger(__name__) + + +class AccountCommonReportFix(object): + + @api.model + def _default_fiscalyear_id(self): + _logger.debug( + '%s, fix cf. PR https://github.com/odoo/odoo/pull/14891', + self._name) + fy_id = super(AccountCommonReportFix, self)._get_fiscalyear() + if fy_id: + return self.env['account.fiscalyear'].browse(fy_id) + + now = time.strftime('%Y-%m-%d') + ids = self._context.get('active_ids', []) + if ids and self._context.get('active_model') == 'account.account': + company = self.env['account.account'].browse(ids[0]) + else: # use current company id + company = self.env.user.company_id + domain = [('company_id', '=', company.id), + ('date_start', '<=', now), ('date_stop', '>=', now)] + return self.env['account.fiscalyear'].search(domain, limit=1) + + def onchange_chart_id(self, cr, uid, ids, + chart_account_id=False, context=None): + _logger.debug( + '%s, fix cf. PR https://github.com/odoo/odoo/pull/14891', + self._name) + res = super(AccountCommonReportFix, self).onchange_chart_id( + cr, uid, ids, chart_account_id=chart_account_id, context=context) + if not res.get('fiscalyear_id'): + if chart_account_id: + company_id = self.pool['account.account'].browse( + cr, uid, chart_account_id, context=context).company_id.id + now = time.strftime('%Y-%m-%d') + domain = [('company_id', '=', company_id), + ('date_start', '<=', now), ('date_stop', '>=', now)] + fiscalyears = self.pool['account.fiscalyear'].search( + cr, uid, domain, limit=1) + res['value'] = { + 'company_id': company_id, + 'fiscalyear_id': fiscalyears and fiscalyears[0] or False, + } + return res + + +class AccountReportGeneralLedgerWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'general.ledger.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AgedOpenInvoice(AccountCommonReportFix, + models.TransientModel): + _inherit = 'aged.open.invoices.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AccountAgedTrialBalance(AccountCommonReportFix, + models.TransientModel): + _inherit = 'account.aged.trial.balance.webkit' + + # no fiscalyear_id in this one since the module has + # its own method for this. + + +class AccountReportOpenInvoicesWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'open.invoices.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AccountPartnerBalanceWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'partner.balance.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AccountReportPartnersLedgerWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'partners.ledger.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AccountReportPrintJournalWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'print.journal.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) + + +class AccountTrialBalanceWizard(AccountCommonReportFix, + models.TransientModel): + _inherit = 'trial.balance.webkit' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id()) diff --git a/account_financial_report_webkit/wizard/aged_partner_balance_wizard.py b/account_financial_report_webkit/wizard/aged_partner_balance_wizard.py index 2275b950..3bce5792 100644 --- a/account_financial_report_webkit/wizard/aged_partner_balance_wizard.py +++ b/account_financial_report_webkit/wizard/aged_partner_balance_wizard.py @@ -1,26 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi -# Copyright 2014 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from datetime import date +# Copyright 2014 Camptocamp SA, Nicolas Bessi. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp.osv import orm, fields -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DATE_FORMAT class AccountAgedTrialBalance(orm.TransientModel): @@ -34,19 +15,7 @@ class AccountAgedTrialBalance(orm.TransientModel): _description = "Aged partner balanced" def _get_current_fiscalyear(self, cr, uid, context=None): - user_obj = self.pool['res.users'] - company = user_obj.browse(cr, uid, uid, context=context).company_id - fyear_obj = self.pool['account.period'] - today = date.today().strftime(DATE_FORMAT) - fyear_ids = fyear_obj.search( - cr, uid, - [('date_start', '>=', today), - ('date_stop', '<=', today), - ('company_id', '=', company.id)], - limit=1, - context=context) - if fyear_ids: - return fyear_ids[0] + return self.pool['account.fiscalyear'].find(cr, uid, context=context) _columns = { 'filter': fields.selection( diff --git a/account_financial_report_webkit_xls/README.rst b/account_financial_report_webkit_xls/README.rst new file mode 100644 index 00000000..deec2ae8 --- /dev/null +++ b/account_financial_report_webkit_xls/README.rst @@ -0,0 +1,64 @@ +.. 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 + +============================== +Financial Reports - XLS Export +============================== + +This module adds XLS export to the following accounting reports: + - General Ledger + - Trial Balance + - Partner Ledger + - Partner Balance + - Aged Partner Balance + - Open Invoices + +Installation +============ + +To install this module, you need also the **report_xls** +module located in: + +https://github.com/OCA/reporting-engine + +Usage +===== + +Use the 'Export' button on the financial report wizards to export the +data in Excel format. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/91/8.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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Noviat + +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_financial_report_webkit_xls/__openerp__.py b/account_financial_report_webkit_xls/__openerp__.py index ff8078d7..292e17f0 100644 --- a/account_financial_report_webkit_xls/__openerp__.py +++ b/account_financial_report_webkit_xls/__openerp__.py @@ -1,22 +1,12 @@ # -*- coding: utf-8 -*- -# Copyright 2009-2016 Noviat. +# Copyright 2009-2017 Noviat. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Add XLS export to accounting reports', - 'version': '8.0.0.5.0', + 'version': '8.0.1.0.0', 'license': 'AGPL-3', 'author': "Noviat,Odoo Community Association (OCA)", 'category': 'Generic Modules/Accounting', - 'description': """ - - This module adds XLS export to the following accounting reports: - - general ledger - - trial balance - - partner ledger - - partner balance - - open invoices - - """, 'depends': ['report_xls', 'account_financial_report_webkit'], 'demo': [], 'data': [ @@ -27,11 +17,11 @@ 'wizard/open_invoices_wizard_view.xml', 'wizard/aged_partner_balance_wizard.xml', ], - 'test': ['tests/general_ledger.yml', - 'tests/partner_ledger.yml', - 'tests/trial_balance.yml', - 'tests/partner_balance.yml', - 'tests/open_invoices.yml'], + 'test': ['test/general_ledger.yml', + 'test/partner_ledger.yml', + 'test/trial_balance.yml', + 'test/partner_balance.yml', + 'test/open_invoices.yml'], 'active': False, 'installable': True, } diff --git a/account_financial_report_webkit_xls/tests/general_ledger.yml b/account_financial_report_webkit_xls/test/general_ledger.yml similarity index 100% rename from account_financial_report_webkit_xls/tests/general_ledger.yml rename to account_financial_report_webkit_xls/test/general_ledger.yml diff --git a/account_financial_report_webkit_xls/tests/open_invoices.yml b/account_financial_report_webkit_xls/test/open_invoices.yml similarity index 100% rename from account_financial_report_webkit_xls/tests/open_invoices.yml rename to account_financial_report_webkit_xls/test/open_invoices.yml diff --git a/account_financial_report_webkit_xls/tests/partner_balance.yml b/account_financial_report_webkit_xls/test/partner_balance.yml similarity index 100% rename from account_financial_report_webkit_xls/tests/partner_balance.yml rename to account_financial_report_webkit_xls/test/partner_balance.yml diff --git a/account_financial_report_webkit_xls/tests/partner_ledger.yml b/account_financial_report_webkit_xls/test/partner_ledger.yml similarity index 100% rename from account_financial_report_webkit_xls/tests/partner_ledger.yml rename to account_financial_report_webkit_xls/test/partner_ledger.yml diff --git a/account_financial_report_webkit_xls/tests/trial_balance.yml b/account_financial_report_webkit_xls/test/trial_balance.yml similarity index 100% rename from account_financial_report_webkit_xls/tests/trial_balance.yml rename to account_financial_report_webkit_xls/test/trial_balance.yml diff --git a/account_financial_report_webkit_xls/tests/__init__.py b/account_financial_report_webkit_xls/tests/__init__.py new file mode 100644 index 00000000..7ebf9166 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +from . import test_general_leger_xls +from . import test_partner_ledger_xls +from . import test_trial_balance_xls +from . import test_partner_balance_xls +from . import test_open_invoices_xls +from . import test_aged_partner_balance_xls diff --git a/account_financial_report_webkit_xls/tests/test_aged_partner_balance_xls.py b/account_financial_report_webkit_xls/tests/test_aged_partner_balance_xls.py new file mode 100644 index 00000000..d05a125f --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_aged_partner_balance_xls.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common_xls import TestCommonXls + + +class TestAgedPartnerBalanceXls(TestCommonXls): + + def _getReportModel(self): + return 'account.aged.trial.balance.webkit' + + def _getXlsReportName(self): + return 'account.account_report_aged_partner_balance_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_aged_trial_blanance_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + fy_id = self.model._get_current_fiscalyear() + vals = self.model.onchange_fiscalyear(fiscalyear=fy_id)['value'] + vals.update({'fiscalyear_id': fy_id}) + return vals + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit_xls/tests/test_common_xls.py b/account_financial_report_webkit_xls/tests/test_common_xls.py new file mode 100644 index 00000000..d8e88004 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_common_xls.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.tests.common import TransactionCase + + +class TestCommonXls(TransactionCase): + """ Common tests for all XLS Exports """ + + def setUp(self): + super(TestCommonXls, self).setUp() + self.model = self.env[self._getReportModel()] + self.xls_report_name = self._getXlsReportName() + ctx = {'xls_export': 1} + self.xls_action_name = self._getXlsReportActionName() + self.xls_action = self.env.ref(self.xls_action_name).with_context(ctx) + wiz_vals = {'chart_account_id': self.env.ref('account.chart0').id} + wiz_vals.update(self._getBaseFilters()) + self.report = self.model.with_context(ctx).create(wiz_vals) + + def common_test_01_action_xls(self): + """ Check if report XLS action is correct """ + report_action = self.report.xls_export() + self.assertDictContainsSubset( + {'type': 'ir.actions.report.xml', + 'report_name': self.xls_report_name}, + report_action) + self.render_dict = report_action['datas'] + + def common_test_02_render_xls(self): + report_xls = self.xls_action.render_report( + self.report.ids, + self.xls_report_name, + self.render_dict) + self.assertGreaterEqual(len(report_xls[0]), 1) + self.assertEqual(report_xls[1], 'xls') + + def _getReportModel(self): + """ + :return: the report model name + """ + raise NotImplementedError() + + def _getXlsReportName(self): + """ + :return: the xls report name + """ + raise NotImplementedError() + + def _getXlsReportActionName(self): + """ + :return: the xls report action name + """ + raise NotImplementedError() + + def _getBaseFilters(self): + """ + :return: the minimum required filters to generate report + """ + raise NotImplementedError() diff --git a/account_financial_report_webkit_xls/tests/test_general_leger_xls.py b/account_financial_report_webkit_xls/tests/test_general_leger_xls.py new file mode 100644 index 00000000..af12a4c6 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_general_leger_xls.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common_xls import TestCommonXls + + +class TestGeneralLedgerXls(TestCommonXls): + + def _getReportModel(self): + return 'general.ledger.webkit' + + def _getXlsReportName(self): + return 'account.account_report_general_ledger_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_general_ledger_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit_xls/tests/test_open_invoices_xls.py b/account_financial_report_webkit_xls/tests/test_open_invoices_xls.py new file mode 100644 index 00000000..d14bbfd7 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_open_invoices_xls.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from datetime import datetime +from .test_common_xls import TestCommonXls + + +class TestOpenInvoicesXls(TestCommonXls): + + def _getReportModel(self): + return 'open.invoices.webkit' + + def _getXlsReportName(self): + return 'account.account_report_open_invoices_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_open_invoices_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + return {'until_date': '%s-12-31' % (datetime.now().year)} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit_xls/tests/test_partner_balance_xls.py b/account_financial_report_webkit_xls/tests/test_partner_balance_xls.py new file mode 100644 index 00000000..d4e2f807 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_partner_balance_xls.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common_xls import TestCommonXls + + +class TestPartnerBalanceXls(TestCommonXls): + + def _getReportModel(self): + return 'partner.balance.webkit' + + def _getXlsReportName(self): + return 'account.account_report_partner_balance_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_partner_balance_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit_xls/tests/test_partner_ledger_xls.py b/account_financial_report_webkit_xls/tests/test_partner_ledger_xls.py new file mode 100644 index 00000000..fbd0d568 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_partner_ledger_xls.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common_xls import TestCommonXls + + +class TestPartnerLedgerXls(TestCommonXls): + + def _getReportModel(self): + return 'partners.ledger.webkit' + + def _getXlsReportName(self): + return 'account.account_report_partner_ledger_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_partners_ledger_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_financial_report_webkit_xls/tests/test_trial_balance_xls.py b/account_financial_report_webkit_xls/tests/test_trial_balance_xls.py new file mode 100644 index 00000000..1b989783 --- /dev/null +++ b/account_financial_report_webkit_xls/tests/test_trial_balance_xls.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from .test_common_xls import TestCommonXls + + +class TestTrialBalanceXls(TestCommonXls): + + def _getReportModel(self): + return 'trial.balance.webkit' + + def _getXlsReportName(self): + return 'account.account_report_trial_balance_xls' + + def _getXlsReportActionName(self): + module = 'account_financial_report_webkit' + action = 'account_report_trial_balance_webkit' + return '%s.%s' % (module, action) + + def _getBaseFilters(self): + return {} + + def test_common(self): + common_tests = [ + x for x in dir(self) + if callable(getattr(self, x)) and x.startswith('common_test_')] + for test in common_tests: + getattr(self, test)() diff --git a/account_journal_report_xls/wizard/__init__.py b/account_journal_report_xls/wizard/__init__.py index 406a7a8f..347f6753 100644 --- a/account_journal_report_xls/wizard/__init__.py +++ b/account_journal_report_xls/wizard/__init__.py @@ -1,23 +1,3 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# -# Copyright (c) 2014 Noviat nv/sa (www.noviat.com). All rights reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# -*- coding: utf-8 -*- from . import print_journal_wizard +from . import account_common_report_fix diff --git a/account_journal_report_xls/wizard/account_common_report_fix.py b/account_journal_report_xls/wizard/account_common_report_fix.py new file mode 100644 index 00000000..e777061d --- /dev/null +++ b/account_journal_report_xls/wizard/account_common_report_fix.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Copyright 2009-2017 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +""" +Bypass of bug in Odoo: +The financial reports do not work on first and last day of the Fiscal Year. +This fix can be removed after merge of +PR https://github.com/odoo/odoo/pull/14891. +""" +import logging +import time +from openerp import api, fields, models +_logger = logging.getLogger(__name__) + + +class AccountCommonReportFix(object): + + @api.model + def _default_fiscalyear_id(self): + _logger.debug( + '%s, fix cf. PR https://github.com/odoo/odoo/pull/14891', + self._name) + fy_id = super(AccountCommonReportFix, self)._get_fiscalyear() + if fy_id: + return self.env['account.fiscalyear'].browse(fy_id) + + now = time.strftime('%Y-%m-%d') + ids = self._context.get('active_ids', []) + if ids and self._context.get('active_model') == 'account.account': + company = self.env['account.account'].browse(ids[0]) + else: # use current company id + company = self.env.user.company_id + domain = [('company_id', '=', company.id), + ('date_start', '<=', now), ('date_stop', '>=', now)] + return self.env['account.fiscalyear'].search(domain, limit=1) + + def onchange_chart_id(self, cr, uid, ids, + chart_account_id=False, context=None): + _logger.debug( + '%s, fix cf. PR https://github.com/odoo/odoo/pull/14891', + self._name) + res = super(AccountCommonReportFix, self).onchange_chart_id( + cr, uid, ids, chart_account_id=chart_account_id, context=context) + if not res.get('fiscalyear_id'): + if chart_account_id: + company_id = self.pool['account.account'].browse( + cr, uid, chart_account_id, context=context).company_id.id + now = time.strftime('%Y-%m-%d') + domain = [('company_id', '=', company_id), + ('date_start', '<=', now), ('date_stop', '>=', now)] + fiscalyears = self.pool['account.fiscalyear'].search( + cr, uid, domain, limit=1) + res['value'] = { + 'company_id': company_id, + 'fiscalyear_id': fiscalyears and fiscalyears[0] or False, + } + return res + + +class AccountPrintJournalXls(AccountCommonReportFix, + models.TransientModel): + _inherit = 'account.print.journal.xls' + + fiscalyear_id = fields.Many2one( + default=lambda self: self._default_fiscalyear_id())