Skip to content

Commit

Permalink
Merge pull request #52 from Escodoo/14.0-rfc-egd_insurance_date_expiry
Browse files Browse the repository at this point in the history
[14.0][RFC] egd_insurance_date_expiry: refactor module
  • Loading branch information
marcelsavegnago authored Dec 6, 2024
2 parents 2fa147a + 9f39145 commit ea45c88
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 100 deletions.
75 changes: 30 additions & 45 deletions egd_insurance_date_expiry/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/Escodoo/{project_repo}/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 <https://github.com/Escodoo/egd-addons/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 <https://github.com/Escodoo/egd-addons/issues/new?body=module:%20egd_insurance_date_expiry%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -50,39 +59,15 @@ Authors
Contributors
~~~~~~~~~~~~

* Marcel Savegnago <[email protected]>

* Matheus Marques <[email protected]>
* `Escodoo <https://escodoo.com.br>`_:

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Escodoo - `https://www.escodoo.com.br <https://www.escodoo.com.br>`_
* Marcel Savegnago <[email protected]>
* Matheus Marques <[email protected]>
* Wesley Oliveira <[email protected]>

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-marcelsavegnago|
This module is part of the `Escodoo/egd-addons <https://github.com/Escodoo/egd-addons/tree/14.0/egd_insurance_date_expiry>`_ project on GitHub.

To contribute to this module, please visit https://www.escodoo.com.br.
You are welcome to contribute.
89 changes: 89 additions & 0 deletions egd_insurance_date_expiry/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * egd_insurance_date_expiry
#
# Translators:
# Wesley Oliveira <[email protected]>, 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"
54 changes: 41 additions & 13 deletions egd_insurance_date_expiry/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
# Copyright 2024 - TODAY, Matheus Marques <[email protected]>
# Copyright 2024 - TODAY, Wesley Oliveira <[email protected]>
# 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"
7 changes: 5 additions & 2 deletions egd_insurance_date_expiry/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Marcel Savegnago <[email protected]>
Matheus Marques <[email protected]>
* `Escodoo <https://escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Matheus Marques <[email protected]>
* Wesley Oliveira <[email protected]>
4 changes: 2 additions & 2 deletions egd_insurance_date_expiry/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit ea45c88

Please sign in to comment.