class delais(models.Model):
_name = 'delais.delais'
_description = 'delais.delais'
project_ids = fields.Many2one('project.project', string='Projet')
delai_arr_mois = fields.Float(string='Délais D arrét en mois', compute='_delai_arret')
this function calculates the sum of the number of missions per project
@api.multi
def _delai_arret(self):
domaine = ('project_ids', '=', self.project_ids.id)
print(domaine)
dict = self.env['mission.mission'].search_read([domaine], ['nbr_mission'])
print(dict)
if not dict:
pass
else:
somme = 0
for key in dict:
print(key['nbr_mission'])
somme = somme + key['nbr_mission'] / 30
print('la somme est : {somme}')
self.delai_arr_mois = somme
print(somme)
class Missions(models.Model):
_name = 'mission.mission'
_description = 'mission.mission'
_rec_name = 'mission'
project_ids = fields.Many2one('project.project', string='Projet')
('Déf', 'Définitif')])
ordre_arre = fields.Date(string='Ordre d arrét')
ordre_repr = fields.Date(string='Ordre de reprise')
nbr_mission = fields.Float(string='nombre de mission', compute='_delais_mission')
this function calculate the number of missions
def _delais_mission(self):
for k in self:
if k.ordre_arre and k.ordre_repr:
date_1 = datetime.strptime(k.ordre_arre, '%Y-%m-%d')
date_2 = datetime.strptime(k.ordre_repr, '%Y-%m-%d')
k.nbr_mission = ((date_2 - date_1).days) / 30
#print(k.nbr_mission)
error is :
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: delais.delais(1, 4)