Saturday, April 27, 2013

OpenERP-export file csv unicode


import base64
from osv import fields,osv
from tools.translate import _
import time

class Report(osv.osv_memory):
    """
    Wizard to create custom report
    """
    _name = "report"
    _description = "Create Report"
    _columns = {
                'start_date' : fields.date('Start Date', required=True),
                'end_date' : fields.date('End Date', required=True),
                'data': fields.binary('File', readonly=True),
                'name': fields.char('Filename', 16, readonly=True),
                'state': fields.selection( ( ('choose','choose'),   # choose date
                     ('get','get'),         # get the file
                   ) ),
                }
   
    def create_report(self,cr,uid,ids,context={}):
        this = self.browse(cr, uid, ids)[0]
        output = 'Start;Ende'
        output += '\n' + this.start_date + ';' + this.end_date
        print this.start_date
        out=base64.encodestring(output)
        return self.write(cr, uid, ids, {'state':'get', 'data':out, 'name':'test.csv'}, context=context)
       
    _defaults = {
                 'state': lambda *a: 'choose',
                 'start_date' : lambda *a: time.strftime('%Y-%m-%d'),
                 'end_date' : lambda *a: time.strftime('%Y-%m-%d'),
                }

   
Report()
************************************************
report.xml
************************************************



   
   
           
   
       
            Custom Report
            report
            form
            16
           
               

                   
                       
                       
                       
                       
                       
                           

                       
                   

                   
                       
                       
                       
                   

               

           

       

       
           
       
       
            Custom Report
            report
            form
            form
            new
       

       
       
                            action="action_report"
                    parent="account.menu_finance_reporting"
                    sequence="40" />
       
       
   

 

No comments: