Odoo 从one2many字段获取上次更新的数据
如何从one2many字段中获取上次更新的数据。我使用了下面的代码,但是当我创建一个新记录时,它不起作用,对于现有的记录,它可以正常工作 代码Odoo 从one2many字段获取上次更新的数据,odoo,odoo-10,Odoo,Odoo 10,如何从one2many字段中获取上次更新的数据。我使用了下面的代码,但是当我创建一个新记录时,它不起作用,对于现有的记录,它可以正常工作 代码 class location(models.Model): _name = 'weather.location' name = fields.Char(string="City Name",required=True) weather_ids = fields.One2many('weather.weather', '
class location(models.Model):
_name = 'weather.location'
name = fields.Char(string="City Name",required=True)
weather_ids = fields.One2many('weather.weather',
'location_id', string="Weather Details", domain=([('forecast','=',False)]))
temperature = fields.Float(string='Temperature', compute='weather_details')
def weather_details(self):
for record in self:
temperature_list = []
for line in record.weather_ids:
temperature_list.append(line.temperature)
self.temperature = record.temperature_list[-1]
当我创建新的时,它会给出以下错误:
自身温度=温度列表[-1]
索引器:列表索引超出范围
任何人都可以帮助从one2many fiel获取最近更新的数据吗?可变温度列表是一个数组,您可以使用温度列表[:-1]访问最后位置,因此如果更改行:
self.temperature=temperature_list[-1]
借
它必须起作用
self.temperature=temperature_list[:-1]