跳至内容
菜单
此问题已终结
1 回复
10254 查看

Hello everyone,

I try to calculate the value depending on previous record this is my code

 @api.depends('odometer')
    def get_km_parcouru(self):
        for record in self.sorted(lambda x: x.id):
            prev = self.env['fleet.vehicle.log.fuel'].search_read(
                [('id', '<', record.id)], order='date desc', limit=1)
            prev_record = prev[0]['odometer'] if prev else 0
            record.km_parcouru = record.odometer - prev_record

When I click on crate button I get this error 

ProgrammingError: can't adapt type 'NewId'

In:

 [('id', '<', record.id)], order='date desc', limit=1) 

形象
丢弃
最佳答案

At create moment the value record.id not exist in datatbase. When creating a record a model with computed fields, the records of the recordset will be in memory only. At that time the id of the record will be a dummy ids of type openerp.models.NewId

形象
丢弃
相关帖文 回复 查看 活动
2
7月 24
15634
2
9月 23
8461
1
4月 20
4797
5
9月 19
5215
0
9月 19
2644