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

« back to all changes in this revision

Viewing changes to l10n_es_aeat_mod340/wizard/wizard_received.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_received_form = """<?xml version="1.0" encoding="utf-8"?>
 
36
<form string="Imports Invoices received">
 
37
   <!-- <label string="Do you want to import invoices received 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 _importreceived(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
    received_obj = pool.get('l10n.es.aeat.mod340.received')
 
60
    configura_obj = mod340_obj.config_id
 
61
 
 
62
    #prepara la where con los taxes que hemos configurado
 
63
    #solo para supplier_taxes_id ( recibidas )
 
64
    where_taxes = ""
 
65
    try:
 
66
      for tax in configura_obj.supplier_taxes_id:
 
67
        if len(where_taxes) == 0:
 
68
                where_taxes = " and ( "
 
69
        else:
 
70
                where_taxes = where_taxes + " or"
 
71
 
 
72
        where_taxes = where_taxes + " t.tax_code_id = " + str(tax.ref_tax_code_id and tax.ref_tax_code_id.id or 'NULL')
 
73
    except Exception:
 
74
        print "error"
 
75
    finally:
 
76
        #bloquea la insercion de registros no se han configurado taxes en config
 
77
        if where_taxes == "":
 
78
                where_taxes = "and t.tax_code_id = -1"
 
79
        else:
 
80
                where_taxes = where_taxes + " )"
 
81
    #recogida de datos
 
82
    cr.execute("""SELECT replace(p.vat,'ES',''),p.name,p.vat,
 
83
                  i.date_invoice,a.amount,t.base_amount,t.tax_amount,
 
84
                  i.amount_total,i.number, i.type
 
85
                FROM account_invoice_tax t 
 
86
                   left join account_invoice i on t.invoice_id = i.id
 
87
                   left join res_partner p on i.partner_id = p.id
 
88
                   left join account_tax a on t.tax_code_id = a.tax_code_id
 
89
                where i.state <> 'draft' and i.type =%s and i.date_invoice between %s and %s """  + where_taxes +
 
90
                """order by date_invoice""",('in_invoice',from_date_invoices,to_date_invoices))
 
91
 
 
92
    for resultado in cr.fetchall():
 
93
        vals = {
 
94
                'mod340_id' : mod340_obj.id,
 
95
                'vat_declared' : resultado[0],
 
96
                'vat_representative' : '',
 
97
                'partner_name': resultado[1],
 
98
                'cod_country' : resultado[2][0:2],
 
99
                'key_country' : identNifDni(resultado[0]),
 
100
                #'vat_country' : '',
 
101
                'key_book' : 'E',
 
102
                'key_operation' : 'A', 
 
103
                #No issued es receive
 
104
                'invoice_date' : resultado[3],
 
105
                'operation_date' : resultado[3],
 
106
                'rate' : resultado[4],
 
107
                'taxable' : resultado[5],
 
108
                'share_tax' : resultado[6],
 
109
                'total' : resultado[7],
 
110
                'taxable_cost' : resultado[7],
 
111
                'number' : resultado[8],
 
112
        }
 
113
        received_obj.create(cr, uid, vals)
 
114
    return {}
 
115
 
 
116
class wizard_received(wizard.interface):
 
117
    states = {
 
118
        'init' : {
 
119
            'actions' : [],
 
120
            'result' : {'type' : 'form',
 
121
                    'arch' : import_received_form,
 
122
                    'fields' : field_duedate,
 
123
                    'state' : [('end', 'Cancel'),('import', 'Import received') ]}
 
124
        },
 
125
        'import' : {
 
126
            'actions' : [],
 
127
            'result' : {'type' : 'action',
 
128
                    'action' : _importreceived,
 
129
                    'state' : 'end'}
 
130
        },
 
131
    }
 
132
wizard_received('l10n_ES_aeat_mod340.wizard_received')