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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*- #

import time
from osv import osv, fields

class mm_report(osv.osv_memory):
    _name = 'mm.report'
    _description = 'MM Report'        
    _columns = {
        'year':fields.many2one('account.fiscalyear', 'Year', required=True),
        'inv_type':fields.many2one('sale_journal.invoice.type','Type',required=True),   
        'report_type':fields.selection([('pdf','PDF'),('odt','ODT')],'Rrport Type', required=True),
    }
    
    _defaults = {
        'report_type':'pdf',
    }
    def print_report(self, cr, uid, ids, context=None):
        '''
        To get the date and print the report
        @return : return report
        '''
        if context is None:
            context = {}
        report_obj = self.pool.get('ir.actions.report.xml')
        datas={'ids':context.get('active_ids',[])}
        res = self.read(cr, uid, ids, ['year','inv_type','report_type'], context=context)
        print 'res-->',res
        year = self.pool.get('account.fiscalyear').browse(cr, uid, res[0]['year'])
        inv_type = self.pool.get('sale_journal.invoice.type').browse(cr, uid, res[0]['inv_type'])
    
        datas['inv_type'] = res[0]['inv_type']
        datas['report_type'] = res[0]['report_type']
        datas['year_start'] = year.date_start
        datas['year_stop'] = year.date_stop
        datas['year'] = time.strftime('%Y',time.strptime(year.date_start,'%Y-%m-%d'))
        datas['inv_type_name'] = inv_type.name
        report_ids = report_obj.search(cr, uid, [('report_name','=','mm')])
        report_obj.write(cr, uid, report_ids[0], {'report_type':res[0]['report_type']})
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'mm',
            'datas': datas,
       }
mm_report()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: