diff --git a/addons/account/account.py b/addons/account/account.py index ef67005c297..c34ad3ebbbd 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -572,6 +572,7 @@ class account_journal(osv.osv): 'default_credit_account_id': fields.many2one('account.account', 'Default Credit Account', domain="[('type','!=','view')]",help="This will act as a default account for credit amount"), 'default_debit_account_id': fields.many2one('account.account', 'Default Debit Account', domain="[('type','!=','view')]",help="This will act as a default account for debit amount"), 'centralisation': fields.boolean('Centralised counterpart', help="Check this box to determine that each entry of this journal won't create a new counterpart but will share the same counterpart. This is used in fiscal year closing."), + 'update_posted': fields.boolean('Allow Cancelling Entries',help="Check this box if you want to cancel the entries related to this journal or want to cancel the invoice related to this journal"), 'group_invoice_lines': fields.boolean('Group invoice lines', help="If this box is checked, the system will try to group the accounting lines when generating them from invoices."), 'sequence_id': fields.many2one('ir.sequence', 'Entry Sequence', help="The sequence gives the display order for a list of journals", required=True), 'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"), @@ -994,6 +995,14 @@ class account_move(osv.osv): def button_validate(self, cursor, user, ids, context=None): return self.post(cursor, user, ids, context=context) + + def button_cancel(self, cr, uid, ids, context={}): + for line in self.browse(cr, uid, ids, context): + if not line.journal_id.update_posted: + raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.')) + if len(ids): + cr.execute('update account_move set state=%s where id =ANY(%s)',('draft',ids,)) + return True def write(self, cr, uid, ids, vals, context={}): c = context.copy() diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 5c0e8bbb369..c0177068b31 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -317,7 +317,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 7c73232f31f..adfaed67abc 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -923,7 +923,13 @@ class account_invoice(osv.osv): account_move_obj = self.pool.get('account.move') invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids']) for i in invoices: - if i['payment_ids']: + if i['move_id']: + account_move_obj.button_cancel(cr, uid, [i['move_id'][0]]) + # delete the move this invoice was pointing to + # Note that the corresponding move_lines and move_reconciles + # will be automatically deleted too + account_move_obj.unlink(cr, uid, [i['move_id'][0]]) + if i['payment_ids']: account_move_line_obj = self.pool.get('account.move.line') pay_ids = account_move_line_obj.browse(cr, uid , i['payment_ids']) for move_line in pay_ids: diff --git a/addons/account_cancel/__init__.py b/addons/account_cancel/__init__.py index aaaec690ccd..49a09e5570e 100644 --- a/addons/account_cancel/__init__.py +++ b/addons/account_cancel/__init__.py @@ -19,7 +19,5 @@ # ############################################################################## -import account_cancel - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_cancel/__openerp__.py b/addons/account_cancel/__openerp__.py index 226af626ee5..abe40d52fca 100644 --- a/addons/account_cancel/__openerp__.py +++ b/addons/account_cancel/__openerp__.py @@ -26,8 +26,7 @@ "depends" : ["account"], "author" : "Tiny", "category": 'Generic Modules/Accounting', - "description": """account_cancel module covers: - the cancellation of accounting entries and invoices""", + "description": """It covers the cancellation of accounting entries and invoices""", 'website': 'http://www.openerp.com', 'init_xml': [], 'update_xml': ['account_cancel_view.xml' ], diff --git a/addons/account_cancel/account_cancel.py b/addons/account_cancel/account_cancel.py deleted file mode 100644 index bcb0ac693cc..00000000000 --- a/addons/account_cancel/account_cancel.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# 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 . -# -############################################################################## -import time -import netsvc -from osv import fields, osv -from tools.translate import _ - -class account_journal(osv.osv): - _inherit = "account.journal" - _columns = { - 'update_posted': fields.boolean('Allow Cancelling Entries',help="Check this box if you want to cancel the entries related to this journal or want to cancel the invoice related to this journal") - } - -account_journal() - -class account_move(osv.osv): - _inherit = "account.move" - _description = "Account Entry" - - def button_cancel(self, cr, uid, ids, context={}): - for line in self.browse(cr, uid, ids, context): - if not line.journal_id.update_posted: - raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.')) - if len(ids): - cr.execute('update account_move set state=%s where id =ANY(%s)',('draft',ids,)) - return True - -account_move() - -class account_invoice(osv.osv): - _inherit = "account.invoice" - - def action_cancel(self, cr, uid, ids, *args): - account_move_obj = self.pool.get('account.move') - invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids']) - for i in invoices: - if i['move_id']: - account_move_obj.button_cancel(cr, uid, [i['move_id'][0]]) - # delete the move this invoice was pointing to - # Note that the corresponding move_lines and move_reconciles - # will be automatically deleted too - account_move_obj.unlink(cr, uid, [i['move_id'][0]]) - return super(account_invoice, self).action_cancel(cr, uid, ids, *args) - -account_invoice() \ No newline at end of file diff --git a/addons/account_cancel/account_cancel_view.xml b/addons/account_cancel/account_cancel_view.xml index da96beb3c29..82eae01347c 100644 --- a/addons/account_cancel/account_cancel_view.xml +++ b/addons/account_cancel/account_cancel_view.xml @@ -12,17 +12,5 @@ - - - account.move.form - account.move - form - - - -