This question has been flagged
4 Replies
36131 Views

Looking at various template XML files, I sometimes see something like this:

t-field-options='{"widget": "contact", "fields": ["address"], "no_marker": true}'

However, I can't find any detailed documentation for various options that are available for such a statement.  There's lots of stuff on "widgets", but it's all about writing Python code to create your own thingamajig.  Is there any documentation for the XML formatting widgets?

Avatar
Discard

@Jeff, I'm also interested in this. I've purchased the theme developer handbook from Odoo's indiegogo campaign here: https://www.indiegogo.com/projects/bootstrap-themes-for-odoo-cms although the book is not likely to be released until the campaign finishes I believe it does cover the subject as it applies to the CMS/E-commerce and theme modules. Once I have read the book I will write back here with information on what I have learnt, however in the meantime if you find any resources covering widget creation and customisation I would be interested to know what you have found.

Best Answer

Find the definition of these Widgets in the XML file defining the Templates:

https://github.com/odoo/odoo/blob/11.0/odoo/addons/base/ir/ir_qweb.xml

<odoo>
<template id="contact_name">
    <div t-if="'name' in fields">
        <t t-if="object.name">
            <span itemprop="name" t-esc="name"/>
        </t>
        <t t-if="not object.name and object.parent_name">
            <span itemprop="name" t-esc="object.parent_name"/>
        </t>
        <t t-if="options.get('country_image') and 'country_id' in fields and object.country_id and object.country_id.image">
            <span t-field="object.country_id.image" t-options='{"widget": "image", "class": "country_flag"}'/>
        </t>
    </div>
</template>
<template id="contact">
    <address t-ignore="true" class="mb0" itemscope="itemscope" itemtype="http://schema.org/Organization">
        <div t-if="not (('name' in fields) or (address and 'address' in fields) or (city and 'city' in fields) or (mobile and 'mobile' in fields) or (website and 'website' in fields) or (email and 'email' in fields))" class="css_non_editable_mode_hidden">
            --<span class="text-muted" t-esc="name"/>--
        </div>
        <t t-if="object.country_id.name_position != 'after'">
            <t t-call="base.contact_name"/>
        </t>
        <div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress">
            <div t-if="address and 'address' in fields">
                <i t-if="not options.get('no_marker')" class='fa fa-map-marker fa-fw'/> <span itemprop="streetAddress" t-raw="address.replace('\n', options.get('no_tag_br') and ', ' or ('&lt;br/&gt;%s' % ('' if options.get('no_marker') else '&amp;nbsp; &amp;nbsp; ')))"/>
            </div>
            <div t-if="city and 'city' in fields">
                <i t-if="not options.get('no_marker')" class='fa fa-map-marker fa-fw'/>
                <span itemprop="addressLocality" t-raw="city"/>,
                <span itemprop="addressCountry" t-raw="country_id"/>
            </div>
            <div t-if="phone and 'phone' in fields"><i t-if="not options.get('no_marker') or options.get('phone_icons')" class='fa fa-phone fa-fw'/> <span itemprop="telephone" t-esc="phone"/></div>
            <div t-if="mobile and 'mobile' in fields"><i t-if="not options.get('no_marker') or options.get('phone_icons')" class='fa fa-mobile fa-fw'/> <span itemprop="telephone" t-esc="mobile"/></div>
            <div t-if="fax and 'fax' in fields"><i t-if="not options.get('no_marker') or options.get('phone_icons')" class='fa fa-fax fa-fw'/> <span itemprop="faxNumber" t-esc="fax"/></div>
            <div t-if="website and 'website' in fields">
                <i t-if="not options.get('no_marker')" class='fa fa-globe'/>
                <a t-att-href="website and '%s%s' % ('http://' if '://' not in website else '',website)"><span itemprop="website" t-esc="website"/></a>
            </div>
            <div t-if="email and 'email' in fields"><i t-if="not options.get('no_marker')" class='fa fa-envelope fa-fw'/> <span itemprop="email" t-esc="email"/></div>
        </div>
        <t t-if="object.country_id and object.country_id.name_position == 'after'">
            <t t-call="base.contact_name"/>
        </t>
    </address>
</template>
</odoo>
Avatar
Discard
Best Answer

There's some basic Widgets documentation here: https://www.odoo.com/documentation/8.0/howtos/web.html#widgets-basics but that doesn't really cover the 'options' for widgets.

 One tip that I found that I'll leave here in case someone else comes looking (as I did): you can pass 'options' to the widget from the XML <field/> definition by setting an 'options' attribute to a JSON dictionary, like this:

<field name="myfield" widget='many2many_checkboxes' options='{"horizontal": 1}' />

This will set widget.options.horizontal to 1, and this option is then available within the QWeb template for the widget, so you can use options to alter the templated layout, for example.


Avatar
Discard
Best Answer

You can pass in the option inside t-field-options param as below


<div t-field="quotation.partner_invoice_id" t-field-options='{

"widget": "contact",

"fields": ["address", "name", "phone", "email"],

"no_marker": true

}'/>

Avatar
Discard