1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
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
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.
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.
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.
26
##############################################################################
32
dates_form = '''<?xml version="1.0"?>
33
<form string="Seleccion de Facturas">
34
<field name="company_id"/>
36
<field name="partner_id"/>
39
<field name="date_start"/>
40
<field name="date_end"/>
42
<field name="based_on"/>
43
<field name="order_by"/>
47
'company_id': {'string': 'Company', 'type': 'many2one',
48
'relation': 'res.company', 'required': True},
49
'partner_id': {'string': 'Partner', 'type': 'many2one',
50
'relation': 'res.partner', 'required': False},
51
'based_on':{'string':'State', 'type':'selection', 'selection':[
55
('all_but_cancelled','All but cancel'),
56
], 'required':True, 'default': lambda *a: 'all'},
57
'order_by':{'string':'Order by', 'type':'selection', 'selection':[
59
('partner','Partner'),
60
], 'required':False, 'default': lambda *a: 'date'},
61
'type':{'string':'Invoice Type', 'type':'selection', 'selection':[
62
('out_invoice','Customer Invoice'),
63
('in_invoice','Supplier Invoice'),
64
('out_refund','Customer Refund'),
65
('in_refund','Supplier Refund'),
66
], 'required':False, 'default': lambda *a: 'out_invoice'},
67
'date_start': {'string': 'Start Date', 'type': 'date',
68
'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
69
'date_end': {'string': 'End Date', 'type': 'date',
70
'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
74
class wizard_report(wizard.interface):
75
def _get_defaults(self, cr, uid, data, context):
76
pool = pooler.get_pool(cr.dbname)
77
period_obj = pool.get('account.period')
78
data['form']['period_id'] = period_obj.find(cr, uid)[0]
79
user = pool.get('res.users').browse(cr, uid, uid, context=context)
81
company_id = user.company_id.id
83
company_id = pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
84
data['form']['company_id'] = company_id
87
def _check(self, cr, uid, data, context):
89
dic = {'date': 'ORDER BY date_invoice, partner_id, number', 'partner': 'ORDER BY partner_id, date_invoice, number'}
90
order_query = dic[form['order_by']]
92
if form['partner_id']:
93
partner_query = " AND partner_id = "+str(form['partner_id'])+" "
94
dic = {'paid_in': "AND state IN ('paid')", 'all': "", 'all_but_cancelled': "AND state IN ('open','paid')",
95
'open': "AND state IN ('open')", 'paid': "AND state IN ('paid')"}
96
line_query = dic[form['based_on']]
97
cr.execute("SELECT id, number FROM account_invoice " \
98
"WHERE date_invoice between %s AND %s " \
101
"AND type = '"+form['type']+"' "+order_query+"",(form['date_start'],form['date_end']))
104
raise wizard.except_wizard(('No Data Available'), ('No records found for your selection!'))
110
'actions': [_get_defaults],
114
'fields': dates_fields,
123
'result': {'type':'choice','next_state':_check}
129
'report': 'account.invoice.report',
135
wizard_report('account.invoice.report')
137
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: