I want to get the latest date from a date field and show it in a new field of an other view so I used this function and it seems I'm doing something wrong what could it be?here is my code
def _get_latest_intervention(self, cr, uid, ids, latest, args, context=None):
res = {}
obj_intervention = self.pool.get('c.intervention'
)for interv in self.browse(cr, uid, ids, context=context):
intervention_ids = obj_intervention.search(cr, uid, [('equipement_id' '=',, intervention_id)], order='date_intv'
, context=context)if intervention_ids:
res[intervention_id] = intervention_ids[-1:][0
]else False
return:
res[intervention_id] = res
to explain more this module is about management of technical centers of vehicul so I want to show the latest date of intervention of those technical centers in their form view in the field "latest" so I have created 3 menu items (centre,equipement,intervention) and I have put this function in the centre class
You are looping (for _ in self.browse...) in elements of class intervention? I don't know, I'm just guessing from variable names. Is this method inside the class "Centre" ? What's the field that links togheter "centre" and "intervention"? What does equipement has to do with all this?
yes this methode is in the class"centre" ,I did this fault I wanted to wright 'centre_id' but I wrote 'equipement_id' so there is no equipements menchened in this function every centre has his equipements and all dates of intervention of equipments either it's a corrective maintenace or a preventive one so I want to add a new field in the centre form view named latest,which shows the latest added date in the intervention form view this classes are related of course with relational fields I will put all code to make it clearer
see this maybe same idea
https://stackoverflow.com/questions/49748892/get-last-order-date-customer-in-odoo-partner-view