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

In this below image you can check i have created two class efficiency and test ,in efficiency class there is one field called start_time so i need this field to display   the minimum value of all record in start field ,which is present in test class.for this i am writing one  function can anyone help,how i should get minimum value of start field and displayed into my start_time field which is present in another model.

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

As an option:

get the lowest amount of 'start' - test . search([],order='start asc', limit=1)

define 'start_time' as float and make it equal to the result above or as integer and store 'id' of the record with min 'start' amount.

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

Hi,

An alternative solution. You may try like this:

class effeciency(models.Model):
_name= "effeciency.effeciency"

def _get_min_test(self):
recs = self.env['test.line'].search([])
        if recs:
    recs_sorted = recs.sorted(key=lambda r: r.start)
            return recs_sorted[0].id
    
    start_time = fields.Many2one('test.line',string="Start Time", default=_get_min_test)
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 23
2558
6
thg 10 20
9030
3
thg 4 19
3407
2
thg 8 18
4221
1
thg 1 16
4102