From b4854c09d876640289be5f7b00da2666d402e54d Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Tue, 15 Jan 2013 14:41:33 +0100 Subject: [PATCH 1/4] [ADD] account_cancel_invoice_check_voucher : ontraint to not be able to cancel an invoice already import in bank statement with a voucher --- .../__init__.py | 25 +++++++++ .../__openerp__.py | 38 ++++++++++++++ .../account_invoice.py | 52 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 account_cancel_invoice_check_voucher/__init__.py create mode 100644 account_cancel_invoice_check_voucher/__openerp__.py create mode 100644 account_cancel_invoice_check_voucher/account_invoice.py diff --git a/account_cancel_invoice_check_voucher/__init__.py b/account_cancel_invoice_check_voucher/__init__.py new file mode 100644 index 000000000..765843d26 --- /dev/null +++ b/account_cancel_invoice_check_voucher/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) +# All Right Reserved +# +# Author : Vincent Renaville (Camptocamp) +# +# 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 account_invoice +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/account_cancel_invoice_check_voucher/__openerp__.py b/account_cancel_invoice_check_voucher/__openerp__.py new file mode 100644 index 000000000..d9c4d9615 --- /dev/null +++ b/account_cancel_invoice_check_voucher/__openerp__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) +# All Right Reserved +# +# Author : Vincent Renaville (Camptocamp) +# +# 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 . +# +############################################################################## +{ + "name" : "Cancel invoice, check on bank statement", + "version" : "1.0", + "depends" : ["base", "account","account_voucher","account_cancel"], + "author" : "CamptoCamp", + "description": """Contraint to not be able to cancel an invoice already import in bank statement with a voucher + """, + 'website': 'http://www.camptocamp.com', + 'init_xml': [], + 'update_xml': [ + ], + 'demo_xml': [], + 'installable': True, + 'active': False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_cancel_invoice_check_voucher/account_invoice.py b/account_cancel_invoice_check_voucher/account_invoice.py new file mode 100644 index 000000000..23ba03a2c --- /dev/null +++ b/account_cancel_invoice_check_voucher/account_invoice.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) +# All Right Reserved +# +# Author : Vincent Renaville (Camptocamp) +# +# 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 tools.translate import _ +from osv import osv +from openerp.osv.orm import TransientModel + +class account_invoice(TransientModel): + _inherit = "account.invoice" + + def action_cancel(self, cr, uid, ids, *args): + ### + invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids']) + for i in invoices: + if i['move_id']: + ## This invoice have a move line, we search move_line converned by this move + cr.execute("""select (select name from account_bank_statement where id = statement_id) as statement_name, + ((select date from account_bank_statement where id = statement_id)) as statement_date, + name from account_bank_statement_line where voucher_id in + ( select voucher_id from account_voucher_line where move_line_id in ( + select id from account_move_line where move_id = %s ))""", (i['move_id'][0],)) + statement_lines = cr.dictfetchall() + if statement_lines: + raise osv.except_osv(_('Error !'), + _('Invoice already import in bank statment (%s) at %s on line %s' + % (statement_lines[0]['statement_name'], + statement_lines[0]['statement_date'], + statement_lines[0]['name'],))) + + + + return super(account_invoice,self).action_cancel(cr, uid, ids, *args) From 86a8ef2a1a7d25822538bbc9192048a749058cef Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Wed, 16 Jan 2013 10:07:40 +0100 Subject: [PATCH 2/4] [FIX] correction regarding Guewen Baconnier @ Camptocamp comments --- .../__init__.py | 8 ++--- .../__openerp__.py | 12 ++----- .../account_invoice.py | 36 +++++++++---------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/account_cancel_invoice_check_voucher/__init__.py b/account_cancel_invoice_check_voucher/__init__.py index 765843d26..7be6ed351 100644 --- a/account_cancel_invoice_check_voucher/__init__.py +++ b/account_cancel_invoice_check_voucher/__init__.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) -# All Right Reserved -# -# Author : Vincent Renaville (Camptocamp) +# 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 @@ -20,6 +17,7 @@ # along with this program. If not, see . # ############################################################################## -import account_invoice + +from . import account_invoice # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_cancel_invoice_check_voucher/__openerp__.py b/account_cancel_invoice_check_voucher/__openerp__.py index d9c4d9615..2bab98b5d 100644 --- a/account_cancel_invoice_check_voucher/__openerp__.py +++ b/account_cancel_invoice_check_voucher/__openerp__.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) -# All Right Reserved -# -# Author : Vincent Renaville (Camptocamp) +# 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 @@ -24,14 +21,11 @@ "name" : "Cancel invoice, check on bank statement", "version" : "1.0", "depends" : ["base", "account","account_voucher","account_cancel"], - "author" : "CamptoCamp", + "author" : "Camptocamp", "description": """Contraint to not be able to cancel an invoice already import in bank statement with a voucher """, 'website': 'http://www.camptocamp.com', - 'init_xml': [], - 'update_xml': [ - ], - 'demo_xml': [], + 'date' : [], 'installable': True, 'active': False, } diff --git a/account_cancel_invoice_check_voucher/account_invoice.py b/account_cancel_invoice_check_voucher/account_invoice.py index 23ba03a2c..fa4c8fefc 100644 --- a/account_cancel_invoice_check_voucher/account_invoice.py +++ b/account_cancel_invoice_check_voucher/account_invoice.py @@ -21,32 +21,32 @@ # ############################################################################## -from tools.translate import _ -from osv import osv -from openerp.osv.orm import TransientModel +from openerp.tools.translate import _ +from openerp.osv import osv, orm -class account_invoice(TransientModel): +class account_invoice(orm.TransientModel): _inherit = "account.invoice" def action_cancel(self, cr, uid, ids, *args): - ### invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids']) for i in invoices: if i['move_id']: - ## This invoice have a move line, we search move_line converned by this move - cr.execute("""select (select name from account_bank_statement where id = statement_id) as statement_name, - ((select date from account_bank_statement where id = statement_id)) as statement_date, - name from account_bank_statement_line where voucher_id in - ( select voucher_id from account_voucher_line where move_line_id in ( - select id from account_move_line where move_id = %s ))""", (i['move_id'][0],)) - statement_lines = cr.dictfetchall() + ## This invoice have a move line, we search move_line concerned by this move + cr.execute("""SELECT abs.name as statement_name, + abs.date as statement_date, + absl.name + FROM account_bank_statement_line as absl + INNER JOIN account_bank_statement as abs + ON absl.statement_id = abs.id + WHERE voucher_id in + ( SELECT voucher_id FROM account_voucher_line WHERE move_line_id in + (SELECT id FROM account_move_line WHERE move_id = %s )) limit 1""", (i['move_id'][0],)) + statement_lines = cr.dictfetchone() if statement_lines: raise osv.except_osv(_('Error !'), _('Invoice already import in bank statment (%s) at %s on line %s' - % (statement_lines[0]['statement_name'], - statement_lines[0]['statement_date'], - statement_lines[0]['name'],))) + % (statement_lines['statement_name'], + statement_lines['statement_date'], + statement_lines['name'],))) - - - return super(account_invoice,self).action_cancel(cr, uid, ids, *args) + return super(account_invoice,self).action_cancel(cr, uid, ids, *args) \ No newline at end of file From e3399c948a975e790ffecf1d74cba8a2f536c02e Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 30 Jan 2013 11:26:07 +0100 Subject: [PATCH 3/4] [IMP] a few points: * typos in strings * capitalize all SQL keywords in the query * fixed prototype of action_cancel in 7.0 --- .../__openerp__.py | 8 +++-- .../account_invoice.py | 31 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/account_cancel_invoice_check_voucher/__openerp__.py b/account_cancel_invoice_check_voucher/__openerp__.py index 2bab98b5d..75329fbaf 100644 --- a/account_cancel_invoice_check_voucher/__openerp__.py +++ b/account_cancel_invoice_check_voucher/__openerp__.py @@ -20,9 +20,13 @@ { "name" : "Cancel invoice, check on bank statement", "version" : "1.0", - "depends" : ["base", "account","account_voucher","account_cancel"], + "depends" : ["base", + "account", + "account_voucher", + "account_cancel", + ], "author" : "Camptocamp", - "description": """Contraint to not be able to cancel an invoice already import in bank statement with a voucher + "description": """Constraint forbidding to cancel an invoice already imported in bank statement with a voucher. """, 'website': 'http://www.camptocamp.com', 'date' : [], diff --git a/account_cancel_invoice_check_voucher/account_invoice.py b/account_cancel_invoice_check_voucher/account_invoice.py index fa4c8fefc..faaf69335 100644 --- a/account_cancel_invoice_check_voucher/account_invoice.py +++ b/account_cancel_invoice_check_voucher/account_invoice.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) +# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) # All Right Reserved # # Author : Vincent Renaville (Camptocamp) @@ -26,27 +26,28 @@ from openerp.osv import osv, orm class account_invoice(orm.TransientModel): _inherit = "account.invoice" - - def action_cancel(self, cr, uid, ids, *args): + + def action_cancel(self, cr, uid, ids, context=None): invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids']) - for i in invoices: - if i['move_id']: + for invoice in invoices: + if invoice['move_id']: ## This invoice have a move line, we search move_line concerned by this move - cr.execute("""SELECT abs.name as statement_name, - abs.date as statement_date, + cr.execute("""SELECT abs.name AS statement_name, + abs.date AS statement_date, absl.name - FROM account_bank_statement_line as absl - INNER JOIN account_bank_statement as abs + FROM account_bank_statement_line AS absl + INNER JOIN account_bank_statement AS abs ON absl.statement_id = abs.id - WHERE voucher_id in - ( SELECT voucher_id FROM account_voucher_line WHERE move_line_id in - (SELECT id FROM account_move_line WHERE move_id = %s )) limit 1""", (i['move_id'][0],)) + WHERE voucher_id IN + ( SELECT voucher_id FROM account_voucher_line WHERE move_line_id IN + (SELECT id FROM account_move_line WHERE move_id = %s )) LIMIT 1""", + (invoice['move_id'][0],)) statement_lines = cr.dictfetchone() if statement_lines: - raise osv.except_osv(_('Error !'), - _('Invoice already import in bank statment (%s) at %s on line %s' + raise osv.except_osv(_('Error!'), + _('Invoice already imported in bank statment (%s) at %s on line %s' % (statement_lines['statement_name'], statement_lines['statement_date'], statement_lines['name'],))) - return super(account_invoice,self).action_cancel(cr, uid, ids, *args) \ No newline at end of file + return super(account_invoice,self).action_cancel(cr, uid, ids, context=context) From bc68019ddff296f192d2c17ef31a9b80099d991c Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Mon, 11 Feb 2013 11:00:17 +0100 Subject: [PATCH 4/4] [FIX] improve sql query --- account_cancel_invoice_check_voucher/account_invoice.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/account_cancel_invoice_check_voucher/account_invoice.py b/account_cancel_invoice_check_voucher/account_invoice.py index faaf69335..91112c334 100644 --- a/account_cancel_invoice_check_voucher/account_invoice.py +++ b/account_cancel_invoice_check_voucher/account_invoice.py @@ -38,9 +38,11 @@ class account_invoice(orm.TransientModel): FROM account_bank_statement_line AS absl INNER JOIN account_bank_statement AS abs ON absl.statement_id = abs.id - WHERE voucher_id IN - ( SELECT voucher_id FROM account_voucher_line WHERE move_line_id IN - (SELECT id FROM account_move_line WHERE move_id = %s )) LIMIT 1""", + WHERE EXISTS (SELECT 1 + FROM account_voucher_line JOIN account_move_line ON + (account_voucher_line.move_line_id = account_move_line.id) + WHERE voucher_id=absl.voucher_id + AND account_move_line.move_id = %s )""", (invoice['move_id'][0],)) statement_lines = cr.dictfetchone() if statement_lines: