Hi every one. My question is, somehow, related to my previous question. How can i create .DAT, .csv, .ods, or even .xls , so that user can have a softcopy of the files. For example, user want to have the copy of list of all pupils in a .DAT then he can download it. Any one can help?
----------------------------
EDIT
Thank you sir for your answer, actually i did what you have told me, but i got an error, or perhaps my code is far way from reality. I made a class named 'file.holder' just like this one:
class file_holder(osv.osv):
_name = 'file.holder'
_columns = { 'name' : fields.char('File name'),
'file_data' : fields.binary('File Name',filters='*.DAT',)
}
def get_file(self, cr, uid, context=None):
file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT')
fo = {} fo = open(file_path,"wb")
active_id = self.pool.get('student.student').search(cr,uid,[])
for list in self.browse(cr,uid,active_id,context=context):
fo.write(list.id+","+list.name) self.create(cr,uid,{ 'name' : '', 'file_data' : file_path })
return fo.read().encode('base64')
file_holder()
where addons is a folder in openerpserver-7, mp_seven is my project name, files is subfolder in my project and where studentlist.DAT resides. Whenever this method is bieng called in other class the browser/terminal says :
file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT')
NameError: global name 'addons' is not defined
------------------------------------------------------------------------
RE EDIT:
Sir, this is how i implement your pseudo code, but my problem now is that my return view doesn't show anything (on my file.holder class):
def file_writer(self, cr, uid, ids, context=None):
virtual_file = StringIO.StringIO()
student_object = self.pool.get('student.student')
active_id = student_object.search(cr,uid,[])
for obj_list in student_object.browse(cr,uid,active_id,context=context):
virtual_file.write(str(obj_list.last_name)+","+str(obj_list.first_name)+","+str(obj_list.middle_name))
self.create(cr,uid,{ 'name' : 'studentList.DAT', 'file_data' : virtual_file })
return { 'type': 'ir.actions.act_window',
'res_model': 'file.holder',
'view_mode': 'form',
'view_type': 'form',
'views': [(False, 'form')],
'target': 'new', }
this is how i called it in my "student.student" class
def call_file_writer(self,cr,uid,ids,context=None):
return self.pool.get('file.holder').file_writer(cr,uid,ids,context=context)
def loadstudent(self,cr,uid,ids,context=None):
.....
return self.call_file_writer(cr, uid, ids, context=context)
When the view is rendered, it shows only the two fields without it's object.