콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
1338 화면
Hello, I would like to know if there is any way to give a many 2 one field in an Odoo form an ascending order and a limited number of records displayed.


아바타
취소
작성자 베스트 답변

Hello, I have not been able to get this code to work, could you tell me exactly what I should replace in the code?

아바타
취소
베스트 답변

Hi,

In Odoo, the Many2one field defaults to displaying records in ascending order. and if you need to change the default order and limit the number of records displayed you can try this code :

partner_id = fields.Many2one( 'res.partner', string='Partner',
        compute='_compute_partner_id', store=True)


    def _compute_partner_id(self):        for record in self:
            ordered_partners = self.env['res.partner'].sudo().search([], order='id desc', limit=5)
            if ordered_partners:
                for partner in ordered_partners:
                    record.partner_id = partner.id

This code ensures that the partner_id field is computed based on the first five partners in descending order according to their IDs. Replace the field name and model according to your specific requirements.


Hope it helps

아바타
취소
작성자

Hello, I have not been able to get this code to work, could you tell me exactly what I should replace in the code?

관련 게시물 답글 화면 활동
1
4월 24
1826
1
11월 24
2251
0
11월 15
5664
0
10월 24
597
2
11월 23
7190