From afe5a0e2852f1ba94e079f1dfd4bbab92b2ea25e Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Tue, 30 Jun 2015 10:48:25 +0200 Subject: [PATCH] Add a configuration parameter to use entry_posted journal setting. Add update_posted in journal items to display or not the button cancel. --- account_default_draft_move/__init__.py | 1 + account_default_draft_move/__openerp__.py | 5 +- account_default_draft_move/account.py | 30 ++++++- .../account_bank_statement.py | 10 +++ account_default_draft_move/account_view.xml | 7 +- .../i18n/account_default_draft_move.pot | 18 ++++- account_default_draft_move/i18n/en.po | 15 +++- account_default_draft_move/i18n/fr.po | 15 +++- account_default_draft_move/res_config.py | 55 +++++++++++++ .../res_config_view.xml | 20 +++++ account_default_draft_move/tests/__init__.py | 12 +-- .../tests/test_account_default_draft_move.py | 80 +++++++++++++++---- 12 files changed, 231 insertions(+), 37 deletions(-) create mode 100644 account_default_draft_move/res_config.py create mode 100644 account_default_draft_move/res_config_view.xml diff --git a/account_default_draft_move/__init__.py b/account_default_draft_move/__init__.py index 3593dc32f..09e765e7e 100644 --- a/account_default_draft_move/__init__.py +++ b/account_default_draft_move/__init__.py @@ -19,3 +19,4 @@ ############################################################################## from . import account from . import account_bank_statement +from . import res_config diff --git a/account_default_draft_move/__openerp__.py b/account_default_draft_move/__openerp__.py index 40dbdbde3..90e055d86 100644 --- a/account_default_draft_move/__openerp__.py +++ b/account_default_draft_move/__openerp__.py @@ -50,8 +50,9 @@ need to make a refund). """, 'website': 'http://www.camptocamp.com', 'data': ['account_view.xml', - 'invoice_view.xml'], + 'invoice_view.xml', + 'res_config_view.xml', + ], 'installable': True, 'auto_install': False, } -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_default_draft_move/account.py b/account_default_draft_move/account.py index a8e5e377b..a8f68a5fd 100644 --- a/account_default_draft_move/account.py +++ b/account_default_draft_move/account.py @@ -17,7 +17,8 @@ # along with this program. If not, see . ############################################################################## -from openerp import models, api, exceptions, _ +from openerp import models, api, fields, exceptions, _ +from openerp.tools.safe_eval import safe_eval class AccountInvoice(models.Model): @@ -27,8 +28,13 @@ class AccountInvoice(models.Model): def action_move_create(self): """Set move line in draft state after creating them.""" res = super(AccountInvoice, self).action_move_create() + use_journal_setting = safe_eval(self.env['ir.config_parameter']. + get_param('use_journal_setting', + default="False")) for inv in self: if inv.move_id: + if use_journal_setting and inv.move_id.journal_id.entry_posted: + continue inv.move_id.state = 'draft' return res @@ -55,3 +61,25 @@ class AccountMove(models.Model): 'SET state=%s ' 'WHERE id IN %s', ('draft', tuple(self.ids))) return True + + @api.multi + def _is_update_posted(self): + ir_module = self.env['ir.module.module'] + can_cancel = ir_module.search([('name', '=', 'account_cancel'), + ('state', '=', 'installed')]) + for move in self: + move.update_posted = can_cancel and move.journal_id.update_posted + + update_posted = fields.Boolean(compute='_is_update_posted', + string='Allow Cancelling Entries') + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + # update help of entry_posted flag + entry_posted = fields.Boolean( + string='Skip \'Draft\' State', + help="""Check this box if you don't want new journal entries +to pass through the 'draft' state and instead goes directly +to the 'posted state' without any manual validation.""") diff --git a/account_default_draft_move/account_bank_statement.py b/account_default_draft_move/account_bank_statement.py index c5e03b40f..f0c67ebc1 100644 --- a/account_default_draft_move/account_bank_statement.py +++ b/account_default_draft_move/account_bank_statement.py @@ -18,6 +18,7 @@ ############################################################################## from openerp import models, api +from openerp.tools.safe_eval import safe_eval class AccountBankStatement(models.Model): @@ -27,5 +28,14 @@ class AccountBankStatement(models.Model): def button_confirm_bank(self): res = super(AccountBankStatement, self).button_confirm_bank() entries = self.mapped('line_ids.journal_entry_id') + use_journal_setting = safe_eval(self.env['ir.config_parameter']. + get_param('use_journal_setting', + default="False")) + if use_journal_setting: + new_entries = self.env['account.move'] + for e in entries: + if not e.journal_id.entry_posted: + new_entries += e + entries = new_entries entries.write({'state': 'draft'}) return res diff --git a/account_default_draft_move/account_view.xml b/account_default_draft_move/account_view.xml index 0092b298f..1351b584a 100644 --- a/account_default_draft_move/account_view.xml +++ b/account_default_draft_move/account_view.xml @@ -8,7 +8,12 @@ + diff --git a/account_default_draft_move/i18n/account_default_draft_move.pot b/account_default_draft_move/i18n/account_default_draft_move.pot index c9f641c37..4b52f8296 100644 --- a/account_default_draft_move/i18n/account_default_draft_move.pot +++ b/account_default_draft_move/i18n/account_default_draft_move.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-10-18 17:48+0000\n" -"PO-Revision-Date: 2013-10-18 17:48+0000\n" +"POT-Creation-Date: 2015-02-19 10:15+0000\n" +"PO-Revision-Date: 2015-02-19 10:15+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -31,7 +31,7 @@ msgid "Bank Statement" msgstr "" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:59 #, python-format msgid "Error!" msgstr "" @@ -42,9 +42,19 @@ msgid "Invoice" msgstr "" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:60 #, python-format msgid "You cannot modify a posted entry of this journal.\n" "First you should set the journal to allow cancelling entries." msgstr "" +#. module: account_default_draft_move +#: model:ir.model,name:account_default_draft_move.model_account_config_settings +msgid "account.config.settings" +msgstr "" + +#. module: account_default_draft_move +#: field:account.config.settings,use_journal_setting:0 +#: model:ir.model.fields,field_description:account_default_draft_move.field_account_config_settings_use_journal_setting +msgid "Use journal setting to post journal entries on invoice and bank statement validation" +msgstr "" diff --git a/account_default_draft_move/i18n/en.po b/account_default_draft_move/i18n/en.po index e744754ae..3c1175659 100644 --- a/account_default_draft_move/i18n/en.po +++ b/account_default_draft_move/i18n/en.po @@ -33,7 +33,7 @@ msgid "Bank Statement" msgstr "Bank Statement" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:59 #, python-format msgid "Error!" msgstr "" @@ -44,9 +44,20 @@ msgid "Invoice" msgstr "" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:60 #, python-format msgid "" "You cannot modify a posted entry of this journal.\n" "First you should set the journal to allow cancelling entries." msgstr "" + +#. module: account_default_draft_move +#: model:ir.model,name:account_default_draft_move.model_account_config_settings +msgid "account.config.settings" +msgstr "" + +#. module: account_default_draft_move +#: field:account.config.settings,use_journal_setting:0 +#: model:ir.model.fields,field_description:account_default_draft_move.field_account_config_settings_use_journal_setting +msgid "Use journal setting to post journal entries on invoice and bank statement validation" +msgstr "" diff --git a/account_default_draft_move/i18n/fr.po b/account_default_draft_move/i18n/fr.po index 1f24069d7..29fc58fb8 100644 --- a/account_default_draft_move/i18n/fr.po +++ b/account_default_draft_move/i18n/fr.po @@ -33,7 +33,7 @@ msgid "Bank Statement" msgstr "Relevé bancaire" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:59 #, python-format msgid "Error!" msgstr "" @@ -44,9 +44,20 @@ msgid "Invoice" msgstr "Facture" #. module: account_default_draft_move -#: code:addons/account_default_draft_move/account.py:47 +#: code:addons/account_default_draft_move/account.py:60 #, python-format msgid "" "You cannot modify a posted entry of this journal.\n" "First you should set the journal to allow cancelling entries." msgstr "" + +#. module: account_default_draft_move +#: model:ir.model,name:account_default_draft_move.model_account_config_settings +msgid "account.config.settings" +msgstr "" + +#. module: account_default_draft_move +#: field:account.config.settings,use_journal_setting:0 +#: model:ir.model.fields,field_description:account_default_draft_move.field_account_config_settings_use_journal_setting +msgid "Use journal setting to post journal entries on invoice and bank statement validation" +msgstr "Utiliser les paramètres du journal pour comptabiliser les pièces comptables lièes aux factures et aux extraits bancaires" diff --git a/account_default_draft_move/res_config.py b/account_default_draft_move/res_config.py new file mode 100644 index 000000000..b5b8f4005 --- /dev/null +++ b/account_default_draft_move/res_config.py @@ -0,0 +1,55 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# Copyright (c) 2014 ACSONE SA/NV (http://acsone.eu). +# +# 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 openerp.osv import orm, fields + + +class AccountConfigSettings(orm.TransientModel): + _inherit = 'account.config.settings' + + _columns = { + 'use_journal_setting': fields.boolean( + 'Use journal setting to post journal entries ' + 'on invoice and bank statement validation',), + } + + def set_parameters(self, cr, uid, ids, context=None): + config = self.browse(cr, uid, ids[0], context) + config_pool = self.pool['ir.config_parameter'] + if config.use_journal_setting: + config_pool.set_param(cr, uid, 'use_journal_setting', + config.use_journal_setting) + else: + # remove the key from parameter + ids = config_pool.search(cr, uid, + [('key', '=', 'use_journal_setting')], + context=context) + if ids: + config_pool.unlink(cr, uid, ids) + + def default_get(self, cr, uid, fields, context=None): + res = super(AccountConfigSettings, self).default_get(cr, uid, fields, + context=context) + config_pool = self.pool['ir.config_parameter'] + res['use_journal_setting'] = config_pool.get_param( + cr, uid, 'use_journal_setting', False) + return res diff --git a/account_default_draft_move/res_config_view.xml b/account_default_draft_move/res_config_view.xml new file mode 100644 index 000000000..e0d096e02 --- /dev/null +++ b/account_default_draft_move/res_config_view.xml @@ -0,0 +1,20 @@ + + + + + + account.config.settings.inherit + + account.config.settings + +
+
+ +
+
+
+
+ +
+
diff --git a/account_default_draft_move/tests/__init__.py b/account_default_draft_move/tests/__init__.py index 53f5739fb..a17f55bf1 100644 --- a/account_default_draft_move/tests/__init__.py +++ b/account_default_draft_move/tests/__init__.py @@ -1,16 +1,8 @@ # -*- coding: utf-8 -*- -# +############################################################################## # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,6 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -# +############################################################################## from . import test_account_default_draft_move diff --git a/account_default_draft_move/tests/test_account_default_draft_move.py b/account_default_draft_move/tests/test_account_default_draft_move.py index aa0bbab8f..500480065 100644 --- a/account_default_draft_move/tests/test_account_default_draft_move.py +++ b/account_default_draft_move/tests/test_account_default_draft_move.py @@ -1,16 +1,8 @@ # -*- coding: utf-8 -*- +############################################################################## # -# -# Authors: Adrien Peiffer +# Authors: Adrien Peiffer, Laetitia Gangloff # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,13 +17,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -# +############################################################################## import openerp.tests.common as common from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT from openerp import workflow +import time + def create_simple_invoice(self): partner_id = self.ref('base.res_partner_2') @@ -58,13 +52,69 @@ def create_simple_invoice(self): }) +def create_simple_bank_statement(self): + return self.env['account.bank.statement'].create({ + 'journal_id': self.ref("account.bank_journal"), + 'date': time.strftime('%Y') + '-07-15', + 'balance_end_real': 42, + 'line_ids': [(0, 0, {'name': 'my payment', + 'partner_id': self.ref('base.res_partner_2'), + 'amount': 42, + 'date': time.strftime('%Y') + '-07-15', + 'account_id': self.ref('account.bnk') + })] + }) + + class TestAccountDefaultDraftMove(common.TransactionCase): def setUp(self): super(TestAccountDefaultDraftMove, self).setUp() def test_draft_move_invoice(self): - invoice = create_simple_invoice(self) - workflow.trg_validate(self.uid, 'account.invoice', invoice.id, - 'invoice_open', self.cr) - self.assertEqual(invoice.move_id.state, 'draft', 'State error!') + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + self.assertEqual(invoice.move_id.state, 'draft', 'State error!') + + def test_draft_move_statement(self): + statement = create_simple_bank_statement(self) + statement.button_confirm_bank() + self.assertEqual(statement.move_line_ids[0].move_id.state, + 'draft', 'State error!') + + def test_config_move_invoice(self): + # update configuration to take account of the journal settings + self.env['ir.config_parameter'].set_param('use_journal_setting', True) + # set entry posted to False + journal = self.env['account.journal'].browse( + self.ref('account.sales_journal')) + journal.entry_posted = False + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + self.assertEqual(invoice.move_id.state, 'draft', 'State error!') + + journal.entry_posted = True + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + self.assertEqual(invoice.move_id.state, 'posted', 'State error!') + + def test_config_move_statement(self): + # update configuration to take account of the journal settings + self.env['ir.config_parameter'].set_param('use_journal_setting', True) + # set entry posted to False + journal = self.env['account.journal'].browse( + self.ref('account.bank_journal')) + journal.entry_posted = False + statement = create_simple_bank_statement(self) + statement.button_confirm_bank() + self.assertEqual(statement.move_line_ids[0].move_id.state, + 'draft', 'State error!') + + journal.entry_posted = True + statement = create_simple_bank_statement(self) + statement.button_confirm_bank() + self.assertEqual(statement.move_line_ids[0].move_id.state, + 'posted', 'State error!')