Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1248 มุมมอง
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?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
เม.ย. 24
1760
1
พ.ย. 24
2022
0
พ.ย. 15
5543
0
ต.ค. 24
554
2
พ.ย. 23
6990