~zaber/openobject-addons/zaber-custom-base_report_creator

« back to all changes in this revision

Viewing changes to base_report_creator/wizard/wiz_dates.py

  • Committer: Aki Mimoto
  • Date: 2013-05-07 15:02:50 UTC
  • Revision ID: aki+launchpad@zaber.com-20130507150250-tcyuxaue9g8orvo8
[IMP] Initial commit of theproventech's base_report_creator fixes for 6.1 (to work in web client)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#    
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2012 credativ (<http://www.credativ.co.uk>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
 
 
24
class date_wizard(osv.osv_memory):
 
25
    _name = "base_report_creator.date_wizard"
 
26
    _description = "Enter Dates for Report"
 
27
    _columns = {
 
28
        'from_menu':fields.boolean('From a menu item?'),
 
29
        'from_date':fields.date('Date From', required=True),
 
30
        'to_date':fields.date('Date To', required=True),
 
31
    }
 
32
    _defaults = {
 
33
        'from_menu': False,
 
34
    }
 
35
    
 
36
    def report_run(self, cr, uid, ids, context=None):
 
37
        data = self.browse(cr, uid, ids, context=context)
 
38
        report_id = context.get('report_id', False)
 
39
        obj_board = self.pool.get('base_report_creator.report')
 
40
        data_obj = self.pool.get('ir.model.data')
 
41
        result = {}
 
42
        
 
43
        if report_id:
 
44
            board = obj_board.browse(cr, uid, report_id, context=context)
 
45
            view = board.view_type1
 
46
            if board.view_type2:
 
47
                view += ',' + board.view_type2
 
48
            if board.view_type3:
 
49
                view += ',' + board.view_type3
 
50
            result = data_obj._get_id(cr, uid, 'base_report_creator', 'view_report_filter')
 
51
            res = data_obj.read(cr, uid, result, ['res_id'])
 
52
            
 
53
            result = {
 
54
                'name': board.name,
 
55
                'view_type': 'form',
 
56
                'view_mode': view,
 
57
                'res_model': 'base_report_creator_report.result',
 
58
                'search_view_id': res['res_id'],
 
59
                'type': 'ir.actions.act_window',
 
60
            }
 
61
            
 
62
        if result and data and data[0].from_date and data[0].to_date and context.get('report_id', False):
 
63
            result['context'] = repr({
 
64
                    'report_id': board.id,
 
65
                    'dates': {
 
66
                                'from_date': data[0].from_date,
 
67
                                'to_date': data[0].to_date,
 
68
                             },
 
69
                })
 
70
            return result
 
71
        else:
 
72
            # We should log an error here
 
73
            return {'type': 'ir.actions.act_window_close'}
 
74
 
 
75
date_wizard()
 
76
 
 
77
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
78
 
 
79