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_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" />
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 _importreceived(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
received_obj = pool.get('l10n.es.aeat.mod340.received')
60
configura_obj = mod340_obj.config_id
62
#prepara la where con los taxes que hemos configurado
63
#solo para supplier_taxes_id ( recibidas )
66
for tax in configura_obj.supplier_taxes_id:
67
if len(where_taxes) == 0:
68
where_taxes = " and ( "
70
where_taxes = where_taxes + " or"
72
where_taxes = where_taxes + " t.tax_code_id = " + str(tax.ref_tax_code_id and tax.ref_tax_code_id.id or 'NULL')
76
#bloquea la insercion de registros no se han configurado taxes en config
78
where_taxes = "and t.tax_code_id = -1"
80
where_taxes = where_taxes + " )"
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))
92
for resultado in cr.fetchall():
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]),
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],
113
received_obj.create(cr, uid, vals)
116
class wizard_received(wizard.interface):
120
'result' : {'type' : 'form',
121
'arch' : import_received_form,
122
'fields' : field_duedate,
123
'state' : [('end', 'Cancel'),('import', 'Import received') ]}
127
'result' : {'type' : 'action',
128
'action' : _importreceived,
132
wizard_received('l10n_ES_aeat_mod340.wizard_received')