Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
Openerp 7 wizard output file type unknown
In openerp 7 wizard the below code
_columns = {
'name': fields.char('Form Name', size=32, readonly=True),
'data': fields.binary('XML', readonly=True),
}
_defaults = {
'name': lambda *a:'employeedata.txt',
}
<record id="view_employee_createxml" model="ir.ui.view">
<field name="name">employee.createxml.form</field>
<field name="model">employee.createxml</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Employee Data">
<group colspan="4" >
<field name="name" colspan="4"/>
<field name="data" colspan="4"/>
</group>
</form>
</field>
The code get the below output: Actual Output:
File name: employee.createxml File Type: Unknown File Type
How to get the below output? Expected Output:
File name: employeedata File Type: .txt
Openerp Version 7 Source code:
addons\web\controllers\main.py
def saveas_ajax(self, req, data, token):
jdata = simplejson.loads(data)
model = jdata['model']
field = jdata['field']
data = jdata['data']
id = jdata.get('id', None)
filename_field = jdata.get('filename_field', None)
context = jdata.get('context', {})
Model = req.session.model(model)
fields = [field]
if filename_field:
fields.append(filename_field)
if data:
res = { field: data }
elif id:
res = Model.read([int(id)], fields, context)[0]
else:
res = Model.default_get(fields, context)
filecontent = base64.b64decode(res.get(field, ''))
if not filecontent:
raise ValueError(_("No content found for field '%s' on '%s:%s'") %
(field, model, id))
else:
filename = '%s_%s' % (model.replace('.', '_'), id)
if filename_field:
filename = res.get(filename_field, '') or filename
return req.make_response(filecontent,
headers=[('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename, req))],
cookies={'fileToken': int(token)})
In the above source code res dict contain only data key so output filename generate with model name and file type None
filename = '%s_%s' % (model.replace('.', '_'), id)
The below code not executed:
if filename_field:
filename = res.get(filename_field, '') or filename
so in the Custom wizard how to set filename_field and filename based on the above code?....
You need to encode content of that text file with base64 lib and return it.
Create a new function for defaults and call it from _defaults like this:
def _get_data(self, cr, uid, context=None):
#READ CONTENT OF THAT TEXT FILE AND ENCODE IT WITH BASE64 LIB
import base64
return base64.encodestring(CONTENT_OF_TEXT_FILE)
'data': _get_data
Thanks, Priyesh Solanki
Thanks for reply already encode content added but In openerp version 7 not working the same code working in version 6.0.4 How to solve issue in version 7? Thanks Please see the below main.py source code
Thanks for reply already encoded the content
The below Code working in the openerp 6.0.4 version But openerp 7 version return File Type unknown? How to solve this issue in version 7?
def default_get(self, cr, uid, fields, context=None):
res = super(employee_create_text, self).default_get(cr, uid, fields, context=context)
pool = pooler.get_pool(cr.dbname)
model = 'employee.data'
depth = 1
xml = self.create_xml(cr, uid, model, depth, context)
if 'name' in fields:
res.update({'filename': 'employeedata.txt'})
if 'data' in fields:
res.update({'data': base64.encodestring(xml.read())})
return res
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 5/15/13, 4:56 AM |
Seen: 4817 times |
Last updated: 3/16/15, 8:10 AM |