mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MRG] [ADD] account_default_draft_move module. The purpose is to ensure that all move that are generated by the system, through invoice or bank statement are in draft
This commit is contained in:
23
account_default_draft_move/__init__.py
Normal file
23
account_default_draft_move/__init__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author Vincent Renaville. 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
|
||||
# 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 . import account
|
||||
from . import account_bank_statement
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
55
account_default_draft_move/__openerp__.py
Normal file
55
account_default_draft_move/__openerp__.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# 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
|
||||
# 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/>.
|
||||
##############################################################################
|
||||
{
|
||||
"name" : "Move in draft state by default",
|
||||
"version" : "1.0",
|
||||
"depends" : ["base", "account", "account_constraints"],
|
||||
"author" : "Camptocamp",
|
||||
'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
|
||||
http://apps.openerp.com) and you'll get closely the same feature as
|
||||
account_cancel, but with the 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' : [],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
54
account_default_draft_move/account.py
Normal file
54
account_default_draft_move/account.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# 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
|
||||
# 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 fields, orm, osv
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class AccountInvoice(orm.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
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')
|
||||
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
|
||||
|
||||
class AccountMove(orm.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context=None):
|
||||
""" We rewrite function button_cancel, to allow invoice or bank statement with linked draft moved
|
||||
to be canceled """
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.state == 'draft':
|
||||
continue
|
||||
else:
|
||||
if not line.journal_id.update_posted:
|
||||
raise osv.except_osv(_('Error!'), _('You cannot modify a posted entry of this journal.\nFirst you should set the journal to allow cancelling entries.'))
|
||||
if ids:
|
||||
cr.execute('UPDATE account_move '\
|
||||
'SET state=%s '\
|
||||
'WHERE id IN %s', ('draft', tuple(ids),))
|
||||
return True
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
50
account_default_draft_move/account_bank_statement.py
Normal file
50
account_default_draft_move/account_bank_statement.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author Vincent Renaville. 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
|
||||
# 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
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
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(AccountBankStatement,self).create_move_from_st_line(
|
||||
cr, uid, st_line_id, company_currency_id,
|
||||
st_line_number, context)
|
||||
# If a bank statement line is already linked to a voucher
|
||||
# we received boolean instead of voucher move ids in move_ids
|
||||
bank_st_line_obj = self.pool.get('account.bank.statement.line')
|
||||
voucher_obj = self.pool.get('account.voucher')
|
||||
st_line = bank_st_line_obj.browse(cr, uid, st_line_id, context=context)
|
||||
if st_line.voucher_id:
|
||||
v = voucher_obj.browse(cr, uid, st_line.voucher_id.id, context=context)
|
||||
move_ids = v.move_id.id
|
||||
|
||||
if not isinstance(move_ids, (tuple, list)):
|
||||
move_ids = [move_ids]
|
||||
# We receive the move created for the bank statement, we set it
|
||||
# to draft
|
||||
if move_ids:
|
||||
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:
|
||||
27
account_default_draft_move/i18n/en.po
Normal file
27
account_default_draft_move/i18n/en.po
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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"
|
||||
|
||||
Reference in New Issue
Block a user