addinglu
[odoo/odoo.git] / addons / l10n_lu / wizard / print_vat.py
1 # -*- encoding: utf-8 -*-
2 #Copyright (c) Vincent Cardon <vincent.cardon@tranquil-it-systems.fr>
3 # Denis Cardon <denis.cardon@tranquilitsystems.com> and Emmanuel RICHARD.
4 #Ingenieur fondateur
5 #Tranquil IT Systems
6
7
8 import wizard
9 import time
10 import datetime
11 import pooler
12 import sys
13 from mx.DateTime import *
14 import tools
15 from report.render import render 
16 from report.interface import report_int
17 import os
18
19 _tax_form = """<?xml version="1.0"?>
20 <form string="VAT Legal Declaration">
21     <field name="tax_code_id"/>
22     <field name="period_id"/>
23 </form>"""
24
25 _tax_fields = {
26     'tax_code_id': {
27         'string': 'Company',
28         'type': 'many2one',
29         'relation': 'account.tax.code',
30         'required': True,
31         'domain': [('parent_id','=',False)]},
32     'period_id': {
33         'string':'Period',
34         'type': 'many2one',
35         'relation': 'account.period',
36         'required':True
37     }
38 }
39
40 class external_pdf(render):
41     def __init__(self, pdf):
42         render.__init__(self)
43         self.pdf = pdf
44         self.output_type='pdf'
45     def _render(self):
46         return self.pdf
47
48
49 class report_custom(report_int):
50     def create(self, cr, uid, ids, datas, context={}):
51         print datas, ids, uid
52
53         taxobj = self.pool.get('account.tax.code')
54         code_ids = taxobj.search(cr, uid, [('parent_id','child_of',[datas['form']['tax_code_id']])])
55         result = {}
56         for t in taxobj.browse(cr, uid, code_ids, {'period_id': datas['form']['period_id']}):
57             if t.code:
58                 result[t.code] = t.sum_period
59         os.system('pdftk... output /tmp/tax.pdf')
60         self.obj = external_pdf(file('/tmp/tax.pdf').read())
61         self.obj.render()
62
63         pdf_string.close()
64         return (self.obj.pdf, 'pdf')
65
66 report_custom('report.l10n_lu.tax.report.print')
67
68
69 class wizard_report(wizard.interface):
70     states = {
71         'init': {
72              'actions': [],
73              'result': {'type':'form', 'arch':_tax_form, 'fields':_tax_fields, 'state':[('end','Cancel'),('pdf','Print Balance Sheet')]},
74         },
75         'pdf': {
76             'actions': [],
77             'result': {'type':'print', 'report': 'l10n_lu.tax.report.print', 'state':'end'},
78         },
79     }
80 wizard_report('l10n_lu.tax.report.wizard')
81