Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6329 Lượt xem

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"

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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"

 

Ảnh đại diện
Huỷ bỏ
Tác giả

Hello; i tried it but ot doesn't work

answer updated, show your code, sample code works.

Tác giả

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

all fields are in the same model?

Tác giả

Yes sir (y) , this is the diffuculitie

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'

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 19
4288
3
thg 8 15
22715
0
thg 2 16
2970
2
thg 8 15
6715
1
thg 8 15
4662