تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1799 أدوات العرض
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.


الصورة الرمزية
إهمال

name_search method is called on many2one fields and inside that you can set the limit the number records displaying on the field.

الكاتب أفضل إجابة

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?

"the Many2one field defaults to displaying records in ascending order"
ascending on what ?? id? name?
Why is it so difficult to change the order and not to use:

partner_id = fields.Many2one( 'res.partner', string='Partner',
order='name', store=True)

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 24
2240
1
نوفمبر 24
3203
0
نوفمبر 15
6229
2
سبتمبر 25
543
0
أكتوبر 24
867