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

I need to create a field with a value suggested by the program according to the last back label generated for the selected series.


I have this:


back_label_from = fields.Integer(string="Back Label From", default=lambda self: self._get_default_back_label())

@api.model    def _get_default_back_label(self):        back_label_id = self.env['back.label'].search([('back_label_from')])        return back_label_id.id

I don't know exactly what to put in the function ( def _get_default_back_label(self): )

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

Hi,
We can retrieve the last created record in the model “back.label” using search method by specifying the order and using limit parameter.

back_label_id = self.env['back.label'].search([("domain")], limit=1, order='id desc')

Hence you will get the last created record object in back_label_id.After getting the object you can assign the value accordingly.If you have any domain used for the search operation please specify the domain in the brackets also.

Eg:

def _get_default_back_label(self)
    back_label_id = self.env['back.label'].search([("domain")], limit=1, order='id desc')
    return back_label_id

Regards

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مايو 22
4449
0
نوفمبر 21
21
4
نوفمبر 21
4653
0
نوفمبر 21
3576
1
يناير 23
2673