1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# Created by Nicolas Bessi on 13.10.08.
6
# Copyright (c) 2008 CamptoCamp. All rights reserved.
7
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
8
# Jordi Esteve <jesteve@zikzakmedia.com>
10
# WARNING: This program as such is intended to be used by professional
11
# programmers who take the whole responsability of assessing all potential
12
# consequences resulting from its eventual inadequacies and bugs
13
# End users who are looking for a ready-to-use solution with commercial
14
# garantees and support are strongly adviced to contract a Free Software
17
# This program is Free Software; you can redistribute it and/or
18
# modify it under the terms of the GNU General Public License
19
# as published by the Free Software Foundation; either version 2
20
# of the License, or (at your option) any later version.
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU General Public License for more details.
27
# You should have received a copy of the GNU General Public License
28
# along with this program; if not, write to the Free Software
29
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31
##############################################################################
34
from mx.DateTime import *
35
from report import report_sxw
40
class print_invoice_list(rml_parse.rml_parse):
41
""" Report that print invoices grouped by currency and type """
42
_name = 'report.account.print_invoice_list'
45
def __init__(self, cr, uid, name, context):
46
super(print_invoice_list, self).__init__(cr, uid, name, context)
47
#contain tuples of in invoices : (curreny, [browse records], currency_untaxed, currency_tax, currency_total)
49
#contain tuples of in refunds : (curreny, [browse records], currency_untaxed, currency_tax, currency_total)
51
#contain tuples of out invoices : (curreny, [browse records], currency_untaxed, currency_tax, currency_total)
52
self.out_invoices = []
53
#contain tuples of out refunds : (curreny, [browse records], currency_untaxed, currency_tax, currency_total)
55
self.localcontext.update({
57
'in_invoices': self.in_invoices,
58
'in_refunds': self.in_refunds,
59
'out_invoices': self.out_invoices,
60
'out_refunds': self.out_refunds,
61
'detailed_taxes': False,
65
def set_context(self, objects, data, ids, report_type = None):
66
"""We do the grouping and proccessing of invoices"""
67
invoice_obj = self.pool.get('account.invoice')
69
if data['model'] == 'ir.ui.menu':
71
if data['form']['out_invoice']:
72
invoice_types.append('out_invoice')
73
if data['form']['out_refund']:
74
invoice_types.append('out_refund')
75
if data['form']['in_invoice']:
76
invoice_types.append('in_invoice')
77
if data['form']['in_refund']:
78
invoice_types.append('in_refund')
80
if data['form']['draft']:
81
invoice_states.append('draft')
82
if data['form']['proforma']:
83
invoice_states.append('proforma')
84
invoice_states.append('proforma2')
85
if data['form']['open']:
86
invoice_states.append('open')
87
if data['form']['paid']:
88
invoice_states.append('paid')
89
if data['form']['cancel']:
90
invoice_states.append('cancel')
91
where = [('company_id','=',data['form']['company_id']),('type','in',invoice_types),('state','in',invoice_states)]
92
if data['form']['state'] in ['byperiod','all']:
93
period_ids = data['form']['periods'][0][2]
94
periods = ','.join([str(id) for id in period_ids])
95
where.append(('period_id','in',period_ids))
96
if data['form']['state'] in ['bydate','all','none']:
97
where.append(('date_invoice','>=',data['form']['date_from']))
98
where.append(('date_invoice','<=',data['form']['date_to']))
100
ids = invoice_obj.search(self.cr, self.uid, where)
101
objects = invoice_obj.browse(self.cr, self.uid, ids)
103
self.localcontext.update({
104
'detailed_taxes': data['form'].get('detailed_taxes'),
108
return super(print_invoice_list, self).set_context(objects, data, ids, report_type)
110
if not isinstance(ids, list) :
112
# we create temp list that will be used for store invoices by type
117
# we get the invoices and sort them by types
118
invoices = invoice_obj.browse(self.cr, self.uid, ids)
119
for inv in invoices :
120
if inv.type == ('in_invoice'):
122
if inv.type == ('in_refund'):
124
if inv.type == ('out_invoice'):
126
if inv.type == ('out_refund'):
128
# we process the invoice and attribute them to the property
129
self.filter_invoices(ininv, self.in_invoices)
130
self.filter_invoices(outinv, self.out_invoices)
131
self.filter_invoices(inref, self.in_refunds)
132
self.filter_invoices(outref, self.out_refunds)
133
super(print_invoice_list, self).set_context(objects, data, ids, report_type)
136
def filter_invoices(self, list, dest) :
140
#We sort the invoice by currency in a tmp dict
141
#{'currency':[browse, records]}
143
currency = inv.currency_id.name
144
if tmp.has_key(currency) :
145
tmp[currency].append(inv)
147
tmp[currency] = [inv]
148
#We compute the total by currency
150
untaxed = tax = total = 0
151
for tmpinv in tmp[curr]:
152
untaxed += tmpinv.amount_untaxed
153
tax += tmpinv.amount_tax
154
total += tmpinv.amount_total
155
#We append the tuple to the property
156
dest.append((curr, tmp[curr], untaxed, tax, total))
160
report_sxw.report_sxw('report.account.invoice.list.report', 'account.invoice', 'addons/account_financial_report/report/invoice_list.rml', parser=print_invoice_list, header=False)