تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
17890 أدوات العرض

How can I use

cus = self.env['res.partner'].search([('id', ...

to find the highest id in the table res.partner ?


الصورة الرمزية
إهمال
أفضل إجابة

Billiard,

You can use:

self.env['res.partner'].search([ ], order="id desc" limit="1")

here order helps to get the id in descending order and limit helps you to fetch the no of records you want to fetch.. i kept 1 to fetch the highest/final id
Hope it helps you

الصورة الرمزية
إهمال
الكاتب

self.env['res.partner'].search([ ], order="id desc", limit=1)

أفضل إجابة




all_records_sorted_by_id = self.env['res.partner'].search([ ]).sorted(key = lambda rec: rec.id, reverse=True)
if all_records_sorted_by_id:
    highest_id = all_records_sorted_by_id[0].id
الصورة الرمزية
إهمال
الكاتب

Now I get this error: TypeError: sorted() got an unexpected keyword argument 'reverse'

you should not receive this error if you write clean v8.0 code and "self" is a recordset in the above code (because of "self.env" used in the code, I assumed that it is v8, but it seems you mix v7/v8 styles and self is not a recordset here as you got this error... ) . see the definition of "sorted" function: "Odoo 8.0"/openerp/models.py#L5450 you can see that "sorted" function has the "reverse" keyword argument in it's definition. Anyway, @Pawan provided better solution (it avoids to turn around all partners list, so more suitable solution especially in case of large quantity of partners), but this one should work as well in a clean v8.0 API code.

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أكتوبر 15
9156
1
مارس 22
3134
1
ديسمبر 23
21039
6
مارس 24
37425
2
مارس 15
17885