~vauxoo/addons-vauxoo/7.0-acc_invo_vat_required_dev_luis

« back to all changes in this revision

Viewing changes to account_invoice_vat_required/account_invoice.py

  • Committer: Luis Tores
  • Date: 2013-08-26 23:54:39 UTC
  • Revision ID: luis_t@vauxoo.com-20130826235439-413ydelcfgtja4ys
[ADD][account_invoice_vat_required]Added validation when validate the invoice, that review data for DIOT

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: moylop260 (moylop260@vauxoo.com)
 
10
#    Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com
 
11
############################################################################
 
12
#
 
13
#    This program is free software: you can redistribute it and/or modify
 
14
#    it under the terms of the GNU Affero General Public License as
 
15
#    published by the Free Software Foundation, either version 3 of the
 
16
#    License, or (at your option) any later version.
 
17
#
 
18
#    This program is distributed in the hope that it will be useful,
 
19
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
#    GNU Affero General Public License for more details.
 
22
#
 
23
#    You should have received a copy of the GNU Affero General Public License
 
24
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
#
 
26
##############################################################################
 
27
from openerp.osv import osv, fields
 
28
from openerp.tools.translate import _
 
29
from string import upper
 
30
 
 
31
 
 
32
class account_invoice(osv.Model):
 
33
    _inherit = 'account.invoice'
 
34
 
 
35
    def invoice_validate(self, cr, uid, ids, context=None):
 
36
        if not context:
 
37
            context = {}
 
38
        for invoice in self.browse(cr, uid, ids, context=context):
 
39
            partner_id = invoice.partner_id
 
40
            partner_vat = upper((partner_id.vat_split or '').replace('-', '').
 
41
                replace('_', '').replace(' ', ''))
 
42
            tax_purchase = False
 
43
            for tax in invoice.tax_line:
 
44
                if tax.tax_id and tax.tax_id.type_tax_use == 'purchase':
 
45
                    tax_purchase = True
 
46
                    continue
 
47
            if tax_purchase and (not partner_vat or not partner_id.\
 
48
                type_of_third or not partner_id.type_of_operation or (
 
49
                partner_id.type_of_third == '05' and not partner_id.\
 
50
                diot_country) or (partner_id.type_of_third == '04' and not\
 
51
                self.pool.get('res.partner').check_vat_mx(partner_vat))):
 
52
                raise osv.except_osv(_('Error!'), _(
 
53
                    'Please review the RFC and data for DIOT Report in the partner.'))
 
54
        return super(account_invoice, self).invoice_validate(cr, uid, ids,
 
55
            context=context)