7

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.

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
  • I dont understand your question, you mean restricting the domain of the one2many?, in that case, restricting the domain to what parametter?. If im in the right direction, the best case would be another field in your adaptation result object (like a boolean one) to difference, and then, add a domain filter in the one2many – dccdany Nov 17 '15 at 05:02
  • I need just change possible values for dropdown(for specific fields in view). `adaptation_result_ids` - it is One2Many field. And I need set my list for possible values only for this _tree_ element. It is possible? – Danila Ganchar Nov 17 '15 at 05:07
  • Yes, but lets suppose that you have 5 items: 200, 300, 500, 1000 and 2500, and you want to show 200, 300, and 500. Whats the difference between the ones that you want to show that the ones that you dont want to show (1000 - 2500)? – dccdany Nov 17 '15 at 05:15
  • I need to show 10-15 and that's all. It is not comfortable use limit more that 20 in form with many fields. Moreover, the last 20-40 records most important records. Other records it is just for history. – Danila Ganchar Nov 17 '15 at 06:41
  • Can you explain your whole scenario, its too confusing. – Bazzinga... Nov 17 '15 at 07:24
  • @010100100110111101101110011 I have dropdown with values like on first screen. I need change values 80-200-500 etc. to 10-15 only for current view that's all. Can you help me? – Danila Ganchar Nov 17 '15 at 07:39
  • you need to do this with python, where is the code? – maazza Nov 17 '15 at 09:06
  • @maazza I think this is configurable using xml or systems settings. Maybe using xpath. I really do not have any idea. – Danila Ganchar Nov 17 '15 at 09:46
  • you may have better luck there https://www.odoo.com/forum/help-1/question/how-to-create-dropdown-list-in-a-custom-module-and-the-values-for-dropdownlist-fetches-from-database-82670 – maazza Nov 17 '15 at 09:56
  • @maazza that's not what I need. It is dropdown for field of model. But I need change dropdown for **tree** element of view. The system has indeed just a few examples and small community. Any non-standard tasks - it is dancing with a tambourine ((( – Danila Ganchar Nov 17 '15 at 10:49

1 Answers1

5

/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
user2127302
  • 236
  • 2
  • 4