From 449ebf7ea6a2f0ddc5b33d37e524e8dcaea87484 Mon Sep 17 00:00:00 2001 From: Milan Date: Thu, 7 Nov 2024 04:35:31 +0100 Subject: [PATCH] [FIX] maintenance_usage: migration cleanup --- maintenance_usage/models/maintenance.py | 5 +++-- maintenance_usage/views/maintenance_views.xml | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/maintenance_usage/models/maintenance.py b/maintenance_usage/models/maintenance.py index 92c17160..6547dc43 100644 --- a/maintenance_usage/models/maintenance.py +++ b/maintenance_usage/models/maintenance.py @@ -1,5 +1,6 @@ from math import floor from odoo import _, api, fields, models +from odoo.tools import get_timedelta class MaintenanceEquipmentCategory(models.Model): @@ -27,8 +28,8 @@ class MaintenanceEquipment(models.Model): def _compute_period(self): for equipment in self: - recurring = equipment.maintenance_ids.filtered('recurring_maintenance') - equipment.period = min(recurring.mapped('period'), default=0) + recurring = equipment.maintenance_ids.filtered('repeat_unit') + equipment.period = min([get_timedelta(r.repeat_interval, r.repeat_unit).days for r in recurring], default=0) @api.model def create(self, values): diff --git a/maintenance_usage/views/maintenance_views.xml b/maintenance_usage/views/maintenance_views.xml index 052ad953..12a83633 100644 --- a/maintenance_usage/views/maintenance_views.xml +++ b/maintenance_usage/views/maintenance_views.xml @@ -38,8 +38,11 @@ - - + + period != 0 or maintenance_usage != 0