[FIX] fleet: avoid function field computation order issues
authorMartin Trigaux <mat@odoo.com>
Thu, 13 Nov 2014 15:02:11 +0000 (16:02 +0100)
committerMartin Trigaux <mat@odoo.com>
Thu, 13 Nov 2014 15:05:54 +0000 (16:05 +0100)
The name of a vehicle is function field.
The field odometer on a vehicle has a a setter that creates an odometer.
The name of an odometer is a function field that uses the name of the vehicle.
If a vehicle is created with a value in odometer field, the odometer is created before the name is computed so the concatanation would fail.
Fixes #3468

addons/fleet/fleet.py

index 3683e79..69900a6 100644 (file)
@@ -426,8 +426,10 @@ class fleet_vehicle_odometer(osv.Model):
         res = {}
         for record in self.browse(cr, uid, ids, context=context):
             name = record.vehicle_id.name
-            if record.date:
-                name = name+ ' / '+ str(record.date)
+            if not name:
+                name = record.date
+            elif record.date:
+                name += ' / '+ record.date
             res[record.id] = name
         return res