Skip to content
Snippets Groups Projects
Commit edc8368f authored by alt-odoo's avatar alt-odoo
Browse files

[FIX] fleet: prevent deletion of vehicle contract


When we create a contract information on a vehicle, there is an activation cost
automatically created. Before this fix, if we delete the activation cost line, it
deletes automatically the associated contract. We should prevent this and add a
warning message instead.

To make it easier for the user, we should also show the contract information on
the list and form views of the vehicule cost.

When deleting the vehicle contract, we should also automatically delete the
activation cost line associated.

closes odoo/odoo#72269

Signed-off-by: default avatarAlex Tuyls <alt-odoo@users.noreply.github.com>
parent 3c388e7c
No related branches found
No related tags found
No related merge requests found
......@@ -2312,6 +2312,12 @@ msgstr ""
msgid "You can define several models (e.g. A3, A4) for each make (Audi)."
msgstr ""
#. module: fleet
#: code:addons/fleet/models/fleet_vehicle_cost.py:76
#, python-format
msgid "You cannot delete an activation cost linked to a contract. You should delete the contract instead."
msgstr ""
#. module: fleet
#: model_terms:ir.ui.view,arch_db:fleet.fleet_vehicle_log_contract_view_form
msgid "amount"
......
......@@ -70,6 +70,11 @@ class FleetVehicleCost(models.Model):
del data['odometer']
return super(FleetVehicleCost, self).create(vals_list)
@api.multi
def unlink(self):
if self.contract_id:
raise UserError(_('You cannot delete an activation cost linked to a contract. You should delete the contract instead.'))
return super(FleetVehicleCost, self).unlink()
class FleetVehicleLogContract(models.Model):
_inherit = ['mail.thread', 'mail.activity.mixin']
......@@ -187,6 +192,14 @@ class FleetVehicleLogContract(models.Model):
self.activity_reschedule(['fleet.mail_act_fleet_contract_to_renew'], date_deadline=vals.get('expiration_date'), new_user_id=vals.get('user_id'))
return res
@api.multi
def unlink(self):
cost_to_unlink = self.cost_id
res = super(FleetVehicleLogContract, self).unlink()
if cost_to_unlink:
cost_to_unlink.unlink()
return res
@api.multi
def contract_close(self):
for record in self:
......
......@@ -10,6 +10,7 @@
<field name="description"/>
<field name="cost_subtype_id"/>
<field name="date"/>
<field name="contract_id"/>
</tree>
</field>
</record>
......@@ -126,6 +127,7 @@
</group>
<group>
<field name="date"/>
<field name="contract_id"/>
<field name="parent_id" groups="base.group_no_one"/>
</group>
</group>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment