[IMP] Change the way moves are set to draft after invoice validation -> Use the same philosophy than in bank-statement rather than using the post method.

[DEL] Remove the po file as they are empty.
[DOC] Add a clearer description in the module
This commit is contained in:
Joel Grand-Guillaume
2013-01-21 15:32:40 +01:00
parent 6d75a71721
commit 7bb515c38e
6 changed files with 43 additions and 126 deletions

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Vincent Renaville. Copyright 2012 Camptocamp SA
# Author Vincent Renaville/Joel Grand-Guillaume. Copyright 2012 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
@@ -15,14 +15,35 @@
#
# 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/>.
#
##############################################################################
{
"name" : "Move in draft state by default",
"version" : "1.0",
"depends" : ["base", "account"],
"depends" : ["base", "account", "account_constraints"],
"author" : "Camptocamp",
"description": """Let move in draft on invoice and bank statement
'license': 'AGPL-3',
"description": """
Let the generated move in draft on invoice and bank statement validation. The main reason
is to ease the user work day-to-day. At first we used account_cancel, but this module allow
to cancel posted move and that's not allowed.
Two needs here:
- We want to be able to cancel an invoice (as soon as move are not validated) without
making a refund. Posted move can't be canceled.
- We want to ensure all move generated from bank statement and invoice are generated in
draft so we can still change them if needed.
Use this module with account_constraints (find it here : https://launchpad.net/account-financial-tools
or in apps.openerp.com) and you'll get closely the same feature as account_cancel,
but with th insurance that user won't change posted move.
The new framework will then be: always work with draft moves, allowing people to change what
they want. At the end of the period, validate all moves. Till there, you ensure no-one can change
something (or they'll need to make a refund).
""",
'website': 'http://www.camptocamp.com',
'data' : [],

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Vincent Renaville. Copyright 2012 Camptocamp SA
# Author Vincent Renaville/Joel Grand-Guillaume. Copyright 2012 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
@@ -15,46 +15,22 @@
#
# 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 fields, orm, osv
from tools.translate import _
class account_move(orm.Model):
_inherit = "account.move"
class AccountInvoice(orm.Model):
_inherit = 'account.invoice'
def post(self, cr, uid, ids, context=None):
return_value = super(account_move,self).post(cr, uid, ids, context)
if return_value:
invoice = context.get('invoice', False)
## We test if the move is related to an invoice in order to post it with draft status
if invoice:
valid_moves = self.validate(cr, uid, ids, context)
if not valid_moves:
raise osv.except_osv(_('Integrity Error'), _('''You can not validate a non-balanced entry.\n \
Make sure you have configured payment terms properly.\n \
The latest payment term line should be of the type "Balance".'''))
def action_move_create(self, cr, uid, ids, context=None):
"""Set move line in draft state after creating them."""
res = super(AccountInvoice,self).action_move_create(cr, uid, ids, context=context)
move_obj = self.pool.get('account.move')
move_obj.write(cr, uid, valid_moves, {'state': 'draft'}, context=context)
for inv in self.browse(cr, uid, ids, context=context):
if inv.move_id:
move_obj.write(cr, uid, [inv.move_id.id], {'state': 'draft'}, context=context)
return res
cr.execute('UPDATE account_move '\
'SET state=%s '\
'WHERE id IN %s',
('draft', tuple(valid_moves),))
return return_value
def button_cancel(self, cr, uid, ids, context=None):
for line in self.browse(cr, uid, ids, context=context):
if line.period_id.state == 'done':
raise osv.except_osv(_('Error'), _('You can not modify a posted entry of closed periods'))
## Change the test of line state instead of journal type
elif line.state == 'posted':
raise osv.except_osv(_('Error'), _('''You can not modify a posted entry of this journal.\n \
You should set the journal to allow cancelling entries if you want to do that.'''))
if ids:
move_obj = self.pool.get('account.move')
move_obj.write(cr, uid, ids, {'state': 'draft'}, context=context)
return True
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -15,18 +15,18 @@
#
# 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 fields, orm
from tools.translate import _
class account_bank_statement(orm.Model):
class AccountBankStatement(orm.Model):
_inherit = "account.bank.statement"
def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None):
move_ids = super(account_bank_statement,self).create_move_from_st_line(cr, uid, st_line_id,
def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id,
st_line_number, context=None):
move_ids = super(AccountBankStatement,self).create_move_from_st_line(cr, uid, st_line_id,
company_currency_id,
st_line_number, context)
## We receive the move created for the bank statement, we set it to draft
@@ -34,4 +34,5 @@ class account_bank_statement(orm.Model):
move_obj = self.pool.get('account.move')
move_obj.write(cr, uid, move_ids, {'state': 'draft'}, context=context)
return move_ids
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -1,27 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_default_draft_move
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-14 10:36+0000\n"
"PO-Revision-Date: 2013-01-14 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_move
msgid "Account Entry"
msgstr "Account Entry"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_bank_statement
msgid "Bank Statement"
msgstr "Bank Statement"

View File

@@ -1,27 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_default_draft_move
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-14 10:36+0000\n"
"PO-Revision-Date: 2013-01-14 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_move
msgid "Account Entry"
msgstr "Account Entry"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_bank_statement
msgid "Bank Statement"
msgstr "Bank Statement"

View File

@@ -1,27 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_default_draft_move
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-14 10:36+0000\n"
"PO-Revision-Date: 2013-01-14 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_move
msgid "Account Entry"
msgstr "Account Entry"
#. module: account_default_draft_move
#: model:ir.model,name:account_default_draft_move.model_account_bank_statement
msgid "Bank Statement"
msgstr "Bank Statement"