-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC] egd_cnh_date_expiry: refactor module
- Loading branch information
1 parent
3c829bb
commit 17482ce
Showing
6 changed files
with
96 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
# 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 models | ||
from odoo import api, fields, models | ||
|
||
|
||
class HrEmployee(models.Model): | ||
|
||
_inherit = "hr.employee" | ||
|
||
def _get_employee_expirations(self): | ||
expiration_date_threshold = datetime.now() + timedelta(days=30) | ||
employees = self.env["hr.employee"].search( | ||
[("expiration_date", "<=", expiration_date_threshold)] | ||
) | ||
expirations = [] | ||
for employee in employees: | ||
days_until_expiration = ( | ||
employee.expiration_date - datetime.now().date() | ||
).days | ||
expirations.append( | ||
{"name": employee.name, "days_until_expiration": days_until_expiration} | ||
) | ||
return expirations | ||
|
||
def action_view_employee_expirations(self): | ||
expirations = self._get_employee_expirations() | ||
return { | ||
"name": "Employees with Expiration Date Approaching", | ||
"view_mode": "tree", | ||
"res_model": "employee.expiration", | ||
"type": "ir.actions.act_window", | ||
"context": {"create": False}, | ||
"domain": [], | ||
"view_id": False, | ||
"views": [(False, "tree")], | ||
"target": "current", | ||
"readonly": True, | ||
"limit": 80, | ||
"auto_search": False, | ||
"auto_refresh": 1, | ||
"expirations": expirations, | ||
} | ||
cnh_days_to_expire = fields.Integer( | ||
string="CNH Days to Expire", | ||
compute="_compute_cnh_days_to_expire", | ||
readonly=True, | ||
) | ||
cnh_expiry_state = fields.Selection( | ||
selection=[ | ||
("valid", "Valid"), | ||
("expiring_soon", "Expiring Soon"), | ||
("expired", "Expired"), | ||
("no_cnh", "No CNH"), | ||
], | ||
string="CNH Expiry State", | ||
compute="_compute_cnh_expiry_state", | ||
store=True, | ||
readonly=True, | ||
) | ||
|
||
@api.depends("expiration_date") | ||
def _compute_cnh_days_to_expire(self): | ||
today = date.today() | ||
for employee in self: | ||
if employee.expiration_date: | ||
days = (employee.expiration_date - today).days | ||
employee.cnh_days_to_expire = days | ||
else: | ||
employee.cnh_days_to_expire = 0 | ||
employee._compute_cnh_expiry_state() | ||
|
||
@api.depends("driver_license", "cnh_days_to_expire") | ||
def _compute_cnh_expiry_state(self): | ||
for employee in self: | ||
if not employee.driver_license: | ||
employee.cnh_expiry_state = "no_cnh" | ||
else: | ||
if employee.cnh_days_to_expire < 0: | ||
employee.cnh_expiry_state = "expired" | ||
elif employee.cnh_days_to_expire <= 30: | ||
employee.cnh_expiry_state = "expiring_soon" | ||
else: | ||
employee.cnh_expiry_state = "valid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
To use this module you need: | ||
|
||
1- Access the employee module and set an expiration date for the driver's license | ||
2 - When the validity is close to one month, | ||
it will appear in a view in fleet/vehicles as cnh expiry | ||
1 - Access the employee module and set an expiration date for the driver's license | ||
2 - In employee tree view, you will have the fields related to driver license expiration | ||
and filters to search driver license expired or expiring soon. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-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). | ||
--> | ||
<odoo> | ||
<record id="view_employee_expiration_tree" model="ir.ui.view"> | ||
<field name="name">hr.employee.expiration.tree (in egd_CNH_expiry)</field> | ||
|
||
<record id="view_employee_tree" model="ir.ui.view"> | ||
<field name="name">hr.employee.tree (in egd_cnh_date_expiry)</field> | ||
<field name="model">hr.employee</field> | ||
<field name="inherit_id" ref="hr.view_employee_tree" /> | ||
<field name="arch" type="xml"> | ||
<tree delete="false" create="false" string="CNH Expiry"> | ||
<field name="name" /> | ||
<field name="expiration_date" /> | ||
</tree> | ||
<field name="work_location" position="after"> | ||
<field name="driver_license" optional="hide" /> | ||
<field name="driver_categ" optional="hide" /> | ||
<field name="expiration_date" optional="hide" /> | ||
<field name="cnh_days_to_expire" optional="hide" /> | ||
<field | ||
name="cnh_expiry_state" | ||
optional="hide" | ||
widget="badge" | ||
decoration-success="cnh_expiry_state == 'valid'" | ||
decoration-warning="cnh_expiry_state == 'expiring_soon'" | ||
decoration-danger="cnh_expiry_state == 'expired'" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="action_employee_expiration" model="ir.actions.act_window"> | ||
<field name="name">CNH Expiry</field> | ||
<field name="res_model">hr.employee</field> | ||
<field name="view_mode">tree</field> | ||
<field name="domain">[('expiration_date', '<=', (context_today() + | ||
relativedelta(days=30)).strftime('%Y-%m-%d')), ('expiration_date', '>=', | ||
context_today().strftime('%Y-%m-%d'))]</field> | ||
<record id="view_employee_filter" model="ir.ui.view"> | ||
<field name="name">hr.employee.search (in egd_cnh_date_expiry)</field> | ||
<field name="model">hr.employee</field> | ||
<field name="inherit_id" ref="hr.view_employee_filter" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//filter[@name='inactive']" position="before"> | ||
<filter | ||
string="CNH Expired" | ||
name="cnh_expired" | ||
domain="[('cnh_expiry_state', '=', 'expired')]" | ||
/> | ||
<filter | ||
string="CNH Expiring Soon" | ||
name="cnh_expiring_soon" | ||
domain="[('cnh_expiry_state', '=', 'expiring_soon')]" | ||
/> | ||
<separator /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
|
||
</odoo> |