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

« back to all changes in this revision

Viewing changes to l10n_es_extras/l10n_ES_aeat_mod340/mod340.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
 
from osv import osv,fields
25
 
import time
26
 
import netsvc
27
 
 
28
 
class l10n_es_aeat_mod340_config(osv.osv):
29
 
    _name = 'l10n.es.aeat.mod340.config'
30
 
    _description = 'Config Model 340'
31
 
    _columns = {
32
 
        'name' : fields.char('Name',size=40),
33
 
        'taxes_id': fields.many2many('account.tax', 'mod340_config_taxes_rel','config_id', 'tax_id', 
34
 
            'Customer Taxes',domain=[('parent_id','=',False),('type_tax_use','in',['sale','all'])]),
35
 
        'supplier_taxes_id': fields.many2many('account.tax',
36
 
        'mod340_config_supplier_taxes_rel', 'config_id', 'tax_id',
37
 
            'Supplier Taxes', domain=[('parent_id', '=', False),('type_tax_use','in',['purchase','all'])])
38
 
    }
39
 
l10n_es_aeat_mod340_config()
40
 
 
41
 
class l10n_es_aeat_mod340(osv.osv):
42
 
 
43
 
    def _total_taxable(self, cursor, user, ids, name, args, context=None):
44
 
        if not ids:
45
 
            return {}
46
 
        res = {}
47
 
        for mod340 in self.browse(cursor, user, ids, context=context):
48
 
            res[mod340.id] = 0.0
49
 
            #registros emitidas
50
 
            if mod340.issued:
51
 
                res[mod340.id] = reduce(lambda x, y: x + y.taxable, mod340.issued, 0.0)
52
 
            #registros recibidas
53
 
            if mod340.received:
54
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.taxable, mod340.received, 0.0)
55
 
            #registros investment
56
 
            if mod340.investment:
57
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.taxable, mod340.investment, 0.0)
58
 
            #registros intracomunitarias
59
 
            if mod340.intracomunitarias:
60
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.taxable, mod340.intracomunitarias, 0.0)
61
 
 
62
 
        return res
63
 
 
64
 
    def _total_share_tax(self, cursor, user, ids, name, args, context=None):
65
 
        if not ids:
66
 
            return {}
67
 
        res = {}
68
 
        for mod340 in self.browse(cursor, user, ids, context=context):
69
 
            res[mod340.id] = 0.0
70
 
            #registros emitidas
71
 
            if mod340.issued:
72
 
                res[mod340.id] = reduce(lambda x, y: x + y.share_tax, mod340.issued, 0.0)
73
 
            #registros recibidas
74
 
            if mod340.received:
75
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.share_tax, mod340.received, 0.0)
76
 
            #registros investment
77
 
            if mod340.investment:
78
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.share_tax, mod340.investment, 0.0)
79
 
            #registros intracomunitarias
80
 
            if mod340.intracomunitarias:
81
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.share_tax, mod340.intracomunitarias, 0.0)
82
 
 
83
 
        return res
84
 
 
85
 
    def _total(self, cursor, user, ids, name, args, context=None):
86
 
        if not ids:
87
 
            return {}
88
 
        res = {}
89
 
        for mod340 in self.browse(cursor, user, ids, context=context):
90
 
            res[mod340.id] = 0.0
91
 
            #registros emitidas
92
 
            if mod340.issued:
93
 
                res[mod340.id] = reduce(lambda x, y: x + y.total, mod340.issued, 0.0)
94
 
            #registros recibidas
95
 
            if mod340.received:
96
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.total, mod340.received, 0.0)
97
 
            #registros investment
98
 
            if mod340.investment:
99
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.total, mod340.investment, 0.0)
100
 
            #registros intracomunitarias
101
 
            if mod340.intracomunitarias:
102
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + y.total, mod340.intracomunitarias, 0.0)
103
 
 
104
 
        return res
105
 
 
106
 
    def _numer_records(self, cursor, user, ids, name, args, context=None):
107
 
        if not ids:
108
 
            return {}
109
 
        res = {}
110
 
        for mod340 in self.browse(cursor, user, ids, context=context):
111
 
            res[mod340.id] = 0.0
112
 
            #registros emitidas
113
 
            if mod340.issued:
114
 
                res[mod340.id] = reduce(lambda x, y: x + 1, mod340.issued, 0)
115
 
            #registros recibidas
116
 
            if mod340.received:
117
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + 1, mod340.received, 0)
118
 
            #registros investment
119
 
            if mod340.investment:
120
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + 1, mod340.investment, 0)
121
 
            #registros intracomunitarias
122
 
            if mod340.intracomunitarias:
123
 
                res[mod340.id] = res[mod340.id] + reduce(lambda x, y: x + 1, mod340.intracomunitarias, 0)
124
 
 
125
 
        return res
126
 
    _name = 'l10n.es.aeat.mod340'
127
 
    _description = 'Model 340'
128
 
    _columns = {
129
 
        'fiscalyear': fields.integer('Fiscal Year',size=4),
130
 
        'type': fields.selection([(' ','Normal'),('C','Complementary'),('S','Replacement')], 'Type Statement'),
131
 
        'type_support': fields.selection([('C','DVD'),('T','Telematics')],'Type Support'),
132
 
        'config_id': fields.many2one('l10n.es.aeat.mod340.config','Config',required=True),
133
 
        'company_id': fields.many2one('res.company', 'Company', required=True),
134
 
        'vat_representative' : fields.char('Vat Legal Representative',size=9),
135
 
        #'vat_company': fields.char('VAT', size=32, requiered=True),
136
 
        'name_surname': fields.char('Name and Surname',size=40),
137
 
        'phone': fields.char('Phone',size=9),
138
 
        'phone_contact' : fields.char('Phone Contact',size=9),
139
 
        'name_contact' : fields.char('Name And Surname Contact',size=40),
140
 
        'period': fields.selection([
141
 
            ('1T','First quarter'),('2T','Second quarter'),('3T','Third quarter'),
142
 
            ('4T','Fourth quarter'),('01','January'),('02','February'),('03','March'),('04','April'),
143
 
            ('05','May'),('06','June'),('07','July'),('08','August'),('09','September'),('10','October'),
144
 
            ('11','November'),('12','December')
145
 
            ], 'Period'),
146
 
        'issued': fields.one2many('l10n.es.aeat.mod340.issued','mod340_id','Invoices Issued'),
147
 
        'received': fields.one2many('l10n.es.aeat.mod340.received','mod340_id','Invoices Received'),
148
 
        'investment': fields.one2many('l10n.es.aeat.mod340.investment','mod340_id','Property Investment'),
149
 
        'intracomunitarias': fields.one2many('l10n.es.aeat.mod340.intracomunitarias','mod340_id','Operations Intracomunitarias'),
150
 
        'state': fields.selection([
151
 
            ('draft', 'Draft'),('open','Confirmed'),('cancel','Cancelled'),
152
 
            ('done','Done')
153
 
            ], 'State', select=True),
154
 
        'date_done': fields.date('Execution date', readonly=True),
155
 
        'number_records' : fields.function(_numer_records, string="Total Records", method=True,
156
 
            type='float'),
157
 
        'total_taxable': fields.function(_total_taxable, string="Total Taxable", method=True,
158
 
            type='float'),
159
 
        'total_sharetax': fields.function(_total_share_tax, string="Total Share Tax", method=True,
160
 
            type='float'),
161
 
        'total': fields.function(_total, string="Total", method=True,
162
 
            type='float'),
163
 
    }
164
 
    _defaults = {
165
 
        'fiscalyear': lambda *a: int(time.strftime('%Y')),
166
 
        'type': lambda *args: ' ',
167
 
        'type_support': lambda *args: 'T',
168
 
    }
169
 
 
170
 
    def set_done(self, cr, uid, id, *args):
171
 
        self.write(cr,uid,id,{'date_done': time.strftime('%Y-%m-%d'),'state': 'done',})
172
 
        wf_service = netsvc.LocalService("workflow")
173
 
        wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', id, 'done', cr)
174
 
        return True
175
 
 
176
 
    #def onchange_company_id(self, cr, uid, ids, company_id):
177
 
    #    vat = False
178
 
    #    if company_id:
179
 
    #        p = self.pool.get('res.company').browse(cr, uid, company_id)
180
 
    #        vat = p.partner_id.vat
181
 
    #        result = {'value':{'vat_company': vat}}
182
 
    #    return result
183
 
 
184
 
l10n_es_aeat_mod340()
185
 
 
186
 
class l10n_es_aeat_mod340_issued(osv.osv):
187
 
    _name = 'l10n.es.aeat.mod340.issued'
188
 
    _description = 'Invoices Issued'
189
 
    _columns = {
190
 
        'mod340_id': fields.many2one('l10n.es.aeat.mod340','Model 340',ondelete="cascade"),
191
 
        'vat_declared' : fields.char('Vat Declared',size=9),
192
 
        'vat_representative' : fields.char('Legal Representative',size=9),
193
 
        'partner_name': fields.char('Name',size=40),
194
 
        'cod_country' : fields.char('Code Country',size=2),
195
 
        'key_country' : fields.selection([
196
 
            ('1','Nif'),('2','Nif/Iva'),('3','Passport'),('4','Dni'),('5','Fiscal Residence Certificate '),
197
 
            ('6','Other')
198
 
            ],'Key Ident Country'),
199
 
        'vat_country' : fields.char('Vat on Country of residence',size =17),
200
 
        'key_book' : fields.selection([
201
 
            ('E','Invoice Issued'),('I','Property Investment'),('R','Invoices Recibed'),
202
 
            ('U','Intra-Community Transactions'),('F','Invoice Issued IGIC'),
203
 
            ('J','Property Investment IGIC'),('S','Invoices Recibed IGIC')
204
 
            ],'Books'),
205
 
        'key_operation' : fields.selection([
206
 
            ('A','Account move Invoices'),('B','Account move Receipt'),
207
 
            ('C','Invoces varius tax rates'),('D','Amendment Invoices'),
208
 
            ('F','Travel Agency'),('G','IGIC'),('H','Gold Investment'),
209
 
            ('I','ISP'),('J','Receipt'),('K','Error correction'),
210
 
            ('L','None of the above')
211
 
            ],'Key Operation'),
212
 
        'invoice_date' : fields.date('Invoice Date'),
213
 
        'operation_date' : fields.date('Operation Date'),
214
 
        'rate' : fields.float('Rate',digits=(5,2)),
215
 
        'taxable' : fields.float('Taxable',digits=(13,2)),
216
 
        'share_tax' : fields.float('Share Tax',digits=(13,2)),
217
 
        'total' : fields.float('Total Invoice',digits=(13,2)),
218
 
        'taxable_cost' : fields.float('Taxable Cost',digits=(13,2)),
219
 
        'number' : fields.char('Invoice Number',size=40),
220
 
        'number_amendment' : fields.char('Number Invoice Amendment',size=40),
221
 
        #HASTA AQUI COMUNES EL RESTO ESPECIFICOS
222
 
        'number_invoices' : fields.integer('Invoices Accumulated',size = 4),
223
 
        'number_records' : fields.integer('Number records accumulated',size = 4),
224
 
        'iterval_ini' : fields.char('Initiation Interval',size=40),
225
 
        'iterval_end' : fields.char('Order Interval',size=40),
226
 
        'invoice_corrected' : fields.char('Invoice Corrected',size=40),
227
 
        'charge' : fields.float('Charge Equivalence',digits=(5,2)),
228
 
        'share_charge' : fields.float('Rate',digits=(5,2)),
229
 
    }
230
 
l10n_es_aeat_mod340_issued()
231
 
 
232
 
class l10n_es_aeat_mod340_received(osv.osv):
233
 
    _name = 'l10n.es.aeat.mod340.received'
234
 
    _description = 'Invoices Received'
235
 
    _inherit = 'l10n.es.aeat.mod340.issued'
236
 
l10n_es_aeat_mod340_received()
237
 
 
238
 
class l10n_es_aeat_mod340_investment(osv.osv):
239
 
    _name = 'l10n.es.aeat.mod340.investment'
240
 
    _description = 'Property Investment'
241
 
    _inherit = 'l10n.es.aeat.mod340.issued'
242
 
l10n_es_aeat_mod340_investment()
243
 
 
244
 
class l10n_es_aeat_mod340_intracomunitarias(osv.osv):
245
 
    _name = 'l10n.es.aeat.mod340.intracomunitarias'
246
 
    _description = 'Operations Intracomunitarias'
247
 
    _inherit = 'l10n.es.aeat.mod340.issued'
248
 
l10n_es_aeat_mod340_intracomunitarias()