2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2007-11-27 15:43:44 +00:00
##############################################################################
2010-09-09 07:13:55 +00:00
#
2009-10-14 11:15:34 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2008-06-16 11:00:21 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# 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.
2007-11-27 15:43:44 +00:00
#
2008-11-03 19:18:56 +00:00
# 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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2007-11-27 15:43:44 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-09-09 07:13:55 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2007-11-27 15:43:44 +00:00
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp . tools . translate import _
2013-03-18 12:27:48 +00:00
from openerp . osv import osv
2010-09-09 07:13:55 +00:00
2007-11-27 15:43:44 +00:00
class Invoice ( osv . osv ) :
2008-07-22 15:11:28 +00:00
_inherit = ' account.invoice '
2007-11-27 15:43:44 +00:00
2012-10-26 12:29:21 +00:00
# Forbid to cancel an invoice if the related move lines have already been
# used in a payment order. The risk is that importing the payment line
# in the bank statement will result in a crash cause no more move will
# be found in the payment line
2012-11-22 14:28:19 +00:00
def action_cancel ( self , cr , uid , ids , context = None ) :
2012-10-26 12:29:21 +00:00
payment_line_obj = self . pool . get ( ' payment.line ' )
2012-11-22 14:28:19 +00:00
for inv in self . browse ( cr , uid , ids , context = context ) :
2012-11-27 10:24:42 +00:00
pl_line_ids = [ ]
2012-11-26 09:52:27 +00:00
if inv . move_id and inv . move_id . line_id :
inv_mv_lines = [ x . id for x in inv . move_id . line_id ]
pl_line_ids = payment_line_obj . search ( cr , uid , [ ( ' move_line_id ' , ' in ' , inv_mv_lines ) ] , context = context )
2012-10-26 12:29:21 +00:00
if pl_line_ids :
2012-11-22 14:28:19 +00:00
pay_line = payment_line_obj . browse ( cr , uid , pl_line_ids , context = context )
2012-10-26 12:29:21 +00:00
payment_order_name = ' , ' . join ( map ( lambda x : x . order_id . reference , pay_line ) )
raise osv . except_osv ( _ ( ' Error! ' ) , _ ( " You cannot cancel an invoice which has already been imported in a payment order. Remove it from the following payment order : %s . " % ( payment_order_name ) ) )
2012-11-22 14:28:19 +00:00
return super ( Invoice , self ) . action_cancel ( cr , uid , ids , context = context )
2012-10-26 12:29:21 +00:00
2008-07-23 14:41:47 +00:00
2012-03-05 18:40:03 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: