Hi,
Please refer to the blog below to set the compute function for the field.https://www.cybrosys.com/blog/how-to-set-compute-function-for-field-using-odoo-17-studio.
Steps to Auto-Fill opening_meter_reading in Odoo Studio
Set opening_meter_reading as a Computed Field:
Open the properties of the opening_meter_reading field.
Enable the "Computed" option to make the field computed.
Define the Compute Method:
In the "Python Code" section for the opening_meter_reading field, you can add the following code:
for record in self:
previous_record = self.search([], order='your_date_field desc', limit=1)
if previous_record:
record.opening_meter_reading = previous_record.closing_meter_reading
else:
record.opening_meter_reading = 0 # or some default value
Replace your_date_field with the actual date field used in your model
Hope it helps