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

Dear all,

I am using Odoo 12 and stucked with a "compute" method set on a field.
My problem is on "write" method. Odoo is calling again the same "compute" method and overriding user entered data.

My field is declared as:

myfield = fields.Char('My field', compute='_get_value', readonly=False, store=True)

def _get_values(self)
    #Code here that sets a default value to "myfield" field and working as expected
    

My problem is this "_get_value" method is called on write method and overrides user entered data.

I have played around with some print() statements and can see that this "_get_value" method runs on form load and also on write method.

Also tried to add:

@api.depends('myfield')
def _get_values(self)
    #...

... at the begging of "_get_value" method with no success!

How can I prevent this "_get_value" compute method to run always, or at least at "write" method?

Thank you all in advance

Best regards

PM


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

Hi Paulo,

You may try to use `write_uid` or `write_date` in depends of the compute method.

These 2 fields will always be updated whenever any change is made and saved.

Ex:

@api.depends('write_date', 'write_uid')


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

@Sudhir Arya,

Thank you very much.

Using your approach I am able to achieve what I need.

Now the compute method only runs on form load.

Thank you very much

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مايو 19
4624
1
يونيو 25
15270
1
أبريل 25
3423
3
أبريل 25
5389
Compute Fields تم الحل
2
يوليو 24
2288