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

[ADD][14.0] Add vehicle ownership, linking partners to vehicles #127 #130

Merged
merged 1 commit into from
Nov 26, 2023
Merged
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
106 changes: 106 additions & 0 deletions fleet_vehicle_ownership/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
=======================
Fleet Vehicle Ownership
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c10570fb68e2d39efee546647fe22fcfc8b4b8022f384619750d9cd0d8428027
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_ownership
: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_ownership
: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 extends the functionality of fleet to support vehicle owner
data and to allow you to add vehicle ownership, linking partners to
vehicles

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

This is an extension of the 'fleet.vehicle' model in the Odoo framework.
It introduces a new field, 'owner_id', to track and associate the owner
of a vehicle.

Fields:

- owner_id: Many2one field linking to the 'res.partner' model. It
represents the owner of the vehicle.

Usage:

- This extension is particularly useful in scenarios where it's
essential to associate each fleet vehicle with a specific owner.
- The 'owner_id' field can be utilized to establish relationships with
partners in the 'res.partner' model, facilitating clear ownership
tracking.

Usage
=====

To use this module, you need to:

1. Go to the veichle form and associate an owner or go to the partner
form and associate a vehicle.

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_ownership%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
-------

* RPSJR

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

- Raimundo Junior raimundopsjr@gmail.com

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_ownership>`_ 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_ownership/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions fleet_vehicle_ownership/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 RPSJR
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Fleet Vehicle Ownership",
"summary": "Add vehicle ownership, linking partners to vehicles",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "RPSJR,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/fleet",
"depends": ["fleet"],
"data": [
"views/res_partner.xml",
"views/fleet_vehicle.xml",
],
"demo": [
"demo/fleet_vehicle.xml",
],
}
21 changes: 21 additions & 0 deletions fleet_vehicle_ownership/demo/fleet_vehicle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 RPSJR
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="vehicle_29" model="fleet.vehicle">
<field name="license_plate">4-LH-44</field>
<field name="vin_sn">44444</field>
<field name="model_id">1</field>
<field name="color">Silver</field>
<field name="location">Silverstone</field>
<field name="owner_id" ref="base.partner_demo" />
<field
name="acquisition_date"
eval="(DateTime.now() - timedelta(days=336)).strftime('%Y-%m-%d')"
/>
<field name="odometer_unit">kilometers</field>
<field name="car_value">44000</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions fleet_vehicle_ownership/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import fleet_vehicle
from . import res_partner
18 changes: 18 additions & 0 deletions fleet_vehicle_ownership/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 RPSJR
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FleetVehicle(models.Model):

_inherit = "fleet.vehicle"

owner_id = fields.Many2one(
"res.partner",
"Owner",
index=True,
tracking=True,
help="Owner of the vehicle",
copy=False,
)
38 changes: 38 additions & 0 deletions fleet_vehicle_ownership/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 RPSJR
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

@api.depends("vehicle_ids")
def _compute_vehicle_count(self):
for rec in self:
rec.vehicle_count = len(rec.vehicle_ids)

vehicle_ids = fields.One2many(
"fleet.vehicle",
"owner_id",
required=True,
help="Vehicles owned by this partner",
)
vehicle_count = fields.Integer(
compute=_compute_vehicle_count, string="Number of Vehicles", store=True
)

def action_view_vehicles(self):
self.ensure_one()
xmlid = "fleet.fleet_vehicle_action"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add self.ensure_one()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
action["context"] = self.env.context.copy()
action["context"].update({"default_owner_id": self.id})
if self.vehicle_count > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recomend to add a default_owner_id = self.id on context

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

action["domain"] = [("id", "in", self.vehicle_ids.ids)]
else:
action["views"] = [
(self.env.ref("fleet.fleet_vehicle_view_form").id, "form")
]
action["res_id"] = self.vehicle_ids and self.vehicle_ids.ids[0] or False
return action
9 changes: 9 additions & 0 deletions fleet_vehicle_ownership/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is an extension of the 'fleet.vehicle' model in the Odoo framework.
It introduces a new field, 'owner_id', to track and associate the owner of a vehicle.

Fields:
- owner_id: Many2one field linking to the 'res.partner' model. It represents the owner of the vehicle.

Usage:
- This extension is particularly useful in scenarios where it's essential to associate each fleet vehicle with a specific owner.
- The 'owner_id' field can be utilized to establish relationships with partners in the 'res.partner' model, facilitating clear ownership tracking.
1 change: 1 addition & 0 deletions fleet_vehicle_ownership/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Raimundo Junior <raimundopsjr@gmail.com>
1 change: 1 addition & 0 deletions fleet_vehicle_ownership/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module extends the functionality of fleet to support vehicle owner data and to allow you to add vehicle ownership, linking partners to vehicles
3 changes: 3 additions & 0 deletions fleet_vehicle_ownership/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To use this module, you need to:

1. Go to the veichle form and associate an owner or go to the partner form and associate a vehicle.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading