From 3a0d84b33607342200f7711e4835446f35797540 Mon Sep 17 00:00:00 2001 From: Carolina Fernandez Date: Thu, 14 Dec 2023 18:10:43 -0300 Subject: [PATCH] [15.0][IMP] fleet_vehicle_inspection: Add cost vehicle inspection and create vehicle service --- fleet_vehicle_inspection/README.rst | 4 +- fleet_vehicle_inspection/i18n/es.po | 36 ++++++++++++++++++ .../i18n/fleet_vehicle_inspection.pot | 36 ++++++++++++++++++ fleet_vehicle_inspection/i18n/it.po | 36 ++++++++++++++++++ fleet_vehicle_inspection/i18n/pt_BR.po | 36 ++++++++++++++++++ .../models/fleet_vehicle_inspection.py | 38 +++++++++++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 6 ++- .../tests/test_fleet_vehicle_inspection.py | 28 ++++++++++++++ .../views/fleet_vehicle_inspection.xml | 10 +++++ 11 files changed, 229 insertions(+), 3 deletions(-) diff --git a/fleet_vehicle_inspection/README.rst b/fleet_vehicle_inspection/README.rst index b7e64bfd..0e8f0067 100644 --- a/fleet_vehicle_inspection/README.rst +++ b/fleet_vehicle_inspection/README.rst @@ -7,7 +7,7 @@ Fleet Vehicle Inspection !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:fce4f2a5a75b3e85a51c0573831ea5e4c6511dc7afad3fcc4bea8702516f13e8 + !! source digest: sha256:e9f054b06950870741c0c7c58018aee2c01a8d15fd0bbc92cfc1051094f77442 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -29,6 +29,7 @@ Fleet Vehicle Inspection |badge1| |badge2| |badge3| |badge4| |badge5| This module extends the Fleet module allowing the registration of vehicle entry and exit inspections. +Add Cost vehicle inspections. Once is confirmed, service vehicle is created. If inspection is cancelled, service vehicle is deleted. **Table of contents** @@ -72,6 +73,7 @@ Contributors * Marcel Savegnago * Brian McMaster +* Tecnativa - Carolina Fernandez Other credits ~~~~~~~~~~~~~ diff --git a/fleet_vehicle_inspection/i18n/es.po b/fleet_vehicle_inspection/i18n/es.po index afd05203..49f24d07 100644 --- a/fleet_vehicle_inspection/i18n/es.po +++ b/fleet_vehicle_inspection/i18n/es.po @@ -115,6 +115,11 @@ msgstr "Cancelar" msgid "Canceled" msgstr "Cancelada" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__company_id +msgid "Company" +msgstr "Compañía" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Confirm Inspection" @@ -125,6 +130,11 @@ msgstr "Confirmar Inspección" msgid "Confirmed" msgstr "Confirmada" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__amount +msgid "Cost" +msgstr "Coste" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_uid #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_uid @@ -141,6 +151,11 @@ msgstr "Creado por" msgid "Created on" msgstr "Creada en" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__currency_id +msgid "Currency" +msgstr "Moneda" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,help:fleet_vehicle_inspection.field_fleet_vehicle_inspection__date_inspected msgid "Date when the vehicle has been inspected" @@ -502,6 +517,12 @@ msgstr "Mensajes" msgid "Miles" msgstr "Millas" +#. module: fleet_vehicle_inspection +#: code:addons/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py:0 +#, python-format +msgid "Must select service type" +msgstr "Debe seleccionar el tipo de servicio" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__my_activity_date_deadline #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__my_activity_date_deadline @@ -665,6 +686,16 @@ msgstr "Descripción del Resultado" msgid "Sequence" msgstr "Secuencia" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_id +msgid "Service" +msgstr "Servicio" + +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_type_id +msgid "Service Type" +msgstr "Tipo de servicio" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Set to Draft" @@ -772,6 +803,11 @@ msgstr "Mensajes de la Página web" msgid "Website communication history" msgstr "Historial de comunicación del sitio web" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__vendor_id +msgid "Vendor" +msgstr "Proveedor" + #~ msgid "SMS Delivery error" #~ msgstr "Error de entrega de SMS" diff --git a/fleet_vehicle_inspection/i18n/fleet_vehicle_inspection.pot b/fleet_vehicle_inspection/i18n/fleet_vehicle_inspection.pot index a48a48ba..b5968a04 100644 --- a/fleet_vehicle_inspection/i18n/fleet_vehicle_inspection.pot +++ b/fleet_vehicle_inspection/i18n/fleet_vehicle_inspection.pot @@ -105,6 +105,11 @@ msgstr "" msgid "Canceled" msgstr "" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__company_id +msgid "Company" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Confirm Inspection" @@ -115,6 +120,11 @@ msgstr "" msgid "Confirmed" msgstr "" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__amount +msgid "Cost" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_uid #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_uid @@ -131,6 +141,11 @@ msgstr "" msgid "Created on" msgstr "" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__currency_id +msgid "Currency" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,help:fleet_vehicle_inspection.field_fleet_vehicle_inspection__date_inspected msgid "Date when the vehicle has been inspected" @@ -492,6 +507,12 @@ msgstr "" msgid "Miles" msgstr "" +#. module: fleet_vehicle_inspection +#: code:addons/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py:0 +#, python-format +msgid "Must select service type" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__my_activity_date_deadline #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__my_activity_date_deadline @@ -652,6 +673,16 @@ msgstr "" msgid "Sequence" msgstr "" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_id +msgid "Service" +msgstr "" + +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_type_id +msgid "Service Type" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Set to Draft" @@ -754,3 +785,8 @@ msgstr "" #: model:ir.model.fields,help:fleet_vehicle_inspection.field_fleet_vehicle_inspection_line__website_message_ids msgid "Website communication history" msgstr "" + +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__vendor_id +msgid "Vendor" +msgstr "" diff --git a/fleet_vehicle_inspection/i18n/it.po b/fleet_vehicle_inspection/i18n/it.po index 7c140d5d..82c10c3f 100644 --- a/fleet_vehicle_inspection/i18n/it.po +++ b/fleet_vehicle_inspection/i18n/it.po @@ -115,6 +115,11 @@ msgstr "Annulla" msgid "Canceled" msgstr "Annullata" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__company_id +msgid "Company" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Confirm Inspection" @@ -125,6 +130,11 @@ msgstr "Conferma ispezione" msgid "Confirmed" msgstr "Confermata" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__amount +msgid "Cost" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_uid #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_uid @@ -133,6 +143,11 @@ msgstr "Confermata" msgid "Created by" msgstr "Creato da" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__currency_id +msgid "Currency" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_date #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_date @@ -503,6 +518,12 @@ msgstr "Messaggi" msgid "Miles" msgstr "Miglia" +#. module: fleet_vehicle_inspection +#: code:addons/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py:0 +#, python-format +msgid "Must select service type" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__my_activity_date_deadline #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__my_activity_date_deadline @@ -666,6 +687,16 @@ msgstr "Descrizione risultato" msgid "Sequence" msgstr "Sequenza" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_id +msgid "Service" +msgstr "" + +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_type_id +msgid "Service Type" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Set to Draft" @@ -773,5 +804,10 @@ msgstr "Messaggi sito web" msgid "Website communication history" msgstr "Cronologia comunicazioni sito web" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__vendor_id +msgid "Vendor" +msgstr "" + #~ msgid "SMS Delivery error" #~ msgstr "Errore consegna SMS" diff --git a/fleet_vehicle_inspection/i18n/pt_BR.po b/fleet_vehicle_inspection/i18n/pt_BR.po index 2eed0dd0..01553b61 100644 --- a/fleet_vehicle_inspection/i18n/pt_BR.po +++ b/fleet_vehicle_inspection/i18n/pt_BR.po @@ -116,6 +116,11 @@ msgstr "Cancelar" msgid "Canceled" msgstr "Cancelado(a)" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__company_id +msgid "Company" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Confirm Inspection" @@ -126,6 +131,11 @@ msgstr "Confirmar Inspeção" msgid "Confirmed" msgstr "Confirmado" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__amount +msgid "Cost" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_uid #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_uid @@ -134,6 +144,11 @@ msgstr "Confirmado" msgid "Created by" msgstr "Criado por" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__currency_id +msgid "Currency" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__create_date #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__create_date @@ -503,6 +518,12 @@ msgstr "Mensagens" msgid "Miles" msgstr "Milhas" +#. module: fleet_vehicle_inspection +#: code:addons/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py:0 +#, python-format +msgid "Must select service type" +msgstr "" + #. module: fleet_vehicle_inspection #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__my_activity_date_deadline #: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection_item__my_activity_date_deadline @@ -666,6 +687,16 @@ msgstr "Descrição do Resultado" msgid "Sequence" msgstr "Sequência" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_id +msgid "Service" +msgstr "" + +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__service_type_id +msgid "Service Type" +msgstr "" + #. module: fleet_vehicle_inspection #: model_terms:ir.ui.view,arch_db:fleet_vehicle_inspection.fleet_vehicle_inspection_form_view msgid "Set to Draft" @@ -773,6 +804,11 @@ msgstr "" msgid "Website communication history" msgstr "" +#. module: fleet_vehicle_inspection +#: model:ir.model.fields,field_description:fleet_vehicle_inspection.field_fleet_vehicle_inspection__vendor_id +msgid "Vendor" +msgstr "" + #~ msgid "SMS Delivery error" #~ msgstr "Erro de entrega de SMS" diff --git a/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py b/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py index f9ff3d47..20bc3173 100644 --- a/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py +++ b/fleet_vehicle_inspection/models/fleet_vehicle_inspection.py @@ -1,4 +1,5 @@ # Copyright 2020 - TODAY, Marcel Savegnago - Escodoo https://www.escodoo.com.br +# Copyright 2023 Tecnativa - Carolina Fernandez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models @@ -102,6 +103,21 @@ class FleetVehicleInspection(models.Model): store=True, ) + amount = fields.Monetary("Cost") + service_type_id = fields.Many2one( + comodel_name="fleet.service.type", + string="Service Type", + domain=[("category", "=", "service")], + ) + vendor_id = fields.Many2one("res.partner", "Vendor") + service_id = fields.Many2one( + comodel_name="fleet.vehicle.log.services", readonly=True, copy=False + ) + company_id = fields.Many2one( + "res.company", "Company", default=lambda self: self.env.company + ) + currency_id = fields.Many2one("res.currency", related="company_id.currency_id") + @api.depends("inspection_line_ids", "state") def _compute_inspection_result(self): for rec in self: @@ -132,6 +148,9 @@ def create(self, vals): def button_cancel(self): records = self.filtered(lambda rec: rec.state in ["draft", "confirmed"]) + services = records.filtered(lambda rec: rec.service_id).mapped("service_id") + if services: + services.sudo().unlink() return records.write({"state": "cancel"}) def button_confirm(self): @@ -145,6 +164,25 @@ def button_confirm(self): raise ValidationError( _("Only inspections in 'draft' or 'cancel' states can be confirmed") ) + if self.amount: + if not self.service_type_id: + raise ValidationError(_("Must select service type")) + self.service_id = ( + self.env["fleet.vehicle.log.services"] + .create( + { + "service_type_id": self.service_type_id.id, + "description": self.name, + "vehicle_id": self.vehicle_id.id, + "amount": self.amount, + "odometer": self.odometer, + "vendor_id": self.vendor_id.id if self.vendor_id else False, + "state": "done", + } + ) + .id + ) + return self.write({"state": "confirmed"}) def button_draft(self): diff --git a/fleet_vehicle_inspection/readme/CONTRIBUTORS.rst b/fleet_vehicle_inspection/readme/CONTRIBUTORS.rst index a9a508da..4df017ce 100644 --- a/fleet_vehicle_inspection/readme/CONTRIBUTORS.rst +++ b/fleet_vehicle_inspection/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Marcel Savegnago * Brian McMaster +* Tecnativa - Carolina Fernandez diff --git a/fleet_vehicle_inspection/readme/DESCRIPTION.rst b/fleet_vehicle_inspection/readme/DESCRIPTION.rst index bbe6a771..5fb6de53 100644 --- a/fleet_vehicle_inspection/readme/DESCRIPTION.rst +++ b/fleet_vehicle_inspection/readme/DESCRIPTION.rst @@ -1 +1,2 @@ This module extends the Fleet module allowing the registration of vehicle entry and exit inspections. +Add Cost vehicle inspections. Once is confirmed, service vehicle is created. If inspection is cancelled, service vehicle is deleted. diff --git a/fleet_vehicle_inspection/static/description/index.html b/fleet_vehicle_inspection/static/description/index.html index abac9c43..1e8e5e51 100644 --- a/fleet_vehicle_inspection/static/description/index.html +++ b/fleet_vehicle_inspection/static/description/index.html @@ -367,10 +367,11 @@

Fleet Vehicle Inspection

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:fce4f2a5a75b3e85a51c0573831ea5e4c6511dc7afad3fcc4bea8702516f13e8 +!! source digest: sha256:e9f054b06950870741c0c7c58018aee2c01a8d15fd0bbc92cfc1051094f77442 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/fleet Translate me on Weblate Try me on Runboat

-

This module extends the Fleet module allowing the registration of vehicle entry and exit inspections.

+

This module extends the Fleet module allowing the registration of vehicle entry and exit inspections. +Add Cost vehicle inspections. Once is confirmed, service vehicle is created. If inspection is cancelled, service vehicle is deleted.

Table of contents

diff --git a/fleet_vehicle_inspection/tests/test_fleet_vehicle_inspection.py b/fleet_vehicle_inspection/tests/test_fleet_vehicle_inspection.py index 8e639dc7..c24700ae 100644 --- a/fleet_vehicle_inspection/tests/test_fleet_vehicle_inspection.py +++ b/fleet_vehicle_inspection/tests/test_fleet_vehicle_inspection.py @@ -1,4 +1,5 @@ # Copyright 2020 - TODAY, Marcel Savegnago - Escodoo +# Copyright 2023 Tecnativa - Carolina Fernandez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl from odoo.exceptions import UserError @@ -79,3 +80,30 @@ def test_fleet_vehicle_inspection(self): # inspection2 confirm without items with self.assertRaises(UserError): self.inspection2.button_confirm() + + def test_fleet_vehicle_inspection_with_amount(self): + test_vendor = self.env["res.partner"].create({"name": "test vendor"}) + self.inspection.inspection_line_ids[0].action_item_success() + self.inspection.inspection_line_ids[1].action_item_success() + self.inspection._compute_inspection_result() + self.inspection.amount = 100 + self.inspection.vendor_id = test_vendor.id + with self.assertRaises(UserError): + self.inspection.button_confirm() + self.inspection.service_type_id = self.env.ref("fleet.type_service_service_8") + self.inspection.button_confirm() + self.assertEqual(self.inspection.service_id.description, self.inspection.name) + self.assertEqual( + self.inspection.service_id.vendor_id, self.inspection.vendor_id + ) + self.assertEqual( + self.inspection.service_id.vehicle_id, self.inspection.vehicle_id + ) + self.assertEqual(self.inspection.service_id.odometer, self.inspection.odometer) + self.assertEqual( + self.inspection.service_id.service_type_id, self.inspection.service_type_id + ) + self.assertEqual(self.inspection.service_id.amount, self.inspection.amount) + self.assertEqual(self.inspection.service_id.state, "done") + self.inspection.button_cancel() + self.assertFalse(self.inspection.service_id) diff --git a/fleet_vehicle_inspection/views/fleet_vehicle_inspection.xml b/fleet_vehicle_inspection/views/fleet_vehicle_inspection.xml index 5b15410b..02da3798 100644 --- a/fleet_vehicle_inspection/views/fleet_vehicle_inspection.xml +++ b/fleet_vehicle_inspection/views/fleet_vehicle_inspection.xml @@ -64,6 +64,16 @@ + + + + + +