~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_invoice/wizard/wizard_invoice_report.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 wizard
 
30
import pooler
 
31
 
 
32
dates_form = '''<?xml version="1.0"?>
 
33
<form string="Seleccion de Facturas">
 
34
        <field name="company_id"/>
 
35
        <newline/>
 
36
        <field name="partner_id"/>
 
37
        <field name="type"/>
 
38
        <newline/>
 
39
        <field name="date_start"/>
 
40
        <field name="date_end"/>
 
41
        <newline/>
 
42
        <field name="based_on"/>
 
43
        <field name="order_by"/>
 
44
</form>'''
 
45
 
 
46
dates_fields = {
 
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':[
 
52
                        ('all','All'),
 
53
                        ('open','Open'),
 
54
                        ('paid','Paid '),
 
55
                        ('all_but_cancelled','All but cancel'),
 
56
                        ], 'required':True, 'default': lambda *a: 'all'},
 
57
        'order_by':{'string':'Order by', 'type':'selection', 'selection':[
 
58
                        ('date','Date'),
 
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')},
 
71
}
 
72
 
 
73
 
 
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)
 
80
        if user.company_id:
 
81
            company_id = user.company_id.id
 
82
        else:
 
83
            company_id = pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
 
84
        data['form']['company_id'] = company_id
 
85
        return data['form']
 
86
 
 
87
    def _check(self, cr, uid, data, context):
 
88
        form = data['form']
 
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']]
 
91
        partner_query = ''
 
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 " \
 
99
                ""+partner_query+"" \
 
100
                                ""+line_query+"" \
 
101
                                "AND type = '"+form['type']+"' "+order_query+"",(form['date_start'],form['date_end']))
 
102
        res = cr.fetchall()
 
103
        if not res:
 
104
            raise wizard.except_wizard(('No Data Available'), ('No records found for your selection!'))
 
105
        return 'report'
 
106
 
 
107
 
 
108
    states = {
 
109
                'init': {
 
110
                        'actions': [_get_defaults],
 
111
                        'result': {
 
112
                                'type': 'form',
 
113
                                'arch': dates_form,
 
114
                                'fields': dates_fields,
 
115
                                'state': [
 
116
                                        ('end', 'Cancel'),
 
117
                                        ('check', 'Print')
 
118
                                ]
 
119
                        }
 
120
                },
 
121
        'check': {
 
122
            'actions': [],
 
123
            'result': {'type':'choice','next_state':_check}
 
124
        },
 
125
                'report': {
 
126
                        'actions': [],
 
127
                        'result': {
 
128
                                'type': 'print',
 
129
                                'report': 'account.invoice.report',
 
130
                                'state':'end'
 
131
                        }
 
132
                }
 
133
        }
 
134
 
 
135
wizard_report('account.invoice.report')
 
136
 
 
137
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: