~camptocamp/account-financial-tools/credit_control_report_improvement_vre

« back to all changes in this revision

Viewing changes to account_cancel_invoice_check_voucher/account_invoice.py

  • Committer: Vincent Renaville
  • Date: 2013-01-15 13:41:33 UTC
  • mto: This revision was merged to the branch mainline in revision 106.
  • Revision ID: vincent.renaville@camptocamp.com-20130115134133-n4ejy89lrm6mj13g
[ADD] account_cancel_invoice_check_voucher : ontraint to not be able to cancel an invoice already import in bank statement with a voucher

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2012 Camptocamp (http://www.camptocamp.com) 
 
5
# All Right Reserved
 
6
#
 
7
# Author : Vincent Renaville (Camptocamp)
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU Affero General Public License as
 
11
#    published by the Free Software Foundation, either version 3 of the
 
12
#    License, or (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU Affero General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU Affero General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from tools.translate import _
 
25
from osv import osv
 
26
from openerp.osv.orm import TransientModel
 
27
 
 
28
class account_invoice(TransientModel):
 
29
    _inherit = "account.invoice"
 
30
    
 
31
    def action_cancel(self, cr, uid, ids, *args):
 
32
        ### 
 
33
        invoices = self.read(cr, uid, ids, ['move_id', 'payment_ids'])
 
34
        for i in invoices:
 
35
            if i['move_id']:
 
36
                ## This invoice have a move line, we search move_line converned by this move
 
37
                cr.execute("""select (select name from account_bank_statement where id = statement_id) as statement_name, 
 
38
                    ((select date from account_bank_statement where id = statement_id)) as statement_date, 
 
39
                    name from account_bank_statement_line where voucher_id in 
 
40
                    ( select voucher_id from account_voucher_line where move_line_id in (
 
41
                    select id from account_move_line where move_id = %s ))""", (i['move_id'][0],))
 
42
                statement_lines = cr.dictfetchall()
 
43
                if statement_lines:
 
44
                    raise osv.except_osv(_('Error !'), 
 
45
                                         _('Invoice already import in bank statment (%s) at %s on line %s'
 
46
                                            % (statement_lines[0]['statement_name'],
 
47
                                               statement_lines[0]['statement_date'],
 
48
                                               statement_lines[0]['name'],)))
 
49
 
 
50
        
 
51
        
 
52
        return super(account_invoice,self).action_cancel(cr, uid, ids, *args)