Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to sort a character field which contains integer values?

By
Dimple
on 6/2/14, 3:13 AM 737 views

I have a character field named employee's id. In which we enter the employee id's like 102,103,1021,..,because it is a character field it shows like 102,1021,103,.. But i want to display like 102,103,1021,... How can i sort the charcter field.?

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 6/2/14, 3:36 AM

The below SQL to Sort character field as int,

select *  from table_name order by cast(employees_id as int) asc

But in python the same code _order = "cast(employees_id as int) asc"  is not support.

Solution to override _generate_order_by method in python,

def _generate_order_by(self, order_spec, query):
        my_order = "cast(employees_id as int) asc"            
        if order_spec:
            return super(class_name, self)._generate_order_by(order_spec, query) + ", " + my_order
        return " order by " + my_order

Refer the link for more details.

 

Can we update it in xml code?

Remya
on 6/2/14, 3:59 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/2/14, 3:13 AM
Seen: 737 times
Last updated: 3/16/15, 8:10 AM