Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo. Dropdown with limits

I have some One2Many field in my model. I set limit = 5 for tree element in view. But how I can change list with possible values(80-200-500 etc.) to my custom list(for example: 10-15-etc.)?

enter image description here

Here my xml:

<!-- 
     info about view: 
     <record model="ir.ui.view" id="view_my_id_employee_form">
        <field name="name">hr.employee.property.form.inherit</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form" />
-->
<field name="adaptation_result_ids">
    <tree default_order="date desc" limit="5">
        <field name="name"/>
        <field name="date"/>
    </tree>
</field>

Maybe it is possible using Window Actions in settings?

enter image description here

I tried different ways but all in vain. Can you help with my problem? Thank you in advance.

like image 729
Danila Ganchar Avatar asked Nov 13 '15 18:11

Danila Ganchar


1 Answers

/addons/web/static/src/js/views/list_view.js

render_pager: function($node) {
//...
this.$pager
//...
.find('.oe_list_pager_state')
    .click(function (e) {
        e.stopPropagation();
        var $this = $(this);

        var $select = $('<select>')
            .appendTo($this.empty())
            .click(function (e) {e.stopPropagation();})
            .append('<option value="80">80</option>' +
                '<option value="200">200</option>' +
                '<option value="500">500</option>' +
                '<option value="2000">2000</option>' +
                '<option value="NaN">' + _t("Unlimited") + '</option>')
            .change(function () {
                var val = parseInt($select.val(), 10);
                self._limit = (isNaN(val) ? null : val);
                self.page = 0;
                self.reload_content();
            }).blur(function() {
                $(this).trigger('change');
            })
            .val(self._limit || 'NaN');
        });
//...
}

/my_module/template.xml

<openerp>
    <data>
        <template id="assets_backend_tree_pager" name="tree pager" inherit_id="web.assets_backend">
            <xpath expr="//script[@src='/web/static/src/js/views/list_view.js']" position="replace">
                <script type="text/javascript" src="/my_module/static/src/js/views/list_view.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

/my_module/static/src/js/views/list_view.js

// TODO code
like image 61
user2127302 Avatar answered Nov 09 '22 13:11

user2127302