From d71de377fc85a58db821e2c921760aa3ace1db5e Mon Sep 17 00:00:00 2001 From: Wesley Oliveira Date: Tue, 8 Oct 2024 15:32:57 -0300 Subject: [PATCH] [RFC] egd_insurance_date_expiry: refactor module --- egd_insurance_date_expiry/README.rst | 75 ++- egd_insurance_date_expiry/i18n/pt_BR.po | 89 ++++ .../models/fleet_vehicle.py | 54 ++- .../readme/CONTRIBUTORS.rst | 7 +- egd_insurance_date_expiry/readme/USAGE.rst | 4 +- .../static/description/index.html | 430 ++++++++++++++++++ .../views/fleet_vehicle.xml | 97 ++-- 7 files changed, 656 insertions(+), 100 deletions(-) create mode 100644 egd_insurance_date_expiry/i18n/pt_BR.po create mode 100644 egd_insurance_date_expiry/static/description/index.html diff --git a/egd_insurance_date_expiry/README.rst b/egd_insurance_date_expiry/README.rst index d63ce4f..7d1b220 100644 --- a/egd_insurance_date_expiry/README.rst +++ b/egd_insurance_date_expiry/README.rst @@ -1,41 +1,50 @@ ========================= Egd Insurance Date Expiry ========================= -.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:98c107ca7f3a97932272ff5c651400c721400b5f5c0a8428969cd08eee41576c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-Escodoo%2Fegd--addons-lightgray.png?logo=github + :target: https://github.com/Escodoo/egd-addons/tree/14.0/egd_insurance_date_expiry + :alt: Escodoo/egd-addons -|badge1| +|badge1| |badge2| |badge3| -Module to track vehicle insurance expiry + Module to track vehicle insurance expiry **Table of contents** .. contents:: :local: - - - Usage ===== - To use this module you need: - 1 - In vehicle registration, fill in the insurance expiration date - -2 - In the insurance expiry menu there -will be vehicle expiry dates over a period of one month +2 - In fleet vehicles tree view, you will have the fields related to insurance expiration +and filters to search vehicles with insurance expired, expiring soon or valid. Bug Tracker =========== -Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smash it by providing detailed and welcomed feedback. +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -50,39 +59,15 @@ Authors Contributors ~~~~~~~~~~~~ -* Marcel Savegnago - -* Matheus Marques +* `Escodoo `_: -Other credits -~~~~~~~~~~~~~ - -The development of this module has been financially supported by: - -* Escodoo - `https://www.escodoo.com.br `_ + * Marcel Savegnago + * Matheus Marques + * Wesley Oliveira Maintainers ~~~~~~~~~~~ -This module is maintained by the Escodoo. - -.. |maintainer-escodoo| image:: https://github.com/escodoo.png?size=80px - :target: https://github.com/Escodoo - :alt: escodoo - -|maintainer-escodoo| - -We at Escodoo are exclusively dedicated to deploying the Odoo Platform and are -focused on providing solutions that make our customers more competitive, lowering -costs, making technology more accessible and ensuring it is used strategically to -add even more value to the business. - -.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px - :target: https://github.com/marcelsavegnago - :alt: marcelsavegnago - -Current `maintainer `__: - -|maintainer-marcelsavegnago| +This module is part of the `Escodoo/egd-addons `_ project on GitHub. -To contribute to this module, please visit https://www.escodoo.com.br. +You are welcome to contribute. diff --git a/egd_insurance_date_expiry/i18n/pt_BR.po b/egd_insurance_date_expiry/i18n/pt_BR.po new file mode 100644 index 0000000..2e1e9fa --- /dev/null +++ b/egd_insurance_date_expiry/i18n/pt_BR.po @@ -0,0 +1,89 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * egd_insurance_date_expiry +# +# Translators: +# Wesley Oliveira , 2024 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-10-08 18:27+0000\n" +"PO-Revision-Date: 2024-10-08 18:27+0000\n" +"Last-Translator: Wesley Oliveira, 2024" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle__display_name +msgid "Display Name" +msgstr "Nome exibido" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields.selection,name:egd_insurance_date_expiry.selection__fleet_vehicle__insurance_expiry_state__expired +msgid "Expired" +msgstr "Expirado" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields.selection,name:egd_insurance_date_expiry.selection__fleet_vehicle__insurance_expiry_state__expiring_soon +msgid "Expiring Soon" +msgstr "Expira em breve" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle__id +msgid "ID" +msgstr "ID" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle__insurance_days_to_expire +msgid "Insurance Days to Expire" +msgstr "Dias para Expirar Seguro" + +#. module: egd_insurance_date_expiry +#: model_terms:ir.ui.view,arch_db:egd_insurance_date_expiry.fleet_vehicle_view_search +msgid "Insurance Expired" +msgstr "Seguro Expirado" + +#. module: egd_insurance_date_expiry +#: model_terms:ir.ui.view,arch_db:egd_insurance_date_expiry.fleet_vehicle_view_search +msgid "Insurance Expiring Soon" +msgstr "Seguro Expira em Breve" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle__insurance_date_expiry +msgid "Insurance Expiry Date" +msgstr "Data de Expiração Seguro" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle__insurance_expiry_state +msgid "Insurance Expiry State" +msgstr "Status Expiração Seguro" + +#. module: egd_insurance_date_expiry +#: model_terms:ir.ui.view,arch_db:egd_insurance_date_expiry.fleet_vehicle_view_search +msgid "Insurance Valid" +msgstr "Seguro Válido" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields,field_description:egd_insurance_date_expiry.field_fleet_vehicle____last_update +msgid "Last Modified on" +msgstr "Última modificação em" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields.selection,name:egd_insurance_date_expiry.selection__fleet_vehicle__insurance_expiry_state__no_insurance +msgid "No Insurance" +msgstr "Sem Seguro" + +#. module: egd_insurance_date_expiry +#: model:ir.model.fields.selection,name:egd_insurance_date_expiry.selection__fleet_vehicle__insurance_expiry_state__valid +msgid "Valid" +msgstr "Válido" + +#. module: egd_insurance_date_expiry +#: model:ir.model,name:egd_insurance_date_expiry.model_fleet_vehicle +msgid "Vehicle" +msgstr "Veículo" diff --git a/egd_insurance_date_expiry/models/fleet_vehicle.py b/egd_insurance_date_expiry/models/fleet_vehicle.py index 4254686..865f697 100644 --- a/egd_insurance_date_expiry/models/fleet_vehicle.py +++ b/egd_insurance_date_expiry/models/fleet_vehicle.py @@ -1,27 +1,55 @@ # Copyright 2024 - TODAY, Matheus Marques +# Copyright 2024 - TODAY, Wesley Oliveira # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from datetime import datetime, timedelta +from datetime import date from odoo import api, fields, models class FleetVehicle(models.Model): + _inherit = "fleet.vehicle" - insurance_date_expiry = fields.Date(string="Insurance expiry date") - insurance_near_expiry = fields.Boolean( - string="insurance Near Expiry", compute="_compute_insurance_near_expiry" + insurance_date_expiry = fields.Date(string="Insurance Expiry Date") + insurance_days_to_expire = fields.Integer( + string="Insurance Days to Expire", + compute="_compute_insurance_days_to_expire", + readonly=True, + ) + insurance_expiry_state = fields.Selection( + selection=[ + ("valid", "Valid"), + ("expiring_soon", "Expiring Soon"), + ("expired", "Expired"), + ("no_insurance", "No Insurance"), + ], + string="Insurance Expiry State", + compute="_compute_insurance_expiry_state", + store=True, + readonly=True, ) @api.depends("insurance_date_expiry") - def _compute_insurance_near_expiry(self): - for vehicle in self: - if vehicle.insurance_date_expiry: - expiry_date = fields.Date.from_string(vehicle.insurance_date_expiry) - if expiry_date - datetime.now().date() <= timedelta(days=30): - vehicle.insurance_near_expiry = True - else: - vehicle.insurance_near_expiry = False + def _compute_insurance_days_to_expire(self): + today = date.today() + for fleet in self: + if fleet.insurance_date_expiry: + days = (fleet.insurance_date_expiry - today).days + fleet.insurance_days_to_expire = days else: - vehicle.insurance_near_expiry = False + fleet.insurance_days_to_expire = 0 + fleet._compute_insurance_expiry_state() + + @api.depends("insurance_date_expiry", "insurance_days_to_expire") + def _compute_insurance_expiry_state(self): + for fleet in self: + if not fleet.insurance_date_expiry: + fleet.insurance_expiry_state = "no_insurance" + else: + if fleet.insurance_days_to_expire < 0: + fleet.insurance_expiry_state = "expired" + elif fleet.insurance_days_to_expire <= 30: + fleet.insurance_expiry_state = "expiring_soon" + else: + fleet.insurance_expiry_state = "valid" diff --git a/egd_insurance_date_expiry/readme/CONTRIBUTORS.rst b/egd_insurance_date_expiry/readme/CONTRIBUTORS.rst index d019575..94ec8c1 100644 --- a/egd_insurance_date_expiry/readme/CONTRIBUTORS.rst +++ b/egd_insurance_date_expiry/readme/CONTRIBUTORS.rst @@ -1,2 +1,5 @@ -Marcel Savegnago -Matheus Marques +* `Escodoo `_: + + * Marcel Savegnago + * Matheus Marques + * Wesley Oliveira diff --git a/egd_insurance_date_expiry/readme/USAGE.rst b/egd_insurance_date_expiry/readme/USAGE.rst index 64720fe..c40c277 100644 --- a/egd_insurance_date_expiry/readme/USAGE.rst +++ b/egd_insurance_date_expiry/readme/USAGE.rst @@ -1,5 +1,5 @@ To use this module you need: 1 - In vehicle registration, fill in the insurance expiration date -2 - In the insurance expiry menu there -will be vehicle expiry dates over a period of one month +2 - In fleet vehicles tree view, you will have the fields related to insurance expiration +and filters to search vehicles with insurance expired, expiring soon or valid. diff --git a/egd_insurance_date_expiry/static/description/index.html b/egd_insurance_date_expiry/static/description/index.html new file mode 100644 index 0000000..0dfec7e --- /dev/null +++ b/egd_insurance_date_expiry/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Egd Insurance Date Expiry + + + +
+

Egd Insurance Date Expiry

+ + +

Beta License: AGPL-3 Escodoo/egd-addons

+
+Module to track vehicle insurance expiry
+

Table of contents

+ +
+

Usage

+

To use this module you need:

+

1 - In vehicle registration, fill in the insurance expiration date +2 - In fleet vehicles tree view, you will have the fields related to insurance expiration +and filters to search vehicles with insurance expired, expiring soon or valid.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Escodoo
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the Escodoo/egd-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/egd_insurance_date_expiry/views/fleet_vehicle.xml b/egd_insurance_date_expiry/views/fleet_vehicle.xml index 71ba71a..6a4f1c8 100644 --- a/egd_insurance_date_expiry/views/fleet_vehicle.xml +++ b/egd_insurance_date_expiry/views/fleet_vehicle.xml @@ -1,45 +1,66 @@ + + - - - fleet.vehicle.form (in egd_insurance_date_expiry) - fleet.vehicle - - - - - + + + fleet.vehicle.form (in egd_insurance_date_expiry) + fleet.vehicle + + + + - + + - - fleet.vehicle.insurance.tree (in egd_insurance_date_expiry) - fleet.vehicle - - - - - + + fleet.vehicle.tree (in egd_insurance_date_expiry) + fleet.vehicle + + + + + + - + + - - Insurance Expiry - fleet.vehicle - tree - - [('insurance_date_expiry', '<', (context_today() + relativedelta(days=30)).strftime('%Y-%m-%d'))] - {'search_default_expiring_insurance': True} - + + fleet.vehicle.search (in egd_insurance_date_expiry) + fleet.vehicle + + + + + + + + + + - -