1
# -*- encoding: utf-8 -*-
2
##############################################################################
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>
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.
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.
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/>.
22
##############################################################################
31
'fromdate': {'string':'From Date', 'type':'date','required':True, },
32
'todate': {'string':'To Date', 'type':'date','required':True, },
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" />
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
46
if cadena[0:1].isdigit() == True:
52
def _importIssued(self, cr, uid, data, context):
54
pool = pooler.get_pool(cr.dbname)
55
from_date_invoices = data['form']['fromdate']
56
to_date_invoices = data['form']['todate']
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
62
#prepara la where con los taxes que hemos configurado
63
#solo para taxes_id ( emitdas )
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 ( "
71
where_taxes = where_taxes + " or"
73
where_taxes = where_taxes + " t.tax_code_id = " + str(taxes_codes.id)
77
#bloquea la insercion de registros no se han configurado taxes en config
79
where_taxes = "and t.tax_code_id = -1"
81
where_taxes = where_taxes + " )"
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))
93
for resultado in cr.fetchall():
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]),
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],
112
issued_obj.create(cr, uid, vals)
115
class wizard_issued(wizard.interface):
119
'result' : {'type' : 'form',
120
'arch' : import_issued_form,
121
'fields' : field_duedate,
122
'state' : [('end', 'Cancel'),('import', 'Import Issued') ]}
126
'result' : {'type' : 'action',
127
'action' : _importIssued,
131
wizard_issued('l10n_ES_aeat_mod340.wizard_issued')