[IMP] Add contraint for Payment Order : If a invoice is imported in a payment order, forbid to reset invoice to cancel or draft
bzr revid: joel.grandguillaume@camptocamp.com-20121026122921-fdlrothxta992cd3
This commit is contained in:
parent
6ef3db0a86
commit
19e1d840c4
|
@ -20,12 +20,29 @@
|
|||
##############################################################################
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from tools.translate import _
|
||||
from osv import fields, osv
|
||||
|
||||
class Invoice(osv.osv):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
# 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
|
||||
def action_cancel(self, cr, uid, ids, *args):
|
||||
payment_line_obj = self.pool.get('payment.line')
|
||||
invoices = self.browse(cr, uid, ids)
|
||||
for inv in invoices:
|
||||
inv_mv_lines = map(lambda x: x.id, inv.move_id.line_id)
|
||||
pl_line_ids = payment_line_obj.search(cr, uid, [('move_line_id','in',inv_mv_lines)])
|
||||
if pl_line_ids:
|
||||
pay_line = payment_line_obj.browse(cr,uid,pl_line_ids)
|
||||
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)))
|
||||
result = super(Invoice, self).action_cancel(cr, uid, ids, *args)
|
||||
return result
|
||||
|
||||
def _amount_to_pay(self, cursor, user, ids, name, args, context=None):
|
||||
'''Return the amount still to pay regarding all the payment orders'''
|
||||
if not ids:
|
||||
|
|
Loading…
Reference in New Issue