~vauxoo/openerp-venezuela-localization/ovl70-fr-rev-hbto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Vauxoo C.A. (http://openerp.com.ve/) All Rights Reserved.
#                    Javier Duran <javier@vauxoo.com>
#                    Nhomar Hernandéz <nhomar@vauxoo.com>
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

'''
Fiscal Report For Venezuela
'''

from osv import osv
from osv import fields
from tools.translate import _
from tools import config
from tools.sql import drop_view_if_exists
import decimal_precision as dp

class fiscal_reports_purchase(osv.osv):
    '''
    Modifying the object fiscal.reports.purchase
    '''
    _name = "fiscal.reports.purchase"
    _description = "Purchase by period"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _order = 'ai_nro_ctrl asc'
    _columns = {
        'ai_date_document': fields.date('Date'),
        'ai_date_invoice': fields.date('Date'),
        'ar_date_document': fields.date('Date Account Retencion'),
        'rp_vat':fields.char('VAT Number', size=24, required=False, readonly=True),
        'rp_id':fields.many2one('res.partner', 'Partner Name', required=True),
        'ai_nro_ctrl':fields.char('Control No.', size=128, required=False, readonly=True),
        'ai_reference':fields.char('Invoice Number', size=128, required=False, readonly=True),
        'ai_amount_total': fields.float('Amount Total', digits_compute= dp.get_precision('Fiscal Report')),
        'ai_amount_untaxed': fields.float('Untaxed Amount', digits_compute= dp.get_precision('Fiscal Report')),
        'ai_amount_tax': fields.float('Tax Amount', digits_compute= dp.get_precision('Fiscal Report')),
        'ai_type':fields.char('Document Type', size=64, required=False, readonly=False),
        'rp_retention': fields.float('Whitholding Rate', digits_compute= dp.get_precision('Fiscal Report')),
        'ai_id':fields.many2one('account.invoice', 'Invoice Description', required=False),
        'ar_line_id':fields.many2one('account.wh.iva.line', 'Account Retention', readonly=True),
        'ar_id':fields.many2one('account.wh.iva', 'Account Retention', readonly=True),
    }
    def init(self, cr):
        '''
        Create or replace view fiscal_reports_purchase
        '''
        drop_view_if_exists(cr, 'fiscal_reports_purchase')
        cr.execute("""
            create or replace view fiscal_reports_purchase as (
                SELECT
                     ai."date_document" AS ai_date_document,
                     ai."date_invoice" AS ai_date_invoice,
                     rp."vat" AS rp_vat,
                     rp."id" AS rp_id,
                     ai."nro_ctrl" AS ai_nro_ctrl,
                     ai."reference" AS ai_reference,
                     ar."date_ret" AS ar_date_document,
                case when ai.type='in_refund'
                then
                    ai."amount_total"*(-1)
                else
                    ai."amount_total" 
                end as ai_amount_total,
                case when ai.type='in_refund'
                then
                    ai."amount_untaxed"*(-1)
                else
                    ai."amount_untaxed" 
                end as ai_amount_untaxed,
                case when ai.type='in_refund'
                then
                    ai."amount_tax"*(-1)
                else
                    ai."amount_tax" 
                end as ai_amount_tax,
                     ai."type" AS ai_type,
                     rp."wh_iva_rate" AS rp_retention,
                     ai."id" AS id,
                     ai."id" AS ai_id,
                     ar_line."id" AS ar_line_id,
                     ar_line."retention_id" AS ar_id
                FROM
                     "res_partner" rp INNER JOIN "account_invoice" ai ON rp."id" = ai."partner_id"
                     LEFT JOIN "account_wh_iva_line" ar_line ON ar_line."invoice_id" = ai."id"
                     LEFT JOIN "account_wh_iva" ar ON ar_line."retention_id" = ar."id"                                                     
                WHERE
                     (ai.type = 'in_refund'
                  OR ai.type = 'in_invoice')
                 AND (ai.state = 'open'
                  OR ai.state = 'paid'
                  OR ai.state = 'done')
                ORDER BY
                     ai_date_invoice ASC,
                     ar."number" ASC
                 )
        """)
fiscal_reports_purchase()  

class fiscal_reports_sale(osv.osv):
    '''
    Modifying the object fiscal.reports.sales
    '''
    _name = "fiscal.reports.sale"
    _description = "Sale by period"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _columns = {
    'ai_date_document': fields.date('Date'),
    'ai_date_invoice': fields.date('Date'),
    'ar_date_document': fields.date('Date Account Retencion'),
    'rp_vat':fields.char('VAT Number', size=64, required=False, readonly=False),
    'rp_id':fields.many2one('res.partner', 'Partner Name', required=True),
    'ai_reference':fields.char('Invoice Number', size=64, required=False, readonly=False),
    'ai_nro_ctrl':fields.char('Control No.', size=64, required=False, readonly=False),
    'ai_amount_total': fields.float('Amount Total', digits_compute= dp.get_precision('Fiscal Report')),
    'ai_amount_untaxed': fields.float('Untaxed amount', digits_compute= dp.get_precision('Fiscal Report')),
    'ai_amount_tax': fields.float('Tax Amount', digits_compute= dp.get_precision('Fiscal Report')),
    'ai_type':fields.char('Type', size=64, required=False, readonly=False),
    'rp_retention': fields.float('Withholding', digits_compute= dp.get_precision('Fiscal Report')),
    'ai_id':fields.many2one('account.invoice', 'Invoice Description', required=False),
    'ar_line_id':fields.many2one('account.wh.iva.line', 'Account Retention', readonly=True),
    'ar_id':fields.many2one('account.wh.iva', 'Account Retention', readonly=True),
    }
    def init(self, cr):
        '''
        Create or replace view fiscal_reports_sale
        '''   
        drop_view_if_exists(cr, 'fiscal_reports_sale') 
        cr.execute("""
            create or replace view fiscal_reports_sale as (
                SELECT
                ai."date_document" AS ai_date_document,
                ai."date_invoice" AS ai_date_invoice,
                rp."vat" AS rp_vat,
                rp."id" AS rp_id,
                ai."number" AS ai_reference,
                ai."nro_ctrl" AS ai_nro_ctrl,
                ar."date_ret" AS ar_date_document,
                case when ai.type='out_refund'
                then
                    ai."amount_total"*(-1)
                else
                    ai."amount_total" 
                end as ai_amount_total,
                case when ai.type='out_refund'
                then
                    ai."amount_untaxed"*(-1)
                else
                    ai."amount_untaxed" 
                end as ai_amount_untaxed,
                case when ai.type='out_refund'
                then
                    ai."amount_tax"*(-1)
                else
                    ai."amount_tax" 
                end as ai_amount_tax,
                ai."type" AS ai_type,
                rp."wh_iva_rate" AS rp_retention,
                ai."id" AS id,
                ai."id" AS ai_id,
                ar_line."id" AS ar_line_id,
                ar_line."retention_id" AS ar_id
                FROM
                 "res_partner" rp INNER JOIN "account_invoice" ai ON rp."id" = ai."partner_id"
                 LEFT JOIN "account_wh_iva_line" ar_line ON ar_line."invoice_id" = ai."id"
                 LEFT JOIN "account_wh_iva" ar ON ar_line."retention_id" = ar."id"
                WHERE
                (ai.type = 'out_refund'
                OR ai.type = 'out_invoice')
                AND (ai.state = 'open'
                OR ai.state = 'paid'
                OR ai.state = 'done')
                ORDER BY
                ai_date_invoice ASC,
                ai."nro_ctrl" ASC
                )
        """)
fiscal_reports_sale()
class fiscal_reports_whp(osv.osv):
    '''
    Modifying the object fiscal.reports.whp
    '''
    _name = "fiscal.reports.whp"
    _description = "Purchase by period"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _columns = {
    'ar_date_ret': fields.date('Date ret.', readonly=True),
    'ai_date_inv': fields.date('Date Invoice'),
    'ar_date_document': fields.date('Date Account Retencion'),
    'rp_vat':fields.char('Vat Number', size=64, readonly=True),
    'rp_id':fields.many2one('res.partner', 'Partner', readonly=True),
    'ar_number':fields.char('Retention Number', size=64, required=False, readonly=True),
    'ai_reference':fields.char('Invoice Number', size=64, required=False, readonly=True),
    'ai_amount_total': fields.float('Amount Total', digits_compute= dp.get_precision('Fiscal Report')),
    'ai_amount_untaxed': fields.float('Amount Untaxed', digits_compute= dp.get_precision('Fiscal Report'), readonly=True),
    'ai_amount_tax': fields.float('Amount tax', digits_compute= dp.get_precision('Fiscal Report'), readonly=True),
    'ar_line_id':fields.many2one('account.wh.iva.line', 'Account Retention', readonly=True),
    'ai_id':fields.many2one('account.invoice', 'Account Invoice', readonly=True),
    'ar_id':fields.many2one('account.wh.iva', 'Account Retention', readonly=True),
    }
    def init(self, cr):
        '''
        Create or replace view fiscal_reports_whp
        '''    
        drop_view_if_exists(cr, 'fiscal_reports_whp')
        cr.execute("""
            create or replace view fiscal_reports_whp as (
                SELECT
                     ar."date_ret" AS ar_date_ret,
                     rp."vat" AS rp_vat,
                     ar."number" AS ar_number,
                     ai."reference" AS ai_reference,
                     ai."date_invoice" AS ai_date_inv,
                     ar."date" AS ar_date_document,
                    case when ai.type='in_refund'
                    then
                        ai."amount_total"*(-1)
                    else
                        ai."amount_total" 
                    end as ai_amount_total,
                    case when ai.type='in_refund'
                    then
                        ai."amount_tax"*(-1)
                    else
                        ai."amount_tax" 
                    end as ai_amount_tax,
                    case when ai.type='in_refund'
                    then
                        ai."amount_untaxed"*(-1)
                    else
                        ai."amount_untaxed" 
                    end as ai_amount_untaxed,
                     ar_line."id" AS id,
                     ar_line."id" AS ar_line_id,
                     ar."id" AS ar_id,
                     rp."id" AS rp_id,
                     ai."id" AS ai_id
                FROM
                     "account_wh_iva_line" ar_line INNER JOIN "account_wh_iva" ar ON ar_line."retention_id" = ar."id"
                     INNER JOIN "res_partner" rp ON ar."partner_id" = rp."id"
                     INNER JOIN "account_invoice" ai ON ar_line."invoice_id" = ai."id"
                WHERE
                    ar."state" = 'done'
                AND
                    (ai."type" = 'in_invoice' OR ai."type" = 'in_refund')
                    )
        """)
fiscal_reports_whp()

class fiscal_reports_whs(osv.osv):
    '''
    Modifying the object fiscal.reports.whs
    '''
    _name = "fiscal.reports.whs"
    _description = "Sale by period"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _columns = {
    'ar_date_ret': fields.date('Date'),
    'ai_date_inv': fields.date('Date Invoice'),
    'ar_date_document': fields.date('Date Account Retencion'),
    'rp_vat':fields.char('Vat Number', size=64, readonly=True),
    'rp_id':fields.many2one('res.partner', 'Partner Name', readonly=True),
    'ar_number':fields.char('WH Number', size=64, readonly=True),
    'ai_number':fields.char('Invoice Number', size=64, readonly=True),
    'ai_id':fields.many2one('account.invoice', 'Invoice', required=False, readonly=True),
    'ai_amount_total': fields.float('Invoice Total', digits_compute= dp.get_precision('Fiscal Report'), readonly=True),
    'ai_amount_untaxed': fields.float('Amount Untaxed', digits_compute= dp.get_precision('Fiscal Report'), readonly=True),
    'ar_line_id':fields.many2one('account.wh.iva.line', 'Account Retention', readonly=True),
    'ai_amount_tax': fields.float('Amount Tax', digits_compute= dp.get_precision('Fiscal Report'), readonly=True),
    'ar_id':fields.many2one('account.wh.iva', 'Retention', required=False, readonly=True),
    'ai_reference':fields.char('Invoice Number', size=64, required=False, readonly=True),
    }
    def init(self, cr):
        '''
        Create or replace view fiscal_reports_whs
        '''    
        drop_view_if_exists(cr, 'fiscal_reports_whs')
        cr.execute("""
            create or replace view fiscal_reports_whs as (
                SELECT
                     ar."date_ret" AS ar_date_ret,
                     rp."vat" AS rp_vat,
                     ar."number" AS ar_number,
                     ai."number" AS ai_reference,
                     ai."number" AS ai_number,
                     ai."date_invoice" AS ai_date_inv,
                     ar."date" AS ar_date_document,
                    case when ai.type='out_refund'
                    then
                        ai."amount_total"*(-1)
                    else
                        ai."amount_total" 
                    end as ai_amount_total,
                    case when ai.type='out_refund'
                    then
                        ai."amount_tax"*(-1)
                    else
                        ai."amount_tax" 
                    end as ai_amount_tax,
                    case when ai.type='out_refund'
                    then
                        ai."amount_untaxed"*(-1)
                    else
                        ai."amount_untaxed" 
                    end as ai_amount_untaxed,
                     ar_line."id" AS id,
                     ar_line."id" AS ar_line_id,
                     ar."id" AS ar_id,
                     rp."id" AS rp_id,
                     ai."id" AS ai_id
                FROM
                     "account_wh_iva_line" ar_line INNER JOIN "account_wh_iva" ar ON ar_line."retention_id" = ar."id"
                     INNER JOIN "res_partner" rp ON ar."partner_id" = rp."id"
                     INNER JOIN "account_invoice" ai ON ar_line."invoice_id" = ai."id"
                WHERE
                    ar."state" = 'done'
                AND
                    (ai."type" = 'out_invoice' OR ai."type" = 'out_refund')
                ORDER BY ar_date_ret
                )
        """)
fiscal_reports_whs()