Odoo Help

Welcome!

This community 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.

0

Openerp 7 wizard output file type unknown

By
Prakash
on 5/15/13, 4:56 AM 3,732 views

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

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 5/15/13, 8:28 AM

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?....

please reply...

Prakash
on 5/16/13, 9:38 AM

Updated Source code https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-576425-bth/+merge/114614

Prakash
on 5/16/13, 10:24 AM
1

Priyesh Solanki (pso)

--Priyesh Solanki (pso)--
Tiny ERP Pvt Ltd
http://www.odoo.com
1100
| 2 2 4
--Priyesh Solanki (pso)--
Priyesh Solanki (pso)
On 5/15/13, 5:12 AM

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

Prakash
on 5/15/13, 5:29 AM
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 5/15/13, 5:21 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/15/13, 4:56 AM
Seen: 3732 times
Last updated: 3/16/15, 8:10 AM