Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

sorting multiple fields in tree view via default_order, v13.0

Subscriure's

Get notified when there's activity on this post

This question has been flagged
viewssorting
2 Respostes
10952 Vistes
Avatar
Mads Søndergaard

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)
1
Avatar
Descartar
Mads Søndergaard
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.

Avatar
Mads Søndergaard
Autor Best Answer

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. :)

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Select multiple elements with XPath Solved
views
Avatar
Avatar
Avatar
Avatar
Avatar
5
d’ag. 24
48220
Filter out (hide) lines in tree component Solved
views
Avatar
Avatar
Avatar
2
d’abr. 24
3486
What are the different types of views available in Odoo? Solved
views
Avatar
Avatar
Avatar
Avatar
3
de juny 23
7935
view layout (two fields on the same row within an xpath) Solved
views
Avatar
Avatar
2
de juny 23
5838
Create view without model, only with buttons and text
views
Avatar
Avatar
Avatar
3
de març 23
11156
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now