~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to validate_type_line_invoice/account_invoice.py

  • Committer: nhomar at vauxoo
  • Date: 2011-06-11 22:55:27 UTC
  • Revision ID: nhomar@vauxoo.com-20110611225527-v2mlv4fbx38j0gg3
[SHELDON ] commiting ortografy

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 openerp.osv import osv, fields
27
 
from openerp.tools.translate import _
28
 
 
29
 
 
30
 
class account_invoice(osv.Model):
31
 
    _inherit = 'account.invoice'
32
 
 
33
 
    def action_move_create(self, cr, uid, ids, context=None):
34
 
        invoice_line_obj = self.pool.get('account.invoice.line')
35
 
        account_obj = self.pool.get('account.account')
36
 
        for id_ in ids:
37
 
            lines = invoice_line_obj.search(
38
 
                cr, uid, [('invoice_id', '=', id_)])
39
 
            for line in lines:
40
 
                id_account = invoice_line_obj.browse(
41
 
                    cr, uid, line).account_id.id
42
 
                type_line = account_obj.browse(cr, uid, id_account).type
43
 
                if type_line == 'receivable' or type_line == 'payable':
44
 
                    raise osv.except_osv(_('Error'), _(
45
 
                        """Type of account in line's must be differt
46
 
                           to 'receivable' and 'payable'"""))
47
 
            type_acc_invo = self.browse(cr, uid, id_).account_id.type
48
 
            type_invoice = self.browse(cr, uid, id_).type
49
 
            if (type_invoice == 'out_invoice' or
50
 
                type_invoice == 'out_refound') and \
51
 
               type_acc_invo != 'receivable':
52
 
                raise osv.except_osv(_('Error'), _(
53
 
                    """Type of account in invoice to Customer
54
 
                       must be 'receivable'"""))
55
 
            if (type_invoice == 'in_invoice' or
56
 
               type_invoice == 'in_refound') and \
57
 
               type_acc_invo != 'payable':
58
 
                raise osv.except_osv(_('Error'), _(
59
 
                    "Type of account in invoice to Partner must be 'payable'"))
60
 
        return super(account_invoice, self).action_move_create(cr, uid, ids)