~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to validate_type_line_invoice/account_invoice.py

  • Committer: Luis Torres
  • Date: 2012-09-14 21:24:31 UTC
  • mto: This revision was merged to the branch mainline in revision 485.
  • Revision ID: luis_t@vauxoo.com-20120914212431-0frhn4z1u818bztt
[ADD][validate_type_line_invoice]Add validation in lines to invoice, for not validate the invoice if type the account is 'payable' or 'receivable'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
 
6
#    All Rights Reserved.
 
7
#    info Vauxoo (info@vauxoo.com)
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
from osv import osv, fields
 
27
from tools.translate import _
 
28
 
 
29
class account_invoice(osv.osv):
 
30
    _inherit = 'account.invoice'
 
31
    
 
32
    def action_move_create(self, cr, uid, ids, context=None):
 
33
        invoice_line_obj=self.pool.get('account.invoice.line')
 
34
        account_obj=self.pool.get('account.account')
 
35
        lines = invoice_line_obj.search(cr,uid,[('invoice_id','=',ids)])
 
36
        ban=0
 
37
        for line in lines:
 
38
            id_account=invoice_line_obj.browse(cr,uid,line).account_id.id
 
39
            type_line=account_obj.browse(cr,uid,id_account).type
 
40
            if type_line == 'receivable' or type_line == 'payable':
 
41
                ban=ban+1
 
42
        if ban==0:
 
43
            res =  super(account_invoice, self).action_move_create(cr, uid, ids)
 
44
        else:
 
45
            raise osv.except_osv(_('Error'), _("Type of account in line's most be differt to 'receivable' and 'payable'"))
 
46
        return {}
 
47
 
 
48
account_invoice()