[FIX] fleet: properly archive Contract/Services

When archiving a vehicle, the active state of its Contracts/Services
were toggled, which was confusing (an archived Contract would suddently
become unarchived on an archived vehicle).

Now we only archive the Contracts/Services when the Vehicle is archived,
and no unarchiving is done.

task-2898104

closes odoo/odoo#95650

X-original-commit: 0be40d67c28b8575613f59ca5b4d8d6ea99638cb
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Kevin Baptiste
2022-07-08 14:34:30 +02:00
parent 4659736fc4
commit 9c6f20a853
+4 -5
View File
@@ -316,6 +316,10 @@ class FleetVehicle(models.Model):
if self.vehicle_type == 'car':
future_driver.sudo().write({'plan_to_change_car': True})
if 'active' in vals and not vals['active']:
self.env['fleet.vehicle.log.contract'].search([('vehicle_id', 'in', self.ids)]).active = False
self.env['fleet.vehicle.log.services'].search([('vehicle_id', 'in', self.ids)]).active = False
res = super(FleetVehicle, self).write(vals)
return res
@@ -347,11 +351,6 @@ class FleetVehicle(models.Model):
vehicle.driver_id = vehicle.future_driver_id
vehicle.future_driver_id = False
def toggle_active(self):
self.env['fleet.vehicle.log.contract'].with_context(active_test=False).search([('vehicle_id', 'in', self.ids)]).toggle_active()
self.env['fleet.vehicle.log.services'].with_context(active_test=False).search([('vehicle_id', 'in', self.ids)]).toggle_active()
super(FleetVehicle, self).toggle_active()
@api.model
def _read_group_stage_ids(self, stages, domain, order):
return self.env['fleet.vehicle.state'].search([], order=order)