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 make a dynamique _order in python ?

By
kaisusr
on 2/18/15, 4:33 PM 707 views

Hello,

How we can make a dynamique _order in py ? for example 

class report_timesheet_task_user(osv.osv):
    _name = "report.timesheet.task.user"
    _auto = False
    _order = "name if a=b, fisrt_name if a>b"

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/18/15, 5:14 PM

Try creating a functional field xxx with store attribute, which loads the function def _get_order(...) like "name if a=b, fisrt_name if a>b" and use this field in (for example) _order ="xxx desc".

UPDATE:

Example:

    @api.one
    @api.depends(
      'sequence',
    )
    def _get_sort(self):
        if self.activity == 'loading':    
          self.sort_dz = self.sequence
        else:         
          self.sort_dz = -self.sequence

    activity = fields.Selection([('loading', 'Loading'),('unloading', 'Unloading')],'Activity Type', required=True, select=True)
    sequence = fields.Integer('Sequence',default=5) 
    sort_dz = fields.Integer('Sort',compute='_get_sort',default=0,store=True)

    _order = "sort_dz desc"

 

Hello; i tried it but ot doesn't work

kaisusr
on 2/19/15, 4:54 AM

answer updated, show your code, sample code works.

zbik
on 2/19/15, 5:49 AM

I have 2 fields: 'date_work':fields.boolean('date'), 'priority_work':fields.boolean('priority') and i have 2 others fields: 'work_priority':fields.integer('priority work'), 'work_date':fields.date('date work') and i want that _order='work_priority desc' when priority_work='t' and date_work='f', and _order='work_date desc' when priority_work='f' and date_work='t', thanks for you

kaisusr
on 2/19/15, 6:51 AM

all fields are in the same model?

zbik
on 2/19/15, 10:12 AM

Yes sir (y) , this is the diffuculitie

kaisusr
on 2/19/15, 11:54 AM

Generally, If yes, it is impossible. How sort all records by parameters from one record??? You may try, like this (where INTEGER you map date to integer), but.... if priority_work='t' and date_work='f' self.sort_dz = self.work_priority else self.sort_dz = INTEGER(work_date) 'sort_dz':fields.integer('sort By') _order='sort_dz desc'

zbik
on 2/19/15, 12:13 PM

Thank you zbik, when i'll find a solution i'll tell you

kaisusr
on 2/20/15, 3:27 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

3 follower(s)

Stats

Asked: 2/18/15, 4:33 PM
Seen: 707 times
Last updated: 3/16/15, 8:10 AM