Hi,
I'm new in OpenERP & I'm developing a module for car rental.
I have two objects as shown below, the first object is 'vehicule' which contains a functional field called 'jrsdelocation' stands for the number of total rental days of the current vehicule that is calculated by the function 'get_jrslocation', it accepts an argument which represents 'number of rental days', the second object is ' location'.
I want to use the attribute on_change on the fields 'datelocation', 'dateretour' and 'vehicule_id' that are contained in 'location' object, when those fields have been edited.
class vehicule_vehicule(osv.osv):
_name = 'vehicule.vehicule'
def get_jrslocation(self, cr, uid, ids, field_name, arg,context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context): if field_name:
res[line.id]= 0 else:
res[line.id]= jrsdelocation + field_name return res
_columns = {
'name': fields.char('ID', size=32, required=True, help='L\'identifiant du véhicule '), 'jrsdelocation': fields.function(get_jrslocation, method=True, string='Jours de location',type='integer', store=True),
} vehicule_vehicule()
class location_location(osv.osv):
def get_jrsslocation(self, cr, uid, ids,context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context): var1 = datetime.strptime(line.datelocation, "%Y-%m-%d") var2 = datetime.strptime(line.dateretour, "%Y-%m-%d") res[line.id]= (var2 - var1).days return res
_name = 'location.location'
_columns = {
'name': fields.char('ID',size=32,required=True),
'vehicule_id': fields.many2one('vehicule.vehicule','Véhicule',required=True),
'datelocation': fields.date('Date location'),
'dateretour': fields.date('Date retour'), 'daylocation': fields.function(get_jrsslocation, method=True, string='Jours de location',type='integer', store=True),
} location_location()