67
text += '1' # Tipo de Registro
68
text += '340' # Modelo Declaración
69
text += self._formatString(report.fiscalyear_id.code, 4) # Ejercicio
70
text += self._formatString(report.company_vat, 9) # NIF del declarante
71
text += self._formatString(report.company_id.name, 40) # Apellidos y nombre o razón social del declarante
72
text += self._formatString(report.support_type, 1) # Tipo de soporte
73
text += self._formatString(report.contact_phone, 9) # Persona de contacto (Teléfono)
74
text += self._formatString(report.name_contact, 40) # Persona de contacto (Apellidos y nombre)
75
text += self._formatNumber(report.number, 13) # Número identificativo de la declaración
76
if (report.type == 'C'): text += 'C' # Declaración complementaria
78
if (report.type == 'S'): text += 'S' # Declaración substitutiva
80
text += self._formatNumber(report.previous_number, 13) # Número identificativo de la declaración anterior
81
text += self._formatString(report.period,2) # Periodo
82
text += self._formatNumber(report.number_records, 9) # Número total de registros
83
text += self._formatNumber(report.total_taxable, 15, 2,True) # Importe total de la base imponible
84
text += self._formatNumber(report.total_sharetax, 15, 2,True) # Importe Total de la cuota del impuesto
85
text += self._formatNumber(report.total, 15, 2,True) # Importe total de las facturas
86
text += 190*' ' # Blancos
87
text += self._formatString(report.representative_vat, 9) # NIF del representante legal
88
text += self._formatString(report.ean13, 17) # Sello electrónico
89
text += 84*' ' # Blancos
70
text += self._formatString(report.fiscalyear_id.code, 4)
72
text += self._formatString(report.company_vat, 9)
73
# Apellidos y nombre o razón social del declarante
74
text += self._formatString(report.company_id.name, 40)
76
text += self._formatString(report.support_type, 1)
77
# Persona de contacto (Teléfono)
78
text += self._formatString(report.contact_phone, 9)
79
# Persona de contacto (Apellidos y nombre)
80
text += self._formatString(report.name_contact, 40)
81
# Número identificativo de la declaración
82
text += self._formatNumber(report.number, 13)
83
# Declaración complementaria
84
if (report.type == 'C'): text += 'C'
86
# Declaración substitutiva
87
if (report.type == 'S'): text += 'S'
89
# Número identificativo de la declaración anterior
90
text += self._formatNumber(report.previous_number, 13)
91
period_stop = report.period_to.date_stop[5:7]
92
period_start = report.period_to.date_start[5:7]
93
if period_start == period_stop:
96
if period_stop == '03':
98
elif period_stop == '06':
100
elif period_stop == '09':
102
elif period_stop == '12':
105
raise orm.except_orm( "ERROR",
106
_("The period hasn't a valid Mod340 period" ))
108
text += self._formatString(period,2)
109
# Número total de registros
110
text += self._formatNumber(report.number_records, 9)
111
# Importe total de la base imponible
112
text += self._formatNumber(report.total_taxable, 15, 2,True)
113
# Importe Total de la cuota del impuesto
114
text += self._formatNumber(report.total_sharetax, 15, 2,True)
115
# Importe total de las facturas
116
text += self._formatNumber(report.total, 15, 2,True)
119
# NIF del representante legal
120
text += self._formatString(report.representative_vat, 9)
122
text += self._formatString(report.ean13, 17)
92
assert len(text) == 502, _("The type 1 record must be 500 characters long")
127
assert len(text)==502,_("The type 1 record must be 500 characters long")
95
132
def _get_formated_invoice_issued(self, cr, uid, report, invoice_issued):
105
142
9-17 NIF del declarante
106
143
18-26 NIF del declarado
107
144
27-35 NIF del representante legal
108
36-75 Apellidos y nombre, razón social o denominación del declarado
145
36-75 Apellidos y nombre, razón social o
146
denominación del declarado
109
147
76-77 Código país
110
148
78 Clave de identificación en el país de residencia
111
79-95 Número de identificación fiscal en el país de residencia. TODO de momento blancos.
149
79-95 Número de identificación fiscal en el país de
150
residencia. TODO de momento blancos.
113
152
99 Clave tipo de libro. Constante 'E'.
114
100 Clave de operación. Constante ' ' para un solo tipo de IVA. Constante 'C' para varios tipos de IVA. TODO Resto de operaciones. Varios tipos impositivos.
153
100 Clave de operación. Constante ' ' para un solo tipo de
154
IVA. Constante 'C' para varios tipos de IVA. TODO Resto
155
de operaciones. Varios tipos impositivos.
115
156
101-108 Fecha de expedición
116
109-116 Fecha de operación. Se consigna la misma que expedición. TODO. Fecha del uso del bien.
157
109-116 Fecha de operación. Se consigna la misma que
158
expedición. TODO. Fecha del uso del bien.
117
159
117-121 Tipo impositivo
118
160
122-135 Base imponible
119
161
136-149 Cuota del impuesto
121
163
164-177 Base imponible a coste. TODO de momento 0.
122
164
178-217 Identificación de la factura
123
165
218-235 Número de registro TODO No se exactamente que es
124
236-243 Número de facturas. Siempre 1. TODO Resumenes de facturas o tickets. Clave A o B.
125
244-245 Número de registro. Siempre 1. TODO Facturas con varios asientos. Clave C.
126
246-325 Intervalo de acumulación. Vacio. TODO Intervalo de resumenes de facturas o tickets.
166
236-243 Número de facturas. Siempre 1. TODO Resumenes de
167
facturas o tickets. Clave A o B.
168
244-245 Número de registro. Siempre 1. TODO Facturas con varios
170
246-325 Intervalo de acumulación. Vacio. TODO Intervalo de
171
resumenes de facturas o tickets.
127
172
326-365 Identificación de la factura rectificativa. TODO.
128
173
366-370 Tipo recargo de equivalencia. TODO.
129
174
371-384 Cuota recargo de equivalencia. TODO.
130
385 Situación del Inmueble #TODO 2012
131
386-410 Referencia Catastral #TODO 2012
132
411-425 Importe Percibido en Metálico #TODO 2012
133
426-429 Ejercicio ( cifras del ejercicio en el que se hubieran declarado las operaciones que dan origen al cobro ) #TODO 2012
134
430-444 Importe percibido por transmisiones de Inmuebles sujetas a IVA. #TODO 2012
175
385 Situación del Inmueble #TODO
176
386-410 Referencia Catastral #TODO
177
411-425 Importe Percibido en Metálico #TODO
178
426-429 Ejercicio (cifras del ejercicio en el que se hubieran
179
declarado las operaciones que dan origen al cobro)
181
430-444 Importe percibido por transmisiones de Inmuebles
140
188
for tax_line in invoice_issued.tax_line_ids:
142
text += '2' # Tipo de Registro
143
text += '340' # Modelo Declaración
144
text += self._formatString(report.fiscalyear_id.code, 4) # Ejercicio
145
text += self._formatString(report.company_vat, 9) # NIF del declarante
146
if invoice_issued.partner_country_code == 'ES': text += self._formatString(invoice_issued.partner_vat, 9) # NIF del declarado
147
else: text += self._formatString(' ', 9)
148
text += self._formatString(invoice_issued.representative_vat, 9) # NIF del representante legal
149
text += self._formatString(invoice_issued.partner_id.name, 40) # Apellidos y nombre, razón social o denominación del declarado
150
text += self._formatString(invoice_issued.partner_country_code, 2) # Código país
151
text += self._formatNumber(invoice_issued.partner_id.vat_type, 1) # Clave de identificación en el país de residencia
152
if invoice_issued.partner_country_code != 'ES': # Número de identificación fiscal en el país de residencia.
153
text += self._formatString(invoice_issued.partner_country_code, 2)
154
text += self._formatString(invoice_issued.partner_vat, 15)
194
text += self._formatString(report.fiscalyear_id.code, 4)
196
text += self._formatString(report.company_vat, 9)
198
if invoice_issued.partner_country_code == 'ES':
199
text += self._formatString(invoice_issued.partner_vat, 9)
200
else: text += self._formatString(' ', 9)
201
# NIF del representante legal
202
text += self._formatString(invoice_issued.representative_vat, 9)
203
# Apellidos y nombre, razón social o denominación del declarado
204
text += self._formatString(invoice_issued.partner_id.name, 40)
206
text += self._formatString(invoice_issued.partner_country_code, 2)
207
# Clave de identificación en el país de residencia
208
text += self._formatNumber(invoice_issued.partner_id.vat_type, 1)
209
# Número de identificación fiscal en el país de residencia.
210
if invoice_issued.partner_country_code != 'ES':
211
text+=self._formatString(invoice_issued.partner_country_code,2)
212
text+=self._formatString(invoice_issued.partner_vat, 15)
155
213
else: text += 17*' '
156
text += 3*' ' # Blancos
157
text += 'E' # Clave tipo de libro. Constante 'E'.
159
if invoice_issued.invoice_id.origin_invoices_ids: # Clave de operación
216
# Clave tipo de libro. Constante 'E'.
219
if invoice_issued.invoice_id.origin_invoices_ids:
161
221
elif len(invoice_issued.tax_line_ids) > 1: text += 'C'
162
222
elif invoice_issued.invoice_id.is_ticket_summary == 1: text += 'B'
165
225
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0],4)
166
226
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1],2)
167
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2) # Fecha de expedición
227
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2)
168
228
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0],4)
169
229
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1],2)
170
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2) # Fecha de operación
172
text += self._formatNumber(tax_line.tax_percentage*100,3,2) #Tipo impositivo
173
text += self._formatNumber(tax_line.base_amount, 11,2,True) # Base imponible
174
text += self._formatNumber(tax_line.tax_amount, 11,2,True) # Cuota del impuesto
175
text += self._formatNumber(tax_line.tax_amount+tax_line.base_amount, 11,2,True) # Importe total de la factura
176
text += ' '+self._formatNumber(0, 11,2) # Base imponible a coste.
177
text += self._formatString(invoice_issued.invoice_id.number, 40) # Identificación de la factura
178
text += self._formatString(self.pool.get('ir.sequence').get(cr, uid, 'mod340'),18) # Número de registro
179
if invoice_issued.invoice_id.is_ticket_summary == 1: # Número de facturas
230
text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2)
232
text += self._formatNumber(tax_line.tax_percentage*100,3,2)
234
text += self._formatNumber(tax_line.base_amount, 11,2,True)
236
text += self._formatNumber(tax_line.tax_amount, 11,2,True)
237
# Importe total de la factura
238
text += self._formatNumber(tax_line.tax_amount+
239
tax_line.base_amount, 11,2,True)
240
# Base imponible a coste.
241
text += ' '+self._formatNumber(0, 11,2)
242
# Identificación de la factura
243
text += self._formatString(invoice_issued.invoice_id.number, 40)
245
text += self._formatString(self.pool.get('ir.sequence').get(cr, uid, 'mod340'),18)
247
if invoice_issued.invoice_id.is_ticket_summary == 1:
180
248
text += self._formatNumber(invoice_issued.invoice_id.number_tickets, 8)
181
249
else: text += self._formatNumber(1, 8)
182
text += self._formatNumber(len(invoice_issued.tax_line_ids), 2) # Número de registros (Desglose)
183
if invoice_issued.invoice_id.is_ticket_summary == 1: # Intervalo de identificación de la acumulación
250
# Número de registros (Desglose)
251
text += self._formatNumber(len(invoice_issued.tax_line_ids), 2)
252
# Intervalo de identificación de la acumulación
253
if invoice_issued.invoice_id.is_ticket_summary == 1:
184
254
text += self._formatString(invoice_issued.invoice_id.first_ticket, 40)
185
255
text += self._formatString(invoice_issued.invoice_id.last_ticket, 40)
186
256
else: text += 80*' '
187
text += self._formatString( ",".join( [x.number for x in invoice_issued.invoice_id.origin_invoices_ids]) , 40 ) # Identificación factura rectificativa
257
# Identificación factura rectificativa
258
text += self._formatString( ",".join( [x.number for x in invoice_issued.invoice_id.origin_invoices_ids]) , 40 )
188
259
text += self._formatNumber(0, 5) # Tipo Recargo de equivalencia
189
260
text += ' '+self._formatNumber(0, 11,2) # Couta del recargo de equivalencia
190
261
text += '0' #Situación del Inmueble #TODO 2012
292
361
for invoice_received in report.received:
293
362
file_contents += self._get_formated_invoice_received(cr,uid,report, invoice_received)
295
365
return file_contents
298
def _export_boe_file(self, cr, uid, ids, report, model=None, context=None):
300
Action that exports the data into a BOE formated text file
309
file_contents += self._get_formated_declaration_record(report)
313
file_contents += self._get_formated_other_records(cr,uid,report)
316
## Generate the file and save as attachment
317
file = base64.encodestring(file_contents)
319
file_name = _("340_report_%s.txt") % (time.strftime(_("%Y-%m-%d")))
320
self.pool.get("ir.attachment").create(cr, uid, {
323
"datas_fname" : file_name,
324
"res_model" : "l10n.es.aeat.mod340",
325
"res_id" : ids and ids[0]
328
l10n_es_aeat_mod340_export_to_boe()