1 from osv import osv, fields
3 class fleet_vehicle_model_type(osv.Model):
4 _name = 'fleet.vehicle.type'
5 _description = 'Type of the vehicle'
7 'name' : fields.char('Name', size=32, required=True),
9 #comment to delete#comment to delete
10 class fleet_vehicle_model(osv.Model):
12 def name_get(self, cr, uid, ids, context=None):
17 reads = self.browse(cr, uid, ids, context=context)
20 name = record.modelname
22 name = record.brand.name+' / '+name
23 res.append((record.id, name))
26 def _model_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
27 res = self.name_get(cr, uid, ids, context=context)
30 _name = 'fleet.vehicle.model'
31 _description = 'Model of a vehicle'
34 'name' : fields.function(_model_name_get_fnc, type="char", string='Name', store=True),
35 'modelname' : fields.char('Model name', size=32, required=True),
36 'brand' : fields.many2one('fleet.vehicle.model.brand', 'Model brand', required=False, help='Brand of the vehicle'),
37 'vendors': fields.many2many('res.partner','fleet_vehicle_model_vendors','model_id', 'partner_id',string='Vendors',required=False),
40 class fleet_vehicle_model_brand(osv.Model):
41 _name = 'fleet.vehicle.model.brand'
42 _description = 'Brand model of the vehicle'
44 'name' : fields.char('Brand Name',size=32, required=True),
47 class fleet_vehicle(osv.Model):
48 _name = 'fleet.vehicle'
49 _description = 'Fleet Vehicle'
52 'registration' : fields.char('Registration', size=32, required=False, help='Registration number of the vehicle (ie: plate number for a car)'),
53 'vin_sn' : fields.char('Chassis Number', size=32, required=False, help='Unique number written on the vehicle motor (VIN/SN number)'),
54 'driver' : fields.many2one('hr.employee', 'Driver',required=False, help='Driver of the vehicle'),
55 'model_id' : fields.many2one('fleet.vehicle.model', 'Model', required=True, help='Model of the vehicle'),
56 'log_ids' : fields.one2many('fleet.vehicle.log', 'vehicle_id', 'Logs'),
57 'acquisition_date' : fields.date('Acquisition date', required=False, help='Date when the vehicle has been bought'),
58 'acquisition_price' : fields.integer('Price', help='Price of the bought vehicle'),
59 'color' : fields.char('Color',size=32, help='Color of the vehicle'),
60 'status' : fields.char('Status',size=32, help='Status of the vehicle (in repair, active, ...)'),
61 'location' : fields.char('Location',size=32, help='Location of the vehicle (garage, ...)'),
62 'doors' : fields.integer('Number of doors', help='Number of doors of the vehicle'),
64 'next_repair_km' : fields.integer('Next Repair Km'),
66 'transmission' : fields.selection([('manual', 'Manual'),('automatic','Automatic')], 'Transmission', help='Transmission Used by the vehicle',required=False),
67 'fuel_type' : fields.selection([('gasoline', 'Gasoline'),('diesel','Diesel'),('electric','Electric'),('hybrid','Hybrid')], 'Fuel Type', help='Fuel Used by the vehicle',required=False),
68 'horsepower' : fields.integer('Horsepower',required=False),
69 'horsepower_tax': fields.float('Horsepower Taxation'),
70 'power' : fields.integer('Power (kW)',required=False,help='Power in kW of the vehicle'),
71 'co2' : fields.float('CO2 Emissions',required=False,help='CO2 emissions of the vehicle'),
74 def on_change_model(self, cr, uid, ids, model_id, context=None):
75 # print "ids: %r" % (ids,)
76 # print "model_id: %r" % (model_id,)
77 # print "context: %r" % (context,)
79 # logger = logging.getLogger('fleet.vehicle')
80 # logger.info('Hello')
88 model = self.pool.get('fleet.vehicle.model').browse(cr, uid, model_id, context=context)
90 print "model: %r" % (model.name,)
94 'message' : "You have selected this %s model" % (model.name,),
98 class fleet_vehicle_log_type(osv.Model):
99 _name = 'fleet.vehicle.log.type'
102 'name' : fields.char('Name', size=32, required=True),
105 class fleet_vehicle_log(osv.Model):
106 _name = 'fleet.vehicle.log'
109 'employee_id' : fields.many2one('hr.employee', 'Employee', required=True),
110 'vehicle_id' : fields.many2one('fleet.vehicle', 'Vehicle', required=True),
112 'create_date' : fields.datetime('Creation Date', readonly=True),
114 'description' : fields.text('Description'),
115 'type' : fields.many2one('fleet.vehicle.log.type', 'Type', required=True),
120 class fleet_vehicle_log_fuel(osv.Model):
121 _inherit = 'fleet.vehicle.log'
122 _name = 'fleet.vehicle.log.fuel'
124 'description' : fields.text('Description'),
127 class fleet_vehicle_log_insurance(osv.Model):
128 _inherit = 'fleet.vehicle.log'
129 _name = 'fleet.vehicle.log.insurance'
131 'description' : fields.text('Description'),
134 class fleet_vehicle_log_services(osv.Model):
135 _inherit = 'fleet.vehicle.log'
136 _name = 'fleet.vehicle.log.services'
138 'description' : fields.text('Description'),
141 class hr_employee(osv.Model):
142 _inherit = 'hr.employee'
145 'vehicle_id' : fields.many2one('fleet.vehicle', 'Vehicle', required=True),
146 'log_ids' : fields.one2many('fleet.vehicle.log', 'employee_id', 'Logs'),