~vauxoo/openerp-mexico-localization/facturae-lugar-expedicion-dev-luis

« back to all changes in this revision

Viewing changes to l10n_mx_invoice_tax_ref/invoice.py

  • Committer: moylop260
  • Date: 2012-09-08 03:25:38 UTC
  • Revision ID: moylop260@vauxoo.com-20120908032538-ozszoaq7j3nm370j
[FIX] [l10n_mx_invoice_tax_ref] Fix compute amount & name of tax from invoice

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        res = {}
43
43
        for invoice_tax in self.browse(cr, uid, ids, context=context):
44
44
            res[invoice_tax.id] = {}
45
 
            if 'tax_id' in self._columns:
46
 
                res[invoice_tax.id]['name2'] = (invoice_tax.tax_id.tax_category_id and invoice_tax.tax_id.tax_category_id.name or invoice_tax.tax_id.name).upper()
47
 
                res[invoice_tax.id]['tax_percent'] = invoice_tax.amount and invoice_tax.base and invoice_tax.amount*100.0 / abs( invoice_tax.base ) or 0.0
48
 
            else:
49
 
                tax_name = invoice_tax.name.lower().replace('.','').replace(' ', '').replace('-', '')
50
 
                tax_percent = invoice_tax.amount and invoice_tax.base and invoice_tax.amount*100.0 / abs( invoice_tax.base ) or 0.0
51
 
                if 'iva' in tax_name:
52
 
                    tax_name = 'IVA'
53
 
                    if tax_percent > 0:
54
 
                        tax_percent = round(tax_percent, 0)#Hay problemas de decimales al calcular el iva, y hasta ahora el iva no tiene decimales
55
 
                elif 'isr' in tax_name:
56
 
                    tax_name = 'ISR'
57
 
                elif 'ieps' in tax_name:
58
 
                    tax_name = 'IEPS'
59
 
                res[invoice_tax.id]['name2'] = tax_name
60
 
                res[invoice_tax.id]['tax_percent'] = tax_percent
61
 
                #res[invoice_tax.id]['amount'] = invoice_tax.amount
 
45
            tax = 'tax_id' in self._columns and invoice_tax.tax_id or False#If patch apply and module account_invoice_tax install
 
46
            tax_name = (tax and tax.tax_category_id and tax.tax_category_id.code or invoice_tax.name).upper().replace('.','').replace(' ', '').replace('-', '')
 
47
            tax_percent = (tax and tax.amount*100.0 or False)#validate? type='percent'
 
48
            tax_percent = tax_percent or ( invoice_tax.amount and invoice_tax.base and invoice_tax.amount*100.0 / abs( invoice_tax.base ) or 0.0 )
 
49
            if 'IVA' in tax_name:
 
50
                tax_name = 'IVA'
 
51
                if not tax and tax_percent > 0:
 
52
                    tax_percent = round(tax_percent, 0)#Hay problemas de decimales al calcular el iva, y hasta ahora el iva no tiene decimales
 
53
            elif 'ISR' in tax_name:
 
54
                tax_name = 'ISR'
 
55
            elif 'IEPS' in tax_name:
 
56
                tax_name = 'IEPS'
 
57
            res[invoice_tax.id]['name2'] = tax_name
 
58
            res[invoice_tax.id]['tax_percent'] = tax_percent
 
59
            #res[invoice_tax.id]['amount'] = invoice_tax.amount
62
60
        return res
63
61
    
64
62
    _columns = {