Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to use on_change attribute ?

By
jean44
on 9/30/13, 9:47 PM 761 views

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()

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 9/30/13, 9:47 PM
Seen: 761 times
Last updated: 3/16/15, 8:10 AM