~openerp-chinese-team/openerp-china/openerp-china

« back to all changes in this revision

Viewing changes to shineit_mm/shineit_mm/wizard/wizard_mm_report.py

  • Committer: JoshuaJan
  • Date: 2012-02-21 03:21:40 UTC
  • Revision ID: joshua@openerp.cn-20120221032140-4wwk95ftpf9x24ec
change the shipped date for report MM

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- #
 
2
 
 
3
import time
 
4
from osv import osv, fields
 
5
 
 
6
PURPOSE_MAPS = {
 
7
    'production':'Production',
 
8
    'sample':'Sale Sample',
 
9
    'development':'Development',
 
10
}
 
11
class mm_report(osv.osv_memory):
 
12
    _name = 'mm.report'
 
13
    _description = 'MM Report'        
 
14
    _columns = {
 
15
        'year':fields.many2one('account.fiscalyear', 'Year', required=True),
 
16
        'purpose':fields.selection([('production', 'PRODUCTION'),('sample', 'SQLE SAMPLE'),('development','DEVELOPMENT')], 'Purpose', required=True),   
 
17
        'report_type':fields.selection([('pdf','PDF'),('odt','ODT')],'Rrport Type', required=True),
 
18
    }
 
19
    
 
20
    _defaults = {
 
21
        'report_type':'pdf',
 
22
    }
 
23
 
 
24
    def print_report(self, cr, uid, ids, context=None):
 
25
        '''
 
26
        To get the date and print the report
 
27
        @return : return report
 
28
        '''
 
29
        if context is None:
 
30
            context = {}
 
31
        report_obj = self.pool.get('ir.actions.report.xml')
 
32
        datas={'ids':context.get('active_ids',[])}
 
33
        res = self.read(cr, uid, ids, ['year','purpose','report_type'], context=context)
 
34
        print 'res-->',res
 
35
        year = self.pool.get('account.fiscalyear').browse(cr, uid, res[0]['year'])
 
36
        datas['purpose'] = res[0]['purpose']
 
37
        datas['purpose_name'] = PURPOSE_MAPS.get(res[0]['purpose'], False)
 
38
        datas['report_type'] = res[0]['report_type']
 
39
        datas['year_start'] = year.date_start
 
40
        datas['year_stop'] = year.date_stop
 
41
        datas['year'] = time.strftime('%Y',time.strptime(year.date_start,'%Y-%m-%d'))
 
42
        report_name = 'sample_mm'
 
43
        if res[0]['purpose'] == 'production':
 
44
            report_name = 'production_mm' 
 
45
        report_ids = report_obj.search(cr, uid, [('report_name','=',report_name)])
 
46
        report_obj.write(cr, uid, report_ids[0], {'report_type':res[0]['report_type']})
 
47
        return {
 
48
            'type':'ir.actions.report.xml',
 
49
            'report_name':report_name,
 
50
            'datas':datas,
 
51
        }
 
52
 
 
53
    
 
54
     
 
55
mm_report()
 
56
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
57