From b93b95e02eeab911c88cf97b8eea2e95e17550e3 Mon Sep 17 00:00:00 2001 From: tranngocson1996 Date: Fri, 3 Dec 2021 03:43:48 +0000 Subject: [PATCH] [IMP] maintenance: add hook method for inherit When you need to add certain details to the data in order to make a maintenance request. I can't do it using the old code. As a result, I've included a hook method to be more flexible with customers. closes odoo/odoo#81052 X-original-commit: a71a8fbc43cf0deee669869792b2ff2ac9ab9a8b Signed-off-by: Arnold Moyaux --- addons/maintenance/models/maintenance.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index 1388bff3f22..702271eefb7 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -221,9 +221,9 @@ class MaintenanceEquipment(models.Model): category_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID) return categories.browse(category_ids) - def _create_new_request(self, date): + def _prepare_maintenance_request_vals(self, date): self.ensure_one() - self.env['maintenance.request'].create({ + return { 'name': _('Preventive Maintenance - %s', self.name), 'request_date': date, 'schedule_date': date, @@ -235,7 +235,13 @@ class MaintenanceEquipment(models.Model): 'maintenance_team_id': self.maintenance_team_id.id, 'duration': self.maintenance_duration, 'company_id': self.company_id.id or self.env.company.id - }) + } + + def _create_new_request(self, date): + self.ensure_one() + vals = self._prepare_maintenance_request_vals(date) + maintenance_requests = self.env['maintenance.request'].create(vals) + return maintenance_requests @api.model def _cron_generate_requests(self):