I want to create Model (car) name like, Telsa / Model X, and I found this piece of code of Fleet module doing that.
FleetVehicleModel class (models.Model)
_name = 'fleet.vehicle.model'
_description = 'Model of a vehicle'
_order = 'desc'
name = fields.Char ('Model name', required = True)
brand_id = fields. Many2one ('fleet.vehicle.model.brand', 'Make', required = True, help = 'Make of the vehicle')
vendors fields.Many2many = ('res.partner', 'fleet_vehicle_model_vendors',' model_id '' partner_id ', string =' Vendors')
image = fields.Binary (related = 'brand_id.image', string = "Logo", readonly = False)
image_medium = fields.Binary (related = 'brand_id.image_medium', string = "Logo (medium) ",
image_small = fields.Binary (related = 'brand_id.image_small', string = "Logo (small)", readonly = False)
@ api.multi
@ api.depends ('name', 'brand_id')
def name_get (self):
res = []
for record in self:
name = record.name
if record.brand_id.name:
name = record.brand_id.name + '/' + name
res.append ((record.id, name))
return res
I do not understand how this code works when I choose the model then press Save button, it will create a new name under the form "Brand / Model" and replace the old name I filled.
And I did not see any 'computed field' in this model.
I figure out by 'print (res)', but I do not understand how this can link 'record.id' in 'res []' to find the new name.
I also can not find any new fields in Database too.
I will appreciate if someone can explain it.
Many thanks