From caa432b137ed757d8aaed78aa24568085e7b8e1a Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Tue, 15 Jan 2013 11:09:22 +0100 Subject: [PATCH] [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) +