Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

order by selection field in List view

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
2 Réponses
23771 Vues
Avatar
Prakash

In openerp 7 list view i want to shows the state value sort in the order draft, assigned and cancel currently shows in Asc or Desc. But in my case we need sorting in the order draft, assigned and cancel state. Based on applied in order by in python file

For example in the SQL the code:-

       select state, date from  object_name
ORDER BY CASE WHEN state = 'draft'  THEN 0 
              WHEN state = 'assigned'  THEN 1 
              WHEN state = 'cancel'  THEN 2
              ELSE 3
         END,  date desc

The above sql code applied in the python

_order = "CASE WHEN state='draft'  THEN 0   WHEN state = 'assigned'  THEN 1 ELSE 2 END,  date desc"

In the above query sorting selection value working in the pg_admin but in the python code its shows below error

Invalid "order" specified. A valid "order" specification is a comma-separated list of valid field names (optionally followed by asc/desc for the direction)

Based on this sorting order by selection value how to apply in openerp ? Override search method also applied the same sql query but shows same issue

2
Avatar
Ignorer
Torsten Francke

it is maybe helpfull to see the complete sql statment which was produce by openerp

Prakash
Auteur

Overridden search method and applied the sql statement same issue please let me provide more details to how to fix issues ? thanks

Avatar
Torsten Francke
Meilleure réponse

per default you can only sort by fields but you can override this

the following code:

    def _generate_order_by(self, order_spec, query):
        my_order = "CASE WHEN state='draft'  THEN 0   WHEN state = 'assigned'  THEN 1 ELSE 2 END,  date desc"            
        if order_spec:
            return super(sale_order, self)._generate_order_by(order_spec, query) + ", " + my_order
        return " order by " + my_order

to your sales_order model. I think this solves your problem. order_spec is given by the client or other order statment and add your stuff as well.

Hint: Overriding this method can add security holes like sql-injection if you do not check carefully your code and know what you do

UPDATE: I build a more generic version to update the sorting of 'state' as defined in the model instead of the name. I publish in our blog: http://blog.initos.com/2013/08/15/openerp-sortieren-nach-prozess-status/ with a german problem description but you can see the code

6
Avatar
Ignorer
Prakash
Auteur

thanks for reply i will try

Prakash
Auteur

In the above code works well in the number of records. but in the empty record shows below issue File "C:\Program Files (x86)\OpenERP 7.0-20130308-002138\Server\server.\openerp\sql_db.py", line 226, in execute ProgrammingError: syntax error at or near "by" LINE 1: ...".id FROM "object.name" WHERE FALSEorder by CASE WH... please guide me how to fix ?

Torsten Francke

add a space in 'return " order by " + my_order' before 'order by', i updated the code above

Prakash
Auteur

Thanks solved

Prakash
Auteur

Hi Markus, The above code worked for default view i also want the same functionality In the List view Header State Field clicked by order by ASC and order by DESC (based on the above _generate_order_by query). I think need to search method override is any sample code available based on this. Thanks

Avatar
Ethan Furman
Meilleure réponse

A version of Markus' answer from his blog. This one only changes the state ordering if state was in the query.

def _generate_order_by(self, order_spec, query):
    "correctly orders state field if state is in query"
    order_by = super(this_table_class, self)._generate_order_by(order_spec, query)
    if order_spec and 'state ' in order_spec:
        state_column = self._columns['state']
        state_order = 'CASE '
        for i, state in enumerate(state_column.selection):
            state_order += "WHEN %s.state='%s' THEN %i " % (self._table, state[0], i)
        state_order += 'END '
        order_by = order_by.replace('"%s"."state" ' % self._table, state_order)
    return order_by
2
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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