diff options
| author | Pierre Masereel <pim@odoo.com> | 2017-02-16 15:48:06 +0100 |
|---|---|---|
| committer | Pierre Masereel <pim@odoo.com> | 2017-02-16 16:13:02 +0100 |
| commit | d63bb0837b0776aa1898d9164917e0a082fbfa18 (patch) | |
| tree | 5accc79a6dbd065004fd8dcb548b3c9fb01c20c3 | |
| parent | a7abfb9e18617956a3c590fadab4397962be2c70 (diff) | |
[FIX] maintenance: maintenance team and duration in cron
When you define recurring maintenance requests on an equipment, the
maintenance duration and the maintenance team is not set on the created
requests.
The problem comes from the creation method called by the cron that
doesn't use the duration and maintenance team to create new requests.
We now use these fields in the request creation
| -rw-r--r-- | addons/maintenance/models/maintenance.py | 2 | ||||
| -rw-r--r-- | addons/maintenance/tests/test_maintenance.py | 25 |
2 files changed, 27 insertions, 0 deletions
diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index dd25c6e0c10..e16a171d29a 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -232,6 +232,8 @@ class MaintenanceEquipment(models.Model): 'maintenance_type': 'preventive', 'owner_user_id': self.owner_user_id.id, 'technician_user_id': self.technician_user_id.id, + 'maintenance_team_id': self.maintenance_team_id.id, + 'duration': self.maintenance_duration, }) @api.model diff --git a/addons/maintenance/tests/test_maintenance.py b/addons/maintenance/tests/test_maintenance.py index d73301d7ec2..3725bf82df7 100644 --- a/addons/maintenance/tests/test_maintenance.py +++ b/addons/maintenance/tests/test_maintenance.py @@ -15,6 +15,7 @@ class TestEquipment(TransactionCase): self.equipment = self.env['maintenance.equipment'] self.maintenance_request = self.env['maintenance.request'] self.res_users = self.env['res.users'] + self.maintenance_team = self.env['maintenance.team'] self.main_company = self.env.ref('base.main_company') res_user = self.env.ref('base.group_user') res_manager = self.env.ref('maintenance.group_equipment_manager') @@ -105,3 +106,27 @@ class TestEquipment(TransactionCase): # As it is generating the requests for one month in advance, we should have 4 requests in total tot_requests = self.maintenance_request.search([('equipment_id', '=', equipment_cron.id)]) self.assertEqual(len(tot_requests), 1, 'The cron should have generated just 1 request for the High Maintenance Monitor.') + + def test_21_cron(self): + """ Check the creation of maintenance requests by the cron""" + + team_test = self.maintenance_team.create({ + 'name': 'team_test', + }) + equipment = self.equipment.create({ + 'name': 'High Maintenance Monitor because of Color Calibration', + 'category_id': self.ref('maintenance.equipment_monitor'), + 'technician_user_id': self.ref('base.user_root'), + 'owner_user_id': self.user.id, + 'assign_date': time.strftime('%Y-%m-%d'), + 'period': 7, + 'color': 3, + 'maintenance_team_id': team_test.id, + 'maintenance_duration': 3.0, + }) + + self.env['maintenance.equipment']._cron_generate_requests() + tot_requests = self.maintenance_request.search([('equipment_id', '=', equipment.id)]) + self.assertEqual(len(tot_requests), 1, 'The cron should have generated just 1 request for the High Maintenance Monitor.') + self.assertEqual(tot_requests.maintenance_team_id.id, team_test.id, 'The maintenance team should be the same as equipment one') + self.assertEqual(tot_requests.duration, 3.0, 'Equipement maintenance duration is not the same as the request one') |
