1
# -*- encoding: utf-8 -*-
3
# Copyright (c) 2010 CamptoCamp. All rights reserved.
4
##############################################################################
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
30
from report import report_sxw
31
from tools import config
32
from tools.translate import _
34
class VATReportPaymentReportFull(report_sxw.rml_parse):
35
_name = 'report.account.vat.declaration.full'
36
def __init__(self, cr, uid, name, context):
37
super(VATReportPaymentReportFull, self).__init__(cr, uid, name, context=context)
38
self.localcontext.update({
40
'get_codes': self._get_codes,
41
'get_company': self._get_company,
42
'get_currency': self._get_currency,
43
'get_lines' : self._get_lines,
45
def _create_tax_code_dict_full(self,cr,uid,context):
47
if self.pool.get('account.tax.code')._get_company(cr, uid, context):
48
tax_code_obj_list = self.pool.get('account.tax.code').search(cr, uid, ['company_id','=',context['company_id']])
50
tax_code_obj_list = self.pool.get('account.tax.code').search(cr, uid, [])
52
for tax_id in tax_code_obj_list:
53
full_obj = { 'amount' : 0.0,
56
tax_list[tax_id] = full_obj
57
## Add Specific id to 0 for untaxes amount
58
full_obj = { 'amount' : 0.0,
61
tax_list[0] = full_obj
63
## This function compute tax based on invoice for an range of date
65
def _construct_full_line(self,form,datee):
66
### Get all line concerned
67
context = {'date_from': form['date_from'],'date_to':form['date_to'],'company_id':form['company_id']}
68
tax_code_obj = self.pool.get('account.tax.code')
69
ids = tax_code_obj.search(self.cr, self.uid, [('company_id','=',context['company_id'])])
70
tax_obj = self.pool.get('account.tax.code')
71
thier_lines = tax_obj.getthirdpartylines(self.cr,self.uid,ids,datee,context)
72
tax_dict = self._create_tax_code_dict_full(self.cr, self.uid, context)
73
for line in thier_lines:
74
## Compute payment for this line
75
if line['debit'] != 0.0:
76
tmp_base_amount = abs(line['debit'])
78
tmp_base_amount = abs(line['credit'])
80
payment_total = tax_obj.getpaymentforaline(self.cr, self.uid, line,datee)
81
prorata = tax_obj.compute_prorate(tmp_base_amount,payment_total)
82
for prodline in tax_obj.getlinefortax(self.cr,self.uid,context,line):
83
if prodline['debit'] != 0.0:
84
amount_tax = 0 - abs(prodline['debit'])
86
amount_tax = abs(prodline['credit'])
87
## Get invoice for move_if one
88
invoice_obj = self.pool.get('account.invoice')
89
invoice_ids = invoice_obj.search(self.cr,self.uid,[('move_id','=',prodline['move_id'])])
91
invoice_number = invoice_obj.browse(self.cr,self.uid,invoice_ids)[0].number
95
## Get partner name for move_if one
96
partner_obj = self.pool.get('res.partner')
97
if prodline['partner_id']:
98
partner_name = partner_obj.browse(self.cr,self.uid,[prodline['partner_id']])[0].name
102
## Get move name for move_if one
103
move_obj = self.pool.get('account.move')
104
if prodline['move_id']:
105
move_name = move_obj.browse(self.cr,self.uid,[prodline['move_id']])[0].name
109
prod_val = { 'name' : prodline['name'],
110
'move_name' : move_name,
111
'prorat_amount' : round(amount_tax * prorata, int(config['price_accuracy'])),
112
'prorata': str(round(prorata * 100, int(config['price_accuracy']))) + '%',
113
'invoice' : invoice_number,
114
'partner' : partner_name
116
prodline['vat_prorata_amount'] = amount_tax * prorata
117
if tax_dict.has_key(prodline['tax_code_id']) :
118
tax_dict[prodline['tax_code_id']]['amount'] = tax_dict[prodline['tax_code_id']]['amount'] + amount_tax * prorata
119
tax_dict[prodline['tax_code_id']]['invoices_link'].append(prod_val)
121
tax_dict[0]['amount'] = tax_dict[0]['amount'] + amount_tax * prorata
122
tax_dict[0]['invoices_link'].append(prod_val)
123
for record in tax_code_obj.browse(self.cr, self.uid, ids, context):
124
def _rec_get(record):
125
if tax_dict.has_key(record.id):
126
amount = tax_dict[record.id]['amount']
129
for rec in record.child_ids:
130
amount += _rec_get(rec) * rec.sign
132
tax_dict[record.id]['amount'] = round(_rec_get(record), int(config['price_accuracy']))
135
def _get_lines(self,form,company_id=False, parent=False, level=0):
137
list_code = self._get_codes(company_id, parent, level)
138
tc = self.pool.get('account.tax.code')
139
if form['date_to_from'] == 'date_to':
140
ThirdParty = self._construct_full_line(form,form['date_to'])
142
ThirdParty = self._construct_full_line(form,form['date_from'])
144
for id_tab in list_code:
146
tax_info = tc.browse(self.cr, self.uid, id_tab[1])
147
#print str(list_code[id])
149
'name':tax_info.name,
151
'amount':ThirdParty[id_tab[1]]['amount'],
152
'invoice_link' :ThirdParty[id_tab[1]]['invoices_link']
154
result.append(res_pot)
156
## Add amount without tax
157
res_pot_without_tax = {
158
'name':_('Amount without VAT'),
160
'amount': ThirdParty[0]['amount'],
161
'invoice_link' :ThirdParty[0]['invoices_link']
163
result.append(res_pot_without_tax)
168
def _get_codes(self, company_id, parent=False, level=0):
169
tc = self.pool.get('account.tax.code')
170
ids = tc.search(self.cr, self.uid, [('parent_id','=',parent),('company_id','=',company_id)])
173
for code in tc.browse(self.cr, self.uid, ids):
174
res.append(('.'*2*level,code.id))
176
res += self._get_codes(company_id, code.id, level+1)
180
def _get_company(self, form):
181
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
183
def _get_currency(self, form):
184
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
189
report_sxw.report_sxw('report.account.vat.payment.declaration.full', 'account.tax.code',
190
'addons/c2c_vat_report_payment/report/vat_report_payment_full.rml', parser=VATReportPaymentReportFull, header=False)