This question has been flagged
1 Reply
6644 Views

 onchange_storage_device(self, cr, uid, ids, storage_type, context=None):
        if storage_type:
            storage_type = self.pool.get('archive.storage.type').browse(cr, uid, storage_type, context=context)
            cr.execute("""select  max(CAST(nullif(split_part(name, '-', 2), '') AS integer)) from archive_storage WHERE storage_device= %d""", (storage_type,))


            sn = cr.fetchone()[0]
            return {'value': {'name': storage_type.name + str( "%05d"% sn+1)}}
        return {'value': {}}

Avatar
Discard

Query engine does not recognize orm class, and you passed storage_type in params, it should rather be the id viz storage_type.id

Best Answer

Try to put storage_type.id instead of storage_type at the end of your statement like this

cr.execute("""select  max(CAST(nullif(split_part(name, '-', 2), '') AS integer)) from archive_storage WHERE storage_device= %d""", (storage_type.id,))

Avatar
Discard