Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
9414 Vistas

I'm trying to apply default_order to a tree view for multiple fields.
Or rather, I'm looking to (1) make lines drag & droppable while also (2) sort them by date_planned_start. But if they're sorted by (2), they aren't (1), and if they're (1), they aren't (2).

Description:
More specifically, I'm trying to make the lines in mrp.production drag & droppable via a "sequence" field, but at the same time order the lines by date_planned_start.
Going by the documentation, this shouldn't be an issue (as both Odoo 8.0 and 13.0 Doc example show default_order="sequence, name desc", more or less exactly what I'm trying to accomplish.)

But adding:

    _order = 'sequence, date_planned_start'     

to the model does nothing.

Adding an xpath to the tree attribute using:

    <attribute name="default_order">sequence, date_planned_start</attribute>

does order the view, but only according to the first field supplied, i.e. by sequence but not date_planned_start. If I reverse the order to ..>date_planned_start, sequence</.., it orders by date, but not by sequence, and as result the lines are no longer drag & droppable.

As mentioned, I've referenced the official documentation, and by the looks of it, this should be quite possible, as it's almost the exact example given. But for some reason, it doesn't work.


Issue:
Only the first field given in the default_order attribute is sorted. The other isn't.

(Relevant) Code:

 
View:
    <record id="inherited_mrp_production_tree_view" model="ir.ui.view">
            <field name="name">mrp.production.tree</field>
            <field name="model">mrp.production</field>
            <field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
            <field name="arch" type="xml">
                <xpath expr="//tree" position="attributes">
                    <attribute name="default_order">date_planned_start, date_start_wo</attribute>
                </xpath>
                <xpath expr="//field[@name='name']" position="before">
                    <field name="sequence" widget="handle"/>
                </xpath>

Model:
    sequence = fields.Integer('Sequence', default=1)
Avatar
Descartar
Autor

Ah, and don't pay any mind to the two fields given in the view code (date_planned_start, date_start_wo), just me playing around trying to get it to work, but forgot to update the code for the example.

Autor Mejor respuesta

Figured it out why it doesn't work, I think:

Each line has a unique "sequence" integer.
When you sort through "sequence" first, there is effectively no sub-grouping left to sort through.

For example:
if you have 12 lines,
6 with a "number_id" of 1, and 6 with one of 2,
and you sort through number_id first,
whatever secondary field (let's call it "priority_id") you're sorting through will be sorted per "group" of number_ids.

So with default_order="number_id,priority_id", you'd get:
12 ->
2x6 (number_ids 1 and 2) ->
2x3x3 (two groups (number_ids 1 and 2) each subdivided into 3 groups (priority_id 1, 2, and 3).

However, since widget="handle" seems(?) to require unique integers per line, and that you sort it first in order to be able to drag & drop the lines, any further subdivision after it, while technically allowed, has no effect.
Conversely, when you sort "sequence" after something else, it appears to be bound into place.

In the above example, it would be equivalent to:

12 ->
12x1 ->
12x1x1 -> So nothing is effectively sorted beyond "Sequence"

Unless I am missing something, which is also quite possible. :)

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
5
ago 24
45345
2
abr 24
1949
3
jun 23
4885
2
jun 23
3895
3
mar 23
9649