rename the report Déclaration TVA by Taxes Statement
[odoo/odoo.git] / addons / account_voucher / report / tax_report.py
1 ##############################################################################
2 #
3 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsability of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # garantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 #
26 ##############################################################################
27
28 import time
29 import pooler
30 from report import report_sxw
31
32 class account_tax_report(report_sxw.rml_parse):
33     def __init__(self, cr, uid, name, context):
34         super(account_tax_report, self).__init__(cr, uid, name, context)
35         self.localcontext.update({
36             'get_invoice': self.getInvoices,
37             'add_invoice': self.addInvoice,
38             'get_tax': self.getTax,
39             'get_tax_detail' : self.getTaxDetail,
40             'get_retail' : self.getRetailTax,
41             'get_retail_detail' : self.getRetailTaxDetail,
42             'get_local_sale' : self.getLocalSale,
43             'get_retail_sale' : self.getRetailSale,
44             'total_local_sale' : self.getTotalLocalSale,
45             'total_local_tax' : self.getTotalLocalTax,
46             'total_retail_sale' : self.getTotalRetailSale,
47             'total_retail_tax' : self.getTotalRetailTax,
48             'time': time,
49             'get_period': self.getPeriod,
50             'test' : self.testMethod,
51             
52         })
53         self.local = 0
54         self. retail = 0
55         
56         self.tax_tax = {}
57         self.retail_tax = {}
58         
59         self.sale_tax = {}
60         self.sale_retail = {}
61         
62         self.total_local_sale = 0
63         self.total_local_tax = 0
64         
65         self.total_retail_sale = 0
66         self.total_retail_tax = 0
67         
68         self.invoices = []
69         self.flag = False
70     #end def
71     
72     def getPeriod(self, period_id):
73         return self.pool.get('account.period').browse(self.cr, self.uid, period_id).name
74     #end def
75     
76     def testMethod(self, obj):
77         print type(obj) == type({}), obj;
78         if type(obj) == type({}) and not self.flag:
79             if obj.has_key('form'):
80                 self.flag = True
81                 ids = self.pool.get('account.move.line').search(self.cr, self.uid, [('period_id','=',obj['form']['period_id'])])
82                 account = self.pool.get('account.move.line').read(self.cr, self.uid,ids,['invoice'])
83                 invoice_ids = []
84                 for i in account:
85                     if i['invoice'][0]:
86                         if not i['invoice'][0] in invoice_ids:
87                             inv = self.pool.get('account.invoice').browse(self.cr, self.uid,i['invoice'][0]) 
88                             if inv.type == 'out_invoice' and inv.state == 'open':
89                                 if not i['invoice'][0] in self.invoices:
90                                     print '*********************** : ',i['invoice'][0]
91                                     self.invoices.append(i['invoice'][0])
92                         #end if
93                     #end if
94                 #end for
95             #end if
96         elif self.flag == False:
97             self.invoices = self.ids
98         #end if
99     #end def
100     
101     def getInvoices(self):
102         print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',self.invoices;
103         return self.pool.get('account.invoice').browse(self.cr, self.uid, self.invoices)
104     #end def
105     
106     def addInvoice(self, invoice):
107         if invoice.retail_tax == 'tax':
108             self.total_local_sale += invoice.amount_untaxed
109             self.total_local_tax += invoice.amount_tax
110             
111             for tax in invoice.tax_line:
112                 if self.tax_tax.has_key(tax.name):
113                     self.tax_tax[tax.name] += tax.tax_amount
114                     self.sale_tax[tax.name] += tax.base_amount
115                 else:
116                     self.tax_tax[tax.name] = tax.tax_amount
117                     self.sale_tax[tax.name] = tax.base_amount
118             #end for
119         elif invoice.retail_tax == 'retail':
120             self.total_retail_sale += invoice.amount_untaxed
121             self.total_retail_tax += invoice.amount_tax
122             self. retail += invoice.amount_total
123             for tax in invoice.tax_line:
124                 if self.retail_tax.has_key(tax.name):
125                     self.retail_tax[tax.name] += tax.tax_amount
126                     self.sale_retail[tax.name] += tax.base_amount
127                 else:
128                     self.retail_tax[tax.name] = tax.tax_amount
129                     self.sale_retail[tax.name] = tax.base_amount
130                 #end if
131             #end for
132         #endif
133     #end def
134     
135     def getTaxDetail(self, tax):
136         return self.tax_tax[tax];
137     
138     def getTax(self):
139         tax = []
140         for i in self.tax_tax:
141             tax.append(i)
142         return tax
143     #end if
144     
145     def getRetailTaxDetail(self, tax):
146         return self.retail_tax[tax];
147     
148     def getRetailTax(self):
149         tax = []
150         for i in self.retail_tax:
151             tax.append(i)
152         return tax
153     #end if
154     
155     def getLocalSale(self, tax):
156         return self.sale_tax[tax]
157     #end def
158     
159     def getRetailSale(self, tax):
160         return self.sale_retail[tax]
161     #end def
162     
163     def getTotalLocalSale(self):
164         return self.total_local_sale
165     #end def
166     
167     def getTotalLocalTax(self):
168         return self.total_local_tax
169     #end def
170     
171     def getTotalRetailSale(self):
172         return self.total_retail_sale
173     #end def
174     
175     def getTotalRetailTax(self):
176         return self.total_retail_tax
177     #end def
178 #end class
179
180 report_sxw.report_sxw(
181     'report.indianvat.declaration',
182     'account.invoice',
183     'addons/india/account/report/tax_report.rml',
184     parser=account_tax_report,
185 )