~avanzosc/openerp-spain/6.1

« back to all changes in this revision

Viewing changes to l10n_es_aeat_mod349/wizard/export_mod349_to_boe.py

  • Committer: Omar (pexego)
  • Date: 2011-03-04 17:52:36 UTC
  • Revision ID: omar@pexego.es-20110304175236-z7yre3omjbc7or95
[ADD] l10n_es_aeat, l10n_es_aeat_347, l10n_es_aeat_349: Adds a generic module for aeat models, 347 module was portedto v6.0 and adds new module to print AEAT model 349.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2004-2010 Pexego Sistemas Inform�ticos. All Rights Reserved
 
5
#
 
6
#    This program is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation, either version 3 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
##############################################################################
 
20
 
 
21
__author__ = "Luis Manuel Angueira Blanco (Pexego)"
 
22
 
 
23
 
 
24
from osv import osv
 
25
from tools.translate import _
 
26
 
 
27
class l10n_es_aeat_mod349_export_to_boe(osv.osv_memory):
 
28
 
 
29
    _inherit = "l10n.es.aeat.report.export_to_boe"
 
30
    _name = "l10n.es.aeat.mod349.export_to_boe"
 
31
    _description = "Export AEAT Model 349 to BOE format"
 
32
 
 
33
 
 
34
    def _get_company_name_with_title(self, company_obj):
 
35
        """
 
36
        Returns company name with title
 
37
        """
 
38
        if company_obj.partner_id and \
 
39
            company_obj.partner_id.title:
 
40
                return company_obj.name + ' ' + company_obj.partner_id.title.capitalize()
 
41
 
 
42
        return company_obj.name
 
43
 
 
44
 
 
45
    def _get_formated_declaration_record(self, report):
 
46
        """
 
47
        Returns a type 1, declaration/company, formated record.
 
48
 
 
49
            · All amounts must be positives
 
50
            · Numeric fields with no data must be filled with zeros
 
51
            · Alfanumeric/Alfabetic fields with no data must be filled with empty spaces
 
52
            · Numeric fields must be right aligned and filled with zeros on the left
 
53
            · Alfanumeric/Alfabetic fields must be uppercase left aligned,
 
54
              filled with empty spaces on right side. No special characters allowed
 
55
              unless specified in field description
 
56
 
 
57
        Format of the record:
 
58
            Tipo registro 1 – Registro de declarante:
 
59
            Posiciones  Naturaleza      Descripción
 
60
            1           Numérico        Tipo de Registro            Constante = '1'
 
61
            2-4         Numérico        Modelo Declaración          Constante = '349'
 
62
            5-8         Numérico        Ejercicio
 
63
            9-17        Alfanumérico    NIF del declarante
 
64
            18-57       Alfanumérico    Apellidos y nombre o razón social del declarante
 
65
            58          Alfabético      Tipo de soporte
 
66
            59-67       Numérico (9)    Teléfono contacto
 
67
            68-107      Alfabético      Apellidos y nombre contacto
 
68
            108-120     Numérico        Número identificativo de la declaración
 
69
            121-122     Alfabético      Declaración complementaria o substitutiva
 
70
            123-135     Numérico        Número identificativo de la declaración anterior
 
71
            136-137     Alfanumérico    Período
 
72
            138-146     Numérico        Número total de operadores intracomunitarios
 
73
            147-161     Numérico        Importe de las operaciones intracomunitarias
 
74
            - 147-159     Numérico        Importe de las operaciones intracomunitarias (parte entera)
 
75
            - 160-161     Numérico        Importe de las operaciones intracomunitarias (parte decimal)
 
76
            162-170     Numérico        Número total de operadores intracomunitarios con rectificaciones
 
77
            171-185     Numérico        Importe total de las rectificaciones
 
78
            - 171-183     Numérico        Importe total de las rectificaciones (parte entera)
 
79
            - 184-185     Numérico        Importe total de las rectificaciones (parte decimal)
 
80
            186         Alfabético      Indicador cambio periodicidad en la obligación a declarar (X o '')
 
81
            187-390     Blancos         ----------------------------------------
 
82
            391-399     Alfanumérico    NIF del representante legal
 
83
            400-487     Blancos         ----------------------------------------
 
84
            488-500     Sello electrónico
 
85
        """
 
86
 
 
87
        assert report, 'No Report defined'
 
88
 
 
89
        company_name = self._get_company_name_with_title(report.company_id)
 
90
        period = report.period_selection == 'MO' and report.month_selection or report.period_selection
 
91
 
 
92
        text = ''                                                               ## Empty text
 
93
 
 
94
        text += '1'                                                             # Tipo de Registro
 
95
        text += '349'                                                           # Modelo Declaración
 
96
        text += self._formatNumber(report.fiscalyear_id.code, 4)                # Ejercicio
 
97
        text += self._formatString(report.company_vat, 9)                       # NIF del declarante
 
98
        text += self._formatString(company_name, 40)                            # Apellidos y nombre o razón social del declarante
 
99
        text += self._formatString(report.support_type, 1)                      # Tipo de soporte
 
100
        text += self._formatString(report.contact_phone.replace(' ', ''), 9)    # Persona de contacto (Teléfono)
 
101
        text += self._formatString(report.contact_name, 40)                     # Persona de contacto (Apellidos y nombre)
 
102
        text += self._formatNumber(report.number, 13)                           # Número identificativo de la declaración
 
103
        text += self._formatString(report.type, 2).replace('N', ' ')            # Declaración complementaria o substitutiva
 
104
        text += self._formatNumber(report.previous_number, 13)                  # Número identificativo de la declaración anterior
 
105
        text += self._formatString(period, 2)                                   # Período
 
106
        text += self._formatNumber(report.total_partner_records, 9)             # Número total de operadores intracomunitarios
 
107
        text += self._formatNumber(report.total_partner_records_amount, 13, 2)  # Importe total de las operaciones intracomunitarias (parte entera)
 
108
        text += self._formatNumber(report.total_partner_refunds, 9)             # Número total de operadores intracomunitarios con rectificaciones
 
109
        text += self._formatNumber(report.total_partner_refunds_amount, 13, 2)  # Importe total de las rectificaciones
 
110
        text += self._formatBoolean(report.frequency_change)                    # Indicador cambio periodicidad en la obligación a declarar
 
111
        text += 204*' '                                                         # Blancos
 
112
        text += self._formatString(report.representative_vat, 9)                # NIF del representante legal
 
113
        text += 88*' '                                                          # Blancos
 
114
        text += 13*' '                                                          # Sello electrónico
 
115
        text += '\r\n'                                                          # Retorno de carro + Salto de línea
 
116
 
 
117
        assert len(text) == 502, _("The type 1 record must be 502 characters long")
 
118
        return text
 
119
 
 
120
 
 
121
    def _get_formated_partner_record(self, report, partner_record):
 
122
        """
 
123
        Returns a type 2, partner record
 
124
 
 
125
        Format of the record:
 
126
            Tipo registro 2
 
127
            Posiciones  Naturaleza      Descripción
 
128
            1           Numérico        Tipo de Registro            Constante = '2'
 
129
            2-4         Numérico        Modelo Declaración          Constante = '349'
 
130
            5-8         Numérico        Ejercicio
 
131
            9-17        Alfanumérico    NIF del declarante
 
132
            18-75       Blancos         ----------------------------------------
 
133
            76-92       Alfanumérico    NIF operador Intracomunitario
 
134
            - 76-77       Alfanumérico    Codigo de País
 
135
            - 78-92       Alfanumérico    NIF
 
136
            93-132      Alfanumérico    Apellidos y nombre o razón social del operador intracomunitario
 
137
            133         Alfanumérico    Clave de operación
 
138
            134-146     Numérico        Base imponible
 
139
            - 134-144     Numérico        Base imponible (parte entera)
 
140
            - 145-146     Numérico        Base imponible (parte decimal)
 
141
            147-500     Blancos         ----------------------------------------
 
142
        """
 
143
 
 
144
        assert report, 'No AEAT 349 Report defined'
 
145
        assert partner_record, 'No Partner record defined'
 
146
 
 
147
        text = ''
 
148
 
 
149
 
 
150
        ## Formateo de algunos campos (debido a que pueden no ser correctos)
 
151
        ## NIF : Se comprueba que no se incluya el código de pais
 
152
        company_vat = report.company_vat
 
153
        if len(report.company_vat) > 9:
 
154
            company_vat = report.company_vat[2:]
 
155
 
 
156
        text += '2'                                                                 # Tipo de registro
 
157
        text += '349'                                                               # Modelo de declaración
 
158
        text += self._formatNumber(report.fiscalyear_id.code, 4)                    # Ejercicio
 
159
        text += self._formatString(company_vat, 9)                                  # NIF del declarante
 
160
        text += 58*' '                                                              # Blancos
 
161
        text += self._formatString(partner_record.partner_vat, 17)                  # NIF del operador intracomunitario
 
162
        text += self._formatString(partner_record.partner_id.name, 40)              # Apellidos y nombre o razón social del operador intracomunitario
 
163
        text += self._formatString(partner_record.operation_key, 1)                 # Clave de operación
 
164
        text += self._formatNumber(partner_record.total_operation_amount, 11, 2)    # Base imponible (parte entera)
 
165
 
 
166
        text += 354*' '                                                             # Blancos
 
167
        text +='\r\n'                                                               # Retorno de carro + Salto de línea
 
168
 
 
169
        assert len(text) == 502, _("The type 2 record must be 502 characters long")
 
170
        return text
 
171
 
 
172
 
 
173
    def _get_formatted_partner_refund(self, report, refund_record):
 
174
        """
 
175
        Returns a type 2, refund record
 
176
 
 
177
        Format of the record:
 
178
            Tipo registro 2
 
179
            Posiciones  Naturaleza      Descripción
 
180
            1           Numérico        Tipo de Registro            Constante = '2'
 
181
            2-4         Numérico        Modelo Declaración          Constante = '349'
 
182
            5-8         Numérico        Ejercicio
 
183
            9-17        Alfanumérico    NIF del declarante
 
184
            18-75       Blancos         ----------------------------------------
 
185
            76-92       Alfanumérico    NIF operador Intracomunitario
 
186
            - 76-77       Alfanumérico    Codigo de Pais
 
187
            - 78-92       Alfanumérico    NIF
 
188
            93-132      Alfanumérico    Apellidos y nombre o razón social del operador intracomunitario
 
189
            133         Alfanumérico    Clave de operación
 
190
            134-146     Blancos         ----------------------------------------
 
191
            147-178     Alfanumérico    Rectificaciones
 
192
            - 147-150     Numérico        Ejercicio
 
193
            - 151-152     Alfanumérico    Periodo
 
194
            - 153-165     Numérico        Base Imponible rectificada
 
195
              - 153-163     Numérico        Base Imponible (parte entera)
 
196
              - 164-165     Numérico        Base Imponible (parte decimal)
 
197
            166-178     Numérico        Base imponible declarada anteriormente
 
198
            - 166-176     Numérico        Base imponible declarada anteriormente (parte entera)
 
199
            - 177-176     Numérico        Base imponible declarada anteriormente (parte decimal)
 
200
            179-500     Blancos         ----------------------------------------
 
201
        """
 
202
 
 
203
        assert report, 'No AEAT 349 Report defined'
 
204
        assert refund_record, 'No Refund record defined'
 
205
 
 
206
        text = ''
 
207
        period = refund_record.period_selection == 'MO' and refund_record.month_selection or refund_record.period_selection
 
208
 
 
209
        text += '2'                                                             # Tipo de registro
 
210
        text += '349'                                                           # Modelo de declaración
 
211
        text += self._formatNumber(report.fiscalyear_id.code, 4)                # Ejercicio
 
212
        text += self._formatString(report.company_vat, 9)                       # NIF del declarante
 
213
        text += 58*' '                                                          # Blancos        
 
214
        text += self._formatString(refund_record.partner_id.vat, 17)            # NIF del operador intracomunitario
 
215
        text += self._formatString(refund_record.partner_id.name, 40)           # Apellidos y nombre o razón social del operador intracomunitario
 
216
        text += self._formatString(refund_record.operation_key, 1)              # Clave de operación
 
217
        text += 13*' '                                                          # Blancos
 
218
        text += self._formatNumber(refund_record.fiscalyear_id.code, 4)         # Ejercicio (de la rectificación)
 
219
        text += self._formatString(period, 2)                                   # Periodo (de la rectificación)
 
220
        text += self._formatNumber(refund_record.total_operation_amount, 11, 2) # Base imponible de la rectificación
 
221
        text += self._formatNumber(refund_record.total_origin_amount, 11, 2)    # Base imponible declarada anteriormente
 
222
        text += 322*' '                                                         # Blancos
 
223
        text +='\r\n'                                                           # Retorno de carro + Salto de línea
 
224
 
 
225
        assert len(text) == 502, _("The type 2 record must be 502 characters long")
 
226
        return text
 
227
 
 
228
 
 
229
    def _get_formated_other_records(self, report):
 
230
        file_contents = ''
 
231
        for refund_record in report.partner_refund_ids:
 
232
            file_contents += self._get_formatted_partner_refund(report, refund_record)
 
233
        
 
234
        return file_contents
 
235
    
 
236
 
 
237
    def _export_boe_file(self, cr, uid, ids, object_to_export, model=None, context=None):
 
238
        return super(l10n_es_aeat_mod349_export_to_boe, self)._export_boe_file(cr, uid, ids, object_to_export, model='349')
 
239
 
 
240
l10n_es_aeat_mod349_export_to_boe()
 
 
b'\\ No newline at end of file'