Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
10244 Visualizzazioni

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) 

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
lug 24
15614
2
set 23
8454
1
apr 20
4787
5
set 19
5208
0
set 19
2633