I changed somethings in my code so I want to show the date in the intervention_id field, here is my code
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class centre(models.Model):
_name = 'res.partner'
_inherit = ['res.partner']
def _get_latest_intervention(self, cr, uid, ids, field_name, 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, [('centre_id', '=', intervention_id)], order='date_intv', context=context)
if intervention_ids:
res[intervention_id] = intervention_ids[-1:][0]
else:
res[intervention_id] = False
return res
rs_ctr = fields.Char(string='Réseau')
nb_ligne = fields.Integer(string='Lignes')
n_agr = fields.Integer(string='N° d\'agrèment')
chef = fields.Char(string='Chef centre')
prp = fields.Char(string='Propriétaire')
equipement_id = fields.Many2one('product.template','Equipements',select=True)
intervention_id = fields.Date(compute='_get_latest_intervention', type="Date", string='Derniére intervention')
properties1 = fields.One2many('product.template','centre_id','Centres')
centre()
class equipement(models.Model):
_name = 'product.template'
_inherit = ['product.template']
name = fields.Char(string='Nom')
num_ligne = fields.Integer(string='N° ligne')
model_mat = fields.Char(string='Model de materiel')
centre_id = fields.Many2one('res.partner','Centres',select=True)
properties2 = fields.One2many('c.maintenance','equipement_id','Equipements')
equipement()
class maintenance(models.Model):
_name = 'c.maintenance'
_description = 'Maintenance'
STATE_SELECTION = [('c','Corrective'),('p','Préventive')]
type_int = fields.Selection(STATE_SELECTION,'Type d\'intervention')
date_intv = fields.Date(string='Date d\'intervention')
equipement_id = fields.Many2one('product.template','Equipements',select=True)
intervention_id = fields.Many2one('c.intervention','Interventions',select=True)
maintenance()
class intervention(models.Model):
_name = 'c.intervention'
STATE_SELECTION = [('c','Corrective'),('p','Préventive')]
_description = 'Interventions'
_inherits = {'res.partner':'centre_id'}
_inherit = {'c.maintenance'}
name = fields.Char(string='Nom')
type_int = fields.Selection(STATE_SELECTION,'Type d\'intervention')
properties4 = fields.One2many('c.maintenance','intervention_id','Interventions')
centre_id = fields.Many2one('res.partner','Centres',select=True)
intervention()
what could be the right way to make this work please
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