Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][RFC] egd_ipva_date_expiry: refactor module #53

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 29 additions & 41 deletions egd_ipva_date_expiry/README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
====================
Egd Ipva 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:e2ab2a3df8a5165e39df984c429792a78cdbbb98dfd0d8e6eaaa585c827aa8f0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_ipva_date_expiry
:alt: Escodoo/egd-addons

|badge1|
|badge1| |badge2| |badge3|

Module monitor IPVA due dates

Expand All @@ -14,25 +29,22 @@ Module monitor IPVA due dates
.. contents::
:local:



Usage
=====


To use this module you need:

1 - In the vehicle registration, enter an expiration date for the IPVA

2 - Enter the ipva expiry menu and expiries close to 1 month will appear
2 - In fleet vehicles tree view, you will have the fields related to IPVA expiration
and filters to search vehicles with IPVA 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_ipva_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 @@ -47,39 +59,15 @@ Authors
Contributors
~~~~~~~~~~~~

* Marcel Savegnago <[email protected]>

* Matheus Marques <[email protected]>

Other credits
~~~~~~~~~~~~~
* `Escodoo <https://escodoo.com.br>`_:

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 <wesley.oliveira@escodoo.com.br>

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_ipva_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_ipva_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_ipva_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 19:15+0000\n"
"PO-Revision-Date: 2024-10-08 19:15+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_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle__display_name
msgid "Display Name"
msgstr "Nome exibido"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields.selection,name:egd_ipva_date_expiry.selection__fleet_vehicle__ipva_expiry_state__expired
msgid "Expired"
msgstr "Expirado"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields.selection,name:egd_ipva_date_expiry.selection__fleet_vehicle__ipva_expiry_state__expiring_soon
msgid "Expiring Soon"
msgstr "Expira em breve"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle__id
msgid "ID"
msgstr "ID"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle__ipva_days_to_expire
msgid "IPVA Days to Expire"
msgstr "Dias para Expirar IPVA"

#. module: egd_ipva_date_expiry
#: model_terms:ir.ui.view,arch_db:egd_ipva_date_expiry.fleet_vehicle_view_search
msgid "IPVA Expired"
msgstr "IPVA Expirado"

#. module: egd_ipva_date_expiry
#: model_terms:ir.ui.view,arch_db:egd_ipva_date_expiry.fleet_vehicle_view_search
msgid "IPVA Expiring Soon"
msgstr "IPVA Expira em Breve"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle__ipva_expiry_date
msgid "IPVA Expiry Date"
msgstr "Data de Expiração IPVA"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle__ipva_expiry_state
msgid "IPVA Expiry State"
msgstr "Status de Expiração IPVA"

#. module: egd_ipva_date_expiry
#: model_terms:ir.ui.view,arch_db:egd_ipva_date_expiry.fleet_vehicle_view_search
msgid "IPVA Valid"
msgstr "IPVA Válido"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields,field_description:egd_ipva_date_expiry.field_fleet_vehicle____last_update
msgid "Last Modified on"
msgstr "Última modificação em"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields.selection,name:egd_ipva_date_expiry.selection__fleet_vehicle__ipva_expiry_state__no_ipva
msgid "No IPVA"
msgstr "Sem IPVA"

#. module: egd_ipva_date_expiry
#: model:ir.model.fields.selection,name:egd_ipva_date_expiry.selection__fleet_vehicle__ipva_expiry_state__valid
msgid "Valid"
msgstr "Válido"

#. module: egd_ipva_date_expiry
#: model:ir.model,name:egd_ipva_date_expiry.model_fleet_vehicle
msgid "Vehicle"
msgstr "Veículo"
51 changes: 39 additions & 12 deletions egd_ipva_date_expiry/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 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

Expand All @@ -11,18 +12,44 @@ class FleetVehicle(models.Model):
_inherit = "fleet.vehicle"

ipva_expiry_date = fields.Date(string="IPVA Expiry Date", store="True")
ipva_near_expiry = fields.Boolean(
string="IPVA Near Expiry", compute="_compute_ipva_near_expiry"
ipva_days_to_expire = fields.Integer(
string="IPVA Days to Expire",
compute="_compute_ipva_days_to_expire",
readonly=True,
)
ipva_expiry_state = fields.Selection(
selection=[
("valid", "Valid"),
("expiring_soon", "Expiring Soon"),
("expired", "Expired"),
("no_ipva", "No IPVA"),
],
string="IPVA Expiry State",
compute="_compute_ipva_expiry_state",
store=True,
readonly=True,
)

@api.depends("ipva_expiry_date")
def _compute_ipva_near_expiry(self):
for vehicle in self:
if vehicle.ipva_expiry_date:
expiry_date = fields.Date.from_string(vehicle.ipva_expiry_date)
if expiry_date - datetime.now().date() <= timedelta(days=30):
vehicle.ipva_near_expiry = True
else:
vehicle.ipva_near_expiry = False
def _compute_ipva_days_to_expire(self):
today = date.today()
for fleet in self:
if fleet.ipva_expiry_date:
days = (fleet.ipva_expiry_date - today).days
fleet.ipva_days_to_expire = days
else:
vehicle.ipva_near_expiry = False
fleet.ipva_days_to_expire = 0
fleet._compute_ipva_expiry_state()

@api.depends("ipva_expiry_date", "ipva_days_to_expire")
def _compute_ipva_expiry_state(self):
for fleet in self:
if not fleet.ipva_expiry_date:
fleet.ipva_expiry_state = "no_ipva"
else:
if fleet.ipva_days_to_expire < 0:
fleet.ipva_expiry_state = "expired"
elif fleet.ipva_days_to_expire <= 30:
fleet.ipva_expiry_state = "expiring_soon"
else:
fleet.ipva_expiry_state = "valid"
7 changes: 5 additions & 2 deletions egd_ipva_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]>
3 changes: 2 additions & 1 deletion egd_ipva_date_expiry/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
To use this module you need:

1 - In the vehicle registration, enter an expiration date for the IPVA
2 - Enter the ipva expiry menu and expiries close to 1 month will appear
2 - In fleet vehicles tree view, you will have the fields related to IPVA expiration
and filters to search vehicles with IPVA expired, expiring soon or valid.
Loading
Loading