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

Iterate over batch of dynamic fields in openerp

By
Nikolay Fominykh
on 9/30/14, 5:06 PM 1,028 views

Our module has code like this: 

class product_product(osv.osv):
    _inherit = "product.product"
    _name = 'product.product'

    def _jdescription(self, cr, uid, ids, fields, arg, context=None):
        result = {}
        for record in self.browse(cr, uid, ids, context=context):
            print record.code, record.lst_price, record.serialized_description
            if record.serialized_description:
                json = simplejson.loads(record.serialized_description)
                print json
                l = ''
                for k, v in json.iteritems():
                    if v:
                        l += "<dt>%s</dt><dd>%s</dd>" % (k, v)
                description_list = "<dl>%s</dl>" % l
                result[record.id] = description_list
        return result

    _columns = {
        'serialized_description': fields.text('Description', type="text"),
        'jdescription': fields.function(_jdescription, type="text"),
    }

We insert jdesription in product_view.xml like this: 

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">product.normal.form.inherit</field>
            <field name="model">product.product</field>
            <field name="priority">5</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Description">
                        <field name='jdescription' />
                    </page>
                </notebook>
            </field>
        </record> 
  </data>
</openerp>

 

Html of course returns to client escaped. So we have following questions: 

1) Are there any kind of forloop built in openerp views?

2) Are there any way to turn off html escape for field? 

3) What is ERP way to view serialized data? 

1

Bejaoui Souheil

--Bejaoui Souheil--
808
| 2 1 4
Sousse, Tunisia
--Bejaoui Souheil--

Odoo developer,  functional and technical consultant

souheil_bejaoui@hotmail.fr

Bejaoui Souheil
On 3/6/15, 9:51 AM

Hi,

have you find the solution? Same question..

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

1 follower(s)

Stats

Asked: 9/30/14, 5:06 PM
Seen: 1028 times
Last updated: 3/16/15, 8:10 AM