~openerp-spain-team/openerp-spain/6.0-git

« back to all changes in this revision

Viewing changes to l10n_es_extras/l10n_ES_aeat_mod340/wizard/wizard_issued.py

  • Committer: Borja L.S.
  • Date: 2010-10-18 10:04:25 UTC
  • Revision ID: git-v1:271c47a993616dbba60585d48b8b98d603199d93
[REF] *: Refactorización para portar a 6.0 - Paso 1.

- Se han renombrado los módulos para usar la nomenclatura propuesta
  por OpenERP: l10n_es para el módulo base de localización (plan de 
  cuentas), l10n_es_* para el resto de módulos.

- Se eliminan los módulos extra_addons/* que deberían moverse a 
  los extra-addons genéricos (no son específicos de España).

- Se renombran los __terp__.py por __openerp__.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (c) 2009 Alejandro Sanchez (http://www.asr-oss.com) All Rights Reserved.
6
 
#                       Alejandro Sanchez <alejandro@asr-oss.com>
7
 
#    $Id$
8
 
#
9
 
#    This program is free software: you can redistribute it and/or modify
10
 
#    it under the terms of the GNU General Public License as published by
11
 
#    the Free Software Foundation, either version 3 of the License, or
12
 
#    (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 General Public License for more details.
18
 
#
19
 
#    You should have received a copy of the GNU General Public License
20
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
#
22
 
##############################################################################
23
 
 
24
 
import wizard
25
 
import netsvc
26
 
import pooler
27
 
import string
28
 
 
29
 
 
30
 
field_duedate={
31
 
    'fromdate': {'string':'From Date', 'type':'date','required':True, },
32
 
    'todate': {'string':'To Date', 'type':'date','required':True, },
33
 
    }
34
 
 
35
 
import_issued_form = """<?xml version="1.0" encoding="utf-8"?>
36
 
<form string="Imports Invoices Issued">
37
 
   <!-- <label string="Do you want to import invoices issued for the selected dates?" />-->
38
 
    <field name="fromdate" />
39
 
    <field name="todate" />
40
 
</form>"""
41
 
 
42
 
def identNifDni(cadena):
43
 
    #identifica si es dni o Nif obteniento la primera parte de la cadena
44
 
    #asume que si es numero sera Dni si es letra Nif
45
 
    resultado = ""
46
 
    if cadena[0:1].isdigit() == True:
47
 
        resultado = "4"     
48
 
    else:
49
 
        resultado = "1"
50
 
    return resultado
51
 
 
52
 
def _importIssued(self, cr, uid, data, context):
53
 
    #recogida parametros
54
 
    pool = pooler.get_pool(cr.dbname)
55
 
    from_date_invoices = data['form']['fromdate']
56
 
    to_date_invoices = data['form']['todate']
57
 
 
58
 
    mod340_obj = pool.get('l10n.es.aeat.mod340').browse(cr, uid, data['id'],context=context)
59
 
    issued_obj = pool.get('l10n.es.aeat.mod340.issued')
60
 
    configura_obj = mod340_obj.config_id
61
 
 
62
 
    #prepara la where con los taxes que hemos configurado
63
 
    #solo para taxes_id ( emitdas )
64
 
    where_taxes = ""
65
 
    try:
66
 
      for tax in configura_obj.taxes_id:
67
 
        taxes_codes = tax.ref_tax_code_id
68
 
        if len(where_taxes) == 0:
69
 
                where_taxes = " and ( "
70
 
        else:
71
 
                where_taxes = where_taxes + " or"
72
 
 
73
 
        where_taxes = where_taxes + " t.tax_code_id = " + str(taxes_codes.id)
74
 
    except Exception:
75
 
        print "error"
76
 
    finally:
77
 
        #bloquea la insercion de registros no se han configurado taxes en config
78
 
        if where_taxes == "":
79
 
                where_taxes = "and t.tax_code_id = -1"
80
 
        else:
81
 
                where_taxes = where_taxes + " )"
82
 
    #recogida de datos
83
 
    cr.execute("""SELECT replace(p.vat,'ES',''),p.name,p.vat,
84
 
                  i.date_invoice,a.amount,t.base_amount,t.tax_amount,
85
 
                  i.amount_total,i.number, i.type
86
 
                FROM account_invoice_tax t 
87
 
                   left join account_invoice i on t.invoice_id = i.id
88
 
                   left join res_partner p on i.partner_id = p.id
89
 
                   left join account_tax a on t.tax_code_id = a.tax_code_id
90
 
                where i.state <> 'draft' and i.type =%s and i.date_invoice between %s and %s """  + where_taxes +
91
 
                """order by date_invoice""",('out_invoice',from_date_invoices,to_date_invoices))
92
 
 
93
 
    for resultado in cr.fetchall():
94
 
        vals = {
95
 
                'mod340_id' : mod340_obj.id,
96
 
                'vat_declared' : resultado[0],
97
 
                'vat_representative' : '',
98
 
                'partner_name': resultado[1],
99
 
                'cod_country' : resultado[2][0:2],
100
 
                'key_country' : identNifDni(resultado[0]),
101
 
                'key_book' : 'E',
102
 
                'key_operation' : 'J', 
103
 
                'invoice_date' : resultado[3],
104
 
                'operation_date' : resultado[3],
105
 
                'rate' : resultado[4] * 100,
106
 
                'taxable' : resultado[5],
107
 
                'share_tax' : resultado[6],
108
 
                'total' : resultado[7],
109
 
                'taxable_cost' : resultado[7],
110
 
                'number' : resultado[8],
111
 
        }
112
 
        issued_obj.create(cr, uid, vals)
113
 
    return {}
114
 
 
115
 
class wizard_issued(wizard.interface):
116
 
    states = {
117
 
        'init' : {
118
 
            'actions' : [],
119
 
            'result' : {'type' : 'form',
120
 
                    'arch' : import_issued_form,
121
 
                    'fields' : field_duedate,
122
 
                    'state' : [('end', 'Cancel'),('import', 'Import Issued') ]}
123
 
        },
124
 
        'import' : {
125
 
            'actions' : [],
126
 
            'result' : {'type' : 'action',
127
 
                    'action' : _importIssued,
128
 
                    'state' : 'end'}
129
 
        },
130
 
    }
131
 
wizard_issued('l10n_ES_aeat_mod340.wizard_issued')