From caa432b137ed757d8aaed78aa24568085e7b8e1a Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Tue, 15 Jan 2013 11:09:22 +0100 Subject: [PATCH 1/4] [ADD] account_cancel_invoice_check_payment : Constraint to not be able to cancel on invoice if already import in payment order --- .../__init__.py | 27 ++++++++++ .../__openerp__.py | 39 +++++++++++++++ .../account_invoice.py | 50 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 account_cancel_invoice_check_payment_order/__init__.py create mode 100644 account_cancel_invoice_check_payment_order/__openerp__.py create mode 100644 account_cancel_invoice_check_payment_order/account_invoice.py diff --git a/account_cancel_invoice_check_payment_order/__init__.py b/account_cancel_invoice_check_payment_order/__init__.py new file mode 100644 index 000000000..2aa5549b3 --- /dev/null +++ b/account_cancel_invoice_check_payment_order/__init__.py @@ -0,0 +1,27 @@ +# -*- 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_payment_order/__openerp__.py b/account_cancel_invoice_check_payment_order/__openerp__.py new file mode 100644 index 000000000..f39dd45d3 --- /dev/null +++ b/account_cancel_invoice_check_payment_order/__openerp__.py @@ -0,0 +1,39 @@ +# -*- 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 payment order", + "version" : "1.0", + "depends" : ["base", "account","account_payment","account_cancel"], + "author" : "CamptoCamp", + "description": """Constraint to not be able to cancel on invoice if already import in payment order + """, + '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_payment_order/account_invoice.py b/account_cancel_invoice_check_payment_order/account_invoice.py new file mode 100644 index 000000000..b93bb3a03 --- /dev/null +++ b/account_cancel_invoice_check_payment_order/account_invoice.py @@ -0,0 +1,50 @@ +# -*- 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, fields + +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 invoice in invoices: + if invoice['move_id']: + ## This invoice have a move line, we search move_line converned by this move + cr.execute("""select (select reference from payment_order where id = order_id) as payment_name, + (select date_done from payment_order where id = order_id) as payment_date, + name from payment_line + where move_line_id in (select id from account_move_line where move_id = %s)""", + (invoice['move_id'][0],)) + payment_orders = cr.dictfetchall() + if payment_orders: + raise osv.except_osv(_('Error !'), _('''Invoice already import in payment \ + order (%s) at %s on line %s''' % + (payment_orders[0]['payment_name'], + payment_orders[0]['payment_date'], + payment_orders[0]['name'],))) + return super(account_invoice,self).action_cancel(cr, uid, ids, *args) + From 639bcf04d72a6482ea20697577adf2a3e10882e7 Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Tue, 15 Jan 2013 17:40:13 +0100 Subject: [PATCH 2/4] [FIX] correction regarding Guewen Baconnier @ Camptocamp comments --- .../__init__.py | 7 +--- .../__openerp__.py | 8 ++--- .../account_invoice.py | 36 +++++++++---------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/account_cancel_invoice_check_payment_order/__init__.py b/account_cancel_invoice_check_payment_order/__init__.py index 2aa5549b3..df03e1a09 100644 --- a/account_cancel_invoice_check_payment_order/__init__.py +++ b/account_cancel_invoice_check_payment_order/__init__.py @@ -1,11 +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 @@ -21,7 +17,6 @@ # 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_payment_order/__openerp__.py b/account_cancel_invoice_check_payment_order/__openerp__.py index f39dd45d3..e195c7bcf 100644 --- a/account_cancel_invoice_check_payment_order/__openerp__.py +++ b/account_cancel_invoice_check_payment_order/__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 @@ -20,12 +17,11 @@ # along with this program. If not, see . # ############################################################################## - { "name" : "Cancel invoice, check on payment order", "version" : "1.0", "depends" : ["base", "account","account_payment","account_cancel"], - "author" : "CamptoCamp", + "author" : "Camptocamp", "description": """Constraint to not be able to cancel on invoice if already import in payment order """, 'website': 'http://www.camptocamp.com', diff --git a/account_cancel_invoice_check_payment_order/account_invoice.py b/account_cancel_invoice_check_payment_order/account_invoice.py index b93bb3a03..520900228 100644 --- a/account_cancel_invoice_check_payment_order/account_invoice.py +++ b/account_cancel_invoice_check_payment_order/account_invoice.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 @@ -21,30 +18,33 @@ # ############################################################################## -from tools.translate import _ -from osv import osv -from openerp.osv.orm import TransientModel, fields +from openerp.tools.translate import _ +from openerp.osv import osv, orm +from openerp.osv.orm import TransientModel -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 invoice in invoices: if invoice['move_id']: - ## This invoice have a move line, we search move_line converned by this move - cr.execute("""select (select reference from payment_order where id = order_id) as payment_name, - (select date_done from payment_order where id = order_id) as payment_date, - name from payment_line - where move_line_id in (select id from account_move_line where move_id = %s)""", + ## This invoice have a move line, we search move_line concerned by this move + cr.execute("""SELECT po.reference as payment_name, + po.date_done as payment_date, + pl.name + FROM payment_line as pl + INNER JOIN payment_order AS po + ON pl.id = order_id + WHERE move_line_id IN (SELECT id FROM account_move_line WHERE move_id = %s)""", (invoice['move_id'][0],)) payment_orders = cr.dictfetchall() if payment_orders: - raise osv.except_osv(_('Error !'), _('''Invoice already import in payment \ - order (%s) at %s on line %s''' % + raise osv.except_osv(_('Error !'), + _("Invoice already import in payment" + "order (%s) at %s on line %s" % (payment_orders[0]['payment_name'], payment_orders[0]['payment_date'], payment_orders[0]['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 3e7da5c393f9c75ab05796533040d799ffed39b9 Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Tue, 15 Jan 2013 17:58:01 +0100 Subject: [PATCH 3/4] [FIX] Correction regarding Nicolas Bessi - Camptocamp comments --- account_cancel_invoice_check_payment_order/__init__.py | 2 +- .../__openerp__.py | 5 +---- .../account_invoice.py | 10 +++++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/account_cancel_invoice_check_payment_order/__init__.py b/account_cancel_invoice_check_payment_order/__init__.py index df03e1a09..bdc0e6ae9 100644 --- a/account_cancel_invoice_check_payment_order/__init__.py +++ b/account_cancel_invoice_check_payment_order/__init__.py @@ -17,6 +17,6 @@ # 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_payment_order/__openerp__.py b/account_cancel_invoice_check_payment_order/__openerp__.py index e195c7bcf..e90273260 100644 --- a/account_cancel_invoice_check_payment_order/__openerp__.py +++ b/account_cancel_invoice_check_payment_order/__openerp__.py @@ -25,10 +25,7 @@ "description": """Constraint to not be able to cancel on invoice if already import in payment order """, 'website': 'http://www.camptocamp.com', - 'init_xml': [], - 'update_xml': [ - ], - 'demo_xml': [], + 'data' : [], 'installable': True, 'active': False, } diff --git a/account_cancel_invoice_check_payment_order/account_invoice.py b/account_cancel_invoice_check_payment_order/account_invoice.py index 520900228..80847edc5 100644 --- a/account_cancel_invoice_check_payment_order/account_invoice.py +++ b/account_cancel_invoice_check_payment_order/account_invoice.py @@ -37,14 +37,14 @@ class account_invoice(orm.TransientModel): FROM payment_line as pl INNER JOIN payment_order AS po ON pl.id = order_id - WHERE move_line_id IN (SELECT id FROM account_move_line WHERE move_id = %s)""", + WHERE move_line_id IN (SELECT id FROM account_move_line WHERE move_id = %s) LIMIT 1""", (invoice['move_id'][0],)) - payment_orders = cr.dictfetchall() + payment_orders = cr.dictfetchone() if payment_orders: raise osv.except_osv(_('Error !'), _("Invoice already import in payment" "order (%s) at %s on line %s" % - (payment_orders[0]['payment_name'], - payment_orders[0]['payment_date'], - payment_orders[0]['name'],))) + (payment_orders['payment_name'], + payment_orders['payment_date'], + payment_orders['name'],))) return super(account_invoice,self).action_cancel(cr, uid, ids, *args) \ No newline at end of file From 8b11928e354875a621f3a98a9d27d23d9d51261c Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 28 Jan 2013 10:26:24 +0100 Subject: [PATCH 4/4] [FIX] indentation, phrasing, unused import, trailing whitespaces --- .../__openerp__.py | 9 +++-- .../account_invoice.py | 34 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/account_cancel_invoice_check_payment_order/__openerp__.py b/account_cancel_invoice_check_payment_order/__openerp__.py index e90273260..a0a2b6efe 100644 --- a/account_cancel_invoice_check_payment_order/__openerp__.py +++ b/account_cancel_invoice_check_payment_order/__openerp__.py @@ -20,9 +20,14 @@ { "name" : "Cancel invoice, check on payment order", "version" : "1.0", - "depends" : ["base", "account","account_payment","account_cancel"], + "depends" : ["account", + "account_payment", + "account_cancel" + ], "author" : "Camptocamp", - "description": """Constraint to not be able to cancel on invoice if already import in payment order + "description": """ +Prevents to cancel an invoice which has already been imported in a +payment order. """, 'website': 'http://www.camptocamp.com', 'data' : [], diff --git a/account_cancel_invoice_check_payment_order/account_invoice.py b/account_cancel_invoice_check_payment_order/account_invoice.py index 80847edc5..118de852e 100644 --- a/account_cancel_invoice_check_payment_order/account_invoice.py +++ b/account_cancel_invoice_check_payment_order/account_invoice.py @@ -20,31 +20,35 @@ from openerp.tools.translate import _ from openerp.osv import osv, orm -from openerp.osv.orm import 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 invoice in invoices: if invoice['move_id']: - ## This invoice have a move line, we search move_line concerned by this move + # This invoice have a move line, we search move_line + # concerned by this move cr.execute("""SELECT po.reference as payment_name, po.date_done as payment_date, pl.name - FROM payment_line as pl - INNER JOIN payment_order AS po - ON pl.id = order_id - WHERE move_line_id IN (SELECT id FROM account_move_line WHERE move_id = %s) LIMIT 1""", - (invoice['move_id'][0],)) + FROM payment_line as pl + INNER JOIN payment_order AS po + ON pl.id = order_id + WHERE move_line_id IN (SELECT id + FROM account_move_line + WHERE move_id = %s) + LIMIT 1""", + (invoice['move_id'][0],)) payment_orders = cr.dictfetchone() if payment_orders: - raise osv.except_osv(_('Error !'), - _("Invoice already import in payment" - "order (%s) at %s on line %s" % - (payment_orders['payment_name'], - payment_orders['payment_date'], - payment_orders['name'],))) - return super(account_invoice,self).action_cancel(cr, uid, ids, *args) \ No newline at end of file + raise osv.except_osv( + _('Error !'), + _("Invoice already imported in the payment " + "order (%s) at %s on line %s" % + (payment_orders['payment_name'], + payment_orders['payment_date'], + payment_orders['name']))) + return super(account_invoice,self).action_cancel(cr, uid, ids, *args)