Skip to Content
Menu
This question has been flagged
1 Reply
3293 Views

Hello everyone,

I'd like to create a computed field that calcule difference between the value of a field from current record and the value of the same field from previous record example:

date        |          field1| cumputed_field

6/1/2018|    45000|   45000

6/2/2018|    45890|  890 = 45890 - 45000

6/3/2018|    46780| 890= 46780 - 45890

6/4/2018|    47500| 720= 47500 - 46780


What should I do to caluculate this computed field.

Thanks

Avatar
Discard
Best Answer

Hi try this,

self.env['your.model'].search([], order='date desc', limit=1)

the fields used to order may change according to your need. I've given the example based on the example you've given(you can also use fields like create_date, id).

Avatar
Discard