11from odoo import api , models , fields , _
2- from datetime import timedelta
32from odoo .exceptions import ValidationError
43
54
@@ -22,11 +21,26 @@ class MaintenancePlan(models.Model):
2221 help = 'Maximum value since the last revision to generate another' )
2322 meter_autoinc_lastvalue = fields .Float (
2423 string = 'Value of last revision' ,
25- help = 'Value from which the last revision was made' )
24+ help = 'Value from which the last revision was made' )
2625 meter_autoinc_lastupdate = fields .Date (
2726 string = 'Date of last revision' ,
2827 readonly = True )
2928
29+ def _compute_next_maintenance (self ):
30+ super ()._compute_next_maintenance ()
31+
32+ for plan in self .filtered (lambda x : x .meter_mode ):
33+ next_maintenance_todo = self .env ['maintenance.request' ].search ([
34+ ('equipment_id' , '=' , plan .equipment_id .id ),
35+ ('maintenance_type' , '=' , 'preventive' ),
36+ ('maintenance_kind_id' , '=' , plan .maintenance_kind_id .id ),
37+ ('maintenance_plan_id' , '=' , plan .id ),
38+ ('stage_id.done' , '!=' , True ),
39+ ('close_date' , '=' , False )], order = "request_date asc" , limit = 1 )
40+
41+ plan .next_maintenance_date = next_maintenance_todo .request_date \
42+ if next_maintenance_todo else plan .start_maintenance_date
43+
3044 @api .onchange ('meter_mode' )
3145 def _onchange_meter_mode (self ):
3246 if self .meter_mode :
0 commit comments