Skip to content

Commit

Permalink
[ADD] tms_expense
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagordz authored and EdgarRetes committed Oct 25, 2024
1 parent 11c868d commit aabd809
Show file tree
Hide file tree
Showing 22 changed files with 1,000 additions and 0 deletions.
135 changes: 135 additions & 0 deletions tms_expense/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
=============
TMS - Expense
=============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:65ec3a61c01781d3682b41318b29cdf68ed5dfaebaa56633685d68e6431c29e5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fstock--logistics--transport-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-transport/tree/17.0/tms_expense
:alt: OCA/stock-logistics-transport
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-transport-17-0/stock-logistics-transport-17-0-tms_expense
: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/stock-logistics-transport&target_branch=17.0
:alt: Try me on Runboat

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

The TMS - Expense module allows drivers and users to register expenses
in trips. This module creates two new expense categories: Fuel and Toll
expenses.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Installation
============

There are two ways of installing the module:

Transport settings
------------------

1. Go to Transport app.
2. Go to Configuration > Settings.
3. In the Trip block, enable the "Manage trip-expenses" setting.

Apps list
---------

1. Go to Apps.
2. Search for TMS - Expense module.
3. Install the module.

Usage
=====

Create expenses in trips
------------------------

1. Go to Transport module.
2. Select or create a new trip.
3. In the Expense page, create a new expense. The driver is set as the
default employee that registered the expense.
4. When the trip is completed, the expense is automatically submitted.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-transport/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/stock-logistics-transport/issues/new?body=module:%20tms_expense%0Aversion:%2017.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
-------

* Open Source Integrators

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

- Santiago Rodriguez srodriguez@opensourceintegrators.com
- Edgar Martinez emartinez@opensourceintegrators.com
- Maxime Chambreuil mchambreuil@opensourceintegrators.com

Other credits
-------------

- Open Source Integrators https://opensourceintegrators.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.

.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px
:target: https://github.com/max3903
:alt: max3903
.. |maintainer-santiagordz| image:: https://github.com/santiagordz.png?size=40px
:target: https://github.com/santiagordz
:alt: santiagordz
.. |maintainer-EdgarRetes| image:: https://github.com/EdgarRetes.png?size=40px
:target: https://github.com/EdgarRetes
:alt: EdgarRetes

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-max3903| |maintainer-santiagordz| |maintainer-EdgarRetes|

This module is part of the `OCA/stock-logistics-transport <https://github.com/OCA/stock-logistics-transport/tree/17.0/tms_expense>`_ 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 tms_expense/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions tms_expense/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2018 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "TMS - Expense",
"summary": "Manage expenses of a trip: hotel, tolls, fuel",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"category": "TMS",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-transport",
"depends": ["tms", "hr_expense"],
"data": [
"data/hr_expense_data.xml",
"data/hr_employee_driver.xml",
"views/hr_expense_views.xml",
"views/tms_order.xml",
],
"demo": [],
"development_status": "Alpha",
"maintainers": ["max3903", "santiagordz", "EdgarRetes"],
}
3 changes: 3 additions & 0 deletions tms_expense/data/hr_employee_driver.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<odoo noupdate="1">
<function model="tms.driver" name="update_existing_drivers_as_employees" />
</odoo>
27 changes: 27 additions & 0 deletions tms_expense/data/hr_expense_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<odoo noupdate="1">
<record id="expense_trip_toll" model="product.product">
<field name="name">Toll</field>
<field name="description">Toll expenses for transportation trips</field>
<field name="standard_price">0.0</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="default_code">TOLL</field>
<field name="can_be_expensed" eval="True" />
<field name="sale_ok" eval="False" />
<field name="purchase_ok" eval="False" />
</record>

<record id="expense_trip_fuel" model="product.product">
<field name="name">Fuel</field>
<field name="description">Fuel expenses for transportation trips</field>
<field name="standard_price">0.0</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="default_code">FUEL</field>
<field name="can_be_expensed" eval="True" />
<field name="sale_ok" eval="False" />
<field name="purchase_ok" eval="False" />
</record>
</odoo>
3 changes: 3 additions & 0 deletions tms_expense/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import hr_expense
from . import tms_driver
from . import tms_order
21 changes: 21 additions & 0 deletions tms_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models


class HrExpense(models.Model):
_inherit = "hr.expense"

trip_id = fields.Many2one("tms.order")

def action_view_order(self):
self.ensure_one()
return {

Check warning on line 14 in tms_expense/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/hr_expense.py#L13-L14

Added lines #L13 - L14 were not covered by tests
"type": "ir.actions.act_window",
"res_model": "tms.order",
"view_mode": "form",
"res_id": self.trip_id.id,
"target": "current",
"name": _("Trip: %s") % self.trip_id.name,
}
38 changes: 38 additions & 0 deletions tms_expense/models/tms_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class TmsDriver(models.Model):
_inherit = "tms.driver"

@api.model
def create(self, vals):
driver = super().create(vals)
self.create_driver_employee(driver)
return driver

Check warning on line 14 in tms_expense/models/tms_driver.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_driver.py#L12-L14

Added lines #L12 - L14 were not covered by tests

@api.model
def update_existing_drivers_as_employees(self):
drivers = self.env["tms.driver"].search([])
for driver in drivers:
driver.create_driver_employee(driver)

def open_commercial_entity(self):
res = super().open_commercial_entity()
return res

Check warning on line 24 in tms_expense/models/tms_driver.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_driver.py#L23-L24

Added lines #L23 - L24 were not covered by tests

def create_driver_employee(self, driver):
employee = self.env["hr.employee"].search([("name", "=", driver.name)], limit=1)

if not employee:
employee_id = self.env["hr.employee"].create(
{
"name": driver.name,
"work_email": driver.email,
"work_phone": driver.phone,
"work_contact_id": driver.id,
}
)
driver.partner_id.employee_ids = [(4, employee_id.id)]
60 changes: 60 additions & 0 deletions tms_expense/models/tms_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class TMSOrder(models.Model):
_inherit = "tms.order"

expense_ids = fields.One2many(
"hr.expense",
"trip_id",
)

employee_id = fields.Many2one(
"hr.employee",
string="Driver",
compute="_compute_driver_employee_id",
store=True,
)

expense_count = fields.Integer(compute="_compute_expenses")

@api.depends("driver_id")
def _compute_driver_employee_id(self):
for record in self:
record.employee_id = self.env["hr.employee"].search(
[("work_contact_id", "=", record.driver_id.id)], limit=1
)
if not record.employee_id:
record.employee_id = self.env["hr.employee"].search(
[("address_id", "=", record.driver_id.id)], limit=1
)

@api.model
def write(self, vals):
result = super().write(vals)

Check warning on line 37 in tms_expense/models/tms_order.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_order.py#L37

Added line #L37 was not covered by tests
if "stage_id" in vals:
if vals["stage_id"] == 3:
for expense in self.expense_ids:
if expense.state != "reported":
expense.action_submit_expenses()
expense.sheet_id.action_submit_sheet()
return result

Check warning on line 44 in tms_expense/models/tms_order.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_order.py#L42-L44

Added lines #L42 - L44 were not covered by tests

@api.depends("expense_ids")
def _compute_expenses(self):
for record in self:
record.expense_count = len(record.expense_ids)

Check warning on line 49 in tms_expense/models/tms_order.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_order.py#L49

Added line #L49 was not covered by tests

def action_view_expenses(self):
self.ensure_one()
return {

Check warning on line 53 in tms_expense/models/tms_order.py

View check run for this annotation

Codecov / codecov/patch

tms_expense/models/tms_order.py#L52-L53

Added lines #L52 - L53 were not covered by tests
"type": "ir.actions.act_window",
"res_model": "hr.expense",
"view_mode": "tree,form",
"domain": [("trip_id", "=", self.id)],
"context": {"default_trip_id": self.id},
"name": _("Expenses for Trip %s") % self.name,
}
3 changes: 3 additions & 0 deletions tms_expense/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions tms_expense/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Santiago Rodriguez <srodriguez@opensourceintegrators.com>
- Edgar Martinez <emartinez@opensourceintegrators.com>
- Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
1 change: 1 addition & 0 deletions tms_expense/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Open Source Integrators <https://opensourceintegrators.com>
1 change: 1 addition & 0 deletions tms_expense/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The TMS - Expense module allows drivers and users to register expenses in trips. This module creates two new expense categories: Fuel and Toll expenses.
11 changes: 11 additions & 0 deletions tms_expense/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
There are two ways of installing the module:

## Transport settings
1. Go to Transport app.
2. Go to Configuration > Settings.
3. In the Trip block, enable the "Manage trip-expenses" setting.

## Apps list
1. Go to Apps.
2. Search for TMS - Expense module.
3. Install the module.
13 changes: 13 additions & 0 deletions tms_expense/readme/MANTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This module is maintained by the OCA.

[![Odoo Community Association](https://odoo-community.org/logo.png)](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/stock-logistics-transport <https://github.com/OCA/stock-logistics-transport/tree/16.0/shipment_advice>`\_
project on GitHub.

You are welcome to contribute. To learn how please visit
https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions tms_expense/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Create expenses in trips
1. Go to Transport module.
2. Select or create a new trip.
3. In the Expense page, create a new expense. The driver is set as the default employee that registered the expense.
4. When the trip is completed, the expense is automatically submitted.
Binary file added tms_expense/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit aabd809

Please sign in to comment.