Add a configuration parameter to use entry_posted journal setting. Add update_posted in journal items to display or not the button cancel.

This commit is contained in:
Laetitia Gangloff
2015-06-30 10:48:25 +02:00
committed by Stéphane Bidoul
parent 48385fbfeb
commit afe5a0e285
12 changed files with 231 additions and 37 deletions

View File

@@ -19,3 +19,4 @@
##############################################################################
from . import account
from . import account_bank_statement
from . import res_config

View File

@@ -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:

View File

@@ -17,7 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
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.""")

View File

@@ -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

View File

@@ -8,7 +8,12 @@
<field name="arch" type="xml">
<data>
<button name="button_validate" position="replace"/>
<button name="button_cancel" position="replace"/>
<button name="button_cancel" position="after">
<field name="update_posted" invisible="1"/>
</button>
<button name="button_cancel" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('update_posted', '=', False)]}</attribute>
</button>
</data>
</field>
</record>

View File

@@ -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 ""

View File

@@ -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 ""

View File

@@ -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"

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_account_config_settings" model="ir.ui.view">
<field name="name">account.config.settings.inherit</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="model">account.config.settings</field>
<field name="arch" type="xml">
<div name="account_config" position="inside">
<div>
<field name="use_journal_setting" class="oe_inline"/>
<label for="use_journal_setting"/>
</div>
</div>
</field>
</record>
</data>
</openerp>

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
#
##############################################################################
from . import test_account_default_draft_move

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
#
##############################################################################
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!')