Skip to content

Commit

Permalink
[ADD] fleet_vehicle_capacity: add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Sep 4, 2024
1 parent 74124af commit cf97d8a
Show file tree
Hide file tree
Showing 19 changed files with 1,099 additions and 0 deletions.
108 changes: 108 additions & 0 deletions fleet_vehicle_capacity/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
======================
Fleet Vehicle Capacity
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c6363705ebe10d7daf6de26c5e8c9689066d8cb8d4c63d5b2e2eca9fc1fe5207
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-OCA%2Ffleet-lightgray.png?logo=github
:target: https://github.com/OCA/fleet/tree/14.0/fleet_vehicle_capacity
:alt: OCA/fleet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/fleet-14-0/fleet-14-0-fleet_vehicle_capacity
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/fleet&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds fields to manage the weight and volume capacity in the
vehicle model. It is also designed to be easily expandable, allowing the
addition of other vehicle-specific capacities in the future as needed.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, it first needs to be installed. Upon installation,
the system will automatically detect the default units of measure (UOM)
for vehicle weight, volume, and passenger capacity, and assign them to
vehicle models accordingly.

The module enhances the Odoo Fleet Management system by allowing
administrators to configure default UOMs for:

- Vehicle Weight (tons)
- Vehicle Volume Capacity (cubic meters)
- Passenger Capacity (number of passengers)

Key Features:

- Automatic Assignment of Default UOMs: After installation, the system
automatically assigns default UOMs to vehicle models based on the
standard UOMs (tons, cubic meters, and units).
- Configurable UOMs: The administrator can update the default UOMs for
vehicle weight, volume, and passenger capacity through the system
settings. Changes made to the default UOMs will be applied to all new
vehicle models automatically.
- Editable Vehicle Model UOMs: While vehicle models use the default
UOMs upon creation, the administrator can still manually override the
UOMs for specific models if needed.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/fleet/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/OCA/fleet/issues/new?body=module:%20fleet_vehicle_capacity%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.

Credits
=======

Authors
-------

* Escodoo

Contributors
------------

- ``Escodoo <https://www.escodoo.com.br>``\ \_:

- Marcel Savegnago marcel.savegnago@escodoo.com.br

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/fleet <https://github.com/OCA/fleet/tree/14.0/fleet_vehicle_capacity>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions fleet_vehicle_capacity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions fleet_vehicle_capacity/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Fleet Vehicle Capacity",
"summary": """
Add capacity fields to vehicles""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/fleet",
"depends": [
"fleet",
"uom",
],
"data": [
"views/res_config_settings.xml",
"views/fleet_vehicle_model.xml",
"views/fleet_vehicle.xml",
],
"demo": [],
}
3 changes: 3 additions & 0 deletions fleet_vehicle_capacity/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import fleet_vehicle
from . import fleet_vehicle_model
from . import res_config_settings
52 changes: 52 additions & 0 deletions fleet_vehicle_capacity/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FleetVehicle(models.Model):

_inherit = "fleet.vehicle"

vehicle_weight = fields.Float(
related="model_id.vehicle_weight",
string="Vehicle Weight",
help="The weight of the vehicle.",
readonly=False,
)

weight_capacity = fields.Float(
related="model_id.weight_capacity",
string="Weight Capacity",
help="The maximum weight capacity the vehicle can support.",
readonly=False,
)

volume_capacity = fields.Float(
related="model_id.volume_capacity",
string="Volume Capacity",
help="The maximum volume capacity the vehicle can support.",
readonly=False,
)

passenger_capacity = fields.Float(
related="model_id.passenger_capacity",
string="Passenger Capacity",
help="The maximum passenger capacity the vehicle can support.",
readonly=False,
)

weight_uom_id = fields.Many2one(
related="model_id.weight_uom_id",
string="Weight and Capacity UOM",
)

volume_uom_id = fields.Many2one(
related="model_id.volume_uom_id",
string="Volume Capacity UOM",
)

passenger_uom_id = fields.Many2one(
related="model_id.passenger_uom_id",
string="Passenger Capacity UOM",
)
103 changes: 103 additions & 0 deletions fleet_vehicle_capacity/models/fleet_vehicle_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2024 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import fields, models

_logger = logging.getLogger(__name__)


class FleetVehicleModel(models.Model):
_inherit = "fleet.vehicle.model"

vehicle_weight = fields.Float(
string="Vehicle Weight", help="The weight of the vehicle."
)

weight_capacity = fields.Float(
string="Weight Capacity",
help="The maximum weight capacity the vehicle can support.",
)

volume_capacity = fields.Float(
string="Volume Capacity",
help="The maximum volume capacity the vehicle can support.",
)

passenger_capacity = fields.Float(
string="Passenger Capacity",
help="The maximum passenger capacity the vehicle can support.",
)

def _get_vehicle_weight_uom_id_from_ir_config_parameter(self):
uom_id = (
self.env["ir.config_parameter"]
.sudo()
.get_param("fleet.default_vehicle_weight_uom_id")
)
if uom_id:
try:
return int(uom_id)
except ValueError:
_logger.error("Invalid Vehicle Weight UOM ID format: %s", uom_id)
return False

Check warning on line 44 in fleet_vehicle_capacity/models/fleet_vehicle_model.py

View check run for this annotation

Codecov / codecov/patch

fleet_vehicle_capacity/models/fleet_vehicle_model.py#L42-L44

Added lines #L42 - L44 were not covered by tests
else:
return self.env["res.config.settings"]._default_vehicle_weight_uom_id()

def _get_vehicle_volume_uom_id_from_ir_config_parameter(self):
uom_id = (
self.env["ir.config_parameter"]
.sudo()
.get_param("fleet.default_vehicle_volume_uom_id")
)
if uom_id:
try:
return int(uom_id)
except ValueError:
_logger.error("Invalid Vehicle Volume UOM ID format: %s", uom_id)
return False

Check warning on line 59 in fleet_vehicle_capacity/models/fleet_vehicle_model.py

View check run for this annotation

Codecov / codecov/patch

fleet_vehicle_capacity/models/fleet_vehicle_model.py#L57-L59

Added lines #L57 - L59 were not covered by tests
else:
return self.env["res.config.settings"]._default_vehicle_volume_uom_id()

def _get_vehicle_passenger_uom_id_from_ir_config_parameter(self):
uom_id = (
self.env["ir.config_parameter"]
.sudo()
.get_param("fleet.default_vehicle_passenger_uom_id")
)
if uom_id:
try:
return int(uom_id)
except ValueError:
_logger.error("Invalid Vehicle Passenger UOM ID format: %s", uom_id)
return False

Check warning on line 74 in fleet_vehicle_capacity/models/fleet_vehicle_model.py

View check run for this annotation

Codecov / codecov/patch

fleet_vehicle_capacity/models/fleet_vehicle_model.py#L72-L74

Added lines #L72 - L74 were not covered by tests
else:
return self.env["res.config.settings"]._default_vehicle_passenger_uom_id()

weight_uom_id = fields.Many2one(
"uom.uom",
string="Weight and Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id)
],
default=lambda x: x._get_vehicle_weight_uom_id_from_ir_config_parameter(),
)

volume_uom_id = fields.Many2one(
"uom.uom",
string="Volume Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_vol").id)
],
default=lambda x: x._get_vehicle_volume_uom_id_from_ir_config_parameter(),
)

passenger_uom_id = fields.Many2one(
"uom.uom",
string="Passenger Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_unit").id)
],
default=lambda x: x._get_vehicle_passenger_uom_id_from_ir_config_parameter(),
)
88 changes: 88 additions & 0 deletions fleet_vehicle_capacity/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2024 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

vehicle_weight_uom_id = fields.Many2one(
"uom.uom",
string="Default Vehicle Weight and Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id),
],
default=lambda self: self._default_vehicle_weight_uom_id(),
help="Default Unit of measure for vehicle weight and capacity.",
default_model="res.config.settings",
config_parameter="fleet.default_vehicle_weight_uom_id",
)

vehicle_volume_uom_id = fields.Many2one(
"uom.uom",
string="Default Vehicle Volume Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_vol").id),
],
default=lambda self: self._default_vehicle_volume_uom_id(),
help="Default Unit of measure for vehicle volume capacity.",
default_model="res.config.settings",
config_parameter="fleet.default_vehicle_volume_uom_id",
)

vehicle_passenger_uom_id = fields.Many2one(
"uom.uom",
string="Default Vehicle Passenger Capacity UOM",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_unit").id),
],
default=lambda self: self._default_vehicle_passenger_uom_id(),
help="Default Unit of measure for vehicle passenger capacity.",
default_model="res.config.settings",
config_parameter="fleet.default_vehicle_passenger_uom_id",
)

@api.model
def _default_vehicle_weight_uom_id(self):
"""Method to find and return the default UOM for vehicle weight and capacity."""
uom = self.env["uom.uom"].search(
[
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id),
("uom_type", "=", "bigger"),
],
limit=1,
order="id",
)
return uom.id if uom else False

@api.model
def _default_vehicle_volume_uom_id(self):
"""Method to find and return the default UOM for vehicle volume capacity."""
uom = self.env["uom.uom"].search(
[
("category_id", "=", self.env.ref("uom.product_uom_categ_vol").id),
("uom_type", "=", "bigger"),
],
limit=1,
order="id",
)
return uom.id if uom else False

@api.model
def _default_vehicle_passenger_uom_id(self):
"""Method to find and return the default UOM for vehicle passenger capacity."""
uom = self.env["uom.uom"].search(
[
("category_id", "=", self.env.ref("uom.product_uom_categ_unit").id),
("uom_type", "=", "reference"),
],
limit=1,
order="id",
)
return uom.id if uom else False
5 changes: 5 additions & 0 deletions fleet_vehicle_capacity/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>

1 change: 1 addition & 0 deletions fleet_vehicle_capacity/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds fields to manage the weight and volume capacity in the vehicle model. It is also designed to be easily expandable, allowing the addition of other vehicle-specific capacities in the future as needed.
Loading

0 comments on commit cf97d8a

Please sign in to comment.