Skip to content

Commit

Permalink
Merge PR #135 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by max3903
  • Loading branch information
OCA-git-bot committed Oct 16, 2024
2 parents 96d70e1 + 1070417 commit 1ef9932
Show file tree
Hide file tree
Showing 21 changed files with 1,069 additions and 0 deletions.
146 changes: 146 additions & 0 deletions tms_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
==============
TMS - Purchase
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:88ffa252a6135ec7f3a8a2b5292cff001c17c8ba69a60a5975aaeb7b73479739
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_purchase
: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_purchase
: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 - Purchase module manages purchase requests to drivers and other
suppliers. This module provides features such as create purchase orders
from trips and purchase vehicles.

.. 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 Trips block, enable the "Manage trip purchases" setting.

Apps list
---------

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

Usage
=====

Purchase vehicles
-----------------

1. Go to Purchase module.
2. Create a new purchase quotation.
3. Add a product that is marked as a vehicle (TMS - Product module).
4. Select the quantity and the unit of measure.
5. Confirm the order.
6. Click "Receive Products" or use the smart button to validate the
receipt in the stock move.
7. The fleet vehicle records will be created with the quantity received.

Purchase from trips
-------------------

1. Go to Transport module.
2. Create or select a trip.
3. In the Purchase page add a new purchase.
4. The purchase will be linked to the trip automatically.

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_purchase%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 [email protected]
- Edgar Martinez [email protected]
- Maxime Chambreuil [email protected]

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_purchase>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions tms_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2018 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
20 changes: 20 additions & 0 deletions tms_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2018 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "TMS - Purchase",
"summary": "Manage purchase requests to drivers and other suppliers",
"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", "tms_product", "purchase"],
"data": [
"views/tms_order.xml",
"views/purchase_order_views.xml",
"views/fleet_vehicle_views.xml",
],
"demo": [],
"development_status": "Alpha",
"maintainers": ["max3903", "santiagordz", "EdgarRetes"],
}
4 changes: 4 additions & 0 deletions tms_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import fleet_vehicle
from . import purchase_order
from . import tms_order
from . import stock_move
18 changes: 18 additions & 0 deletions tms_purchase/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import _, fields, models


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

purchase_order_id = fields.Many2one("purchase.order")

def action_view_order(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"res_model": "purchase.order",
"view_mode": "form",
"res_id": self.purchase_order_id.id,
"target": "current",
"name": _("Purchase order: %s") % self.purchase_order_id.name,
}
84 changes: 84 additions & 0 deletions tms_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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 PurchaseOrder(models.Model):
_inherit = "purchase.order"
trip_id = fields.Many2one("tms.order")
vehicle_ids = fields.One2many("fleet.vehicle", "purchase_order_id")
vehicle_count = fields.Integer(compute="_compute_vehicle_count", readonly=True)

order_vehicle_count = fields.Integer(
compute="_compute_order_vehicle_count",
string="Vehicle Count",
copy=False,
default=0,
store=True,
)

@api.depends("vehicle_ids")
def _compute_order_vehicle_count(self):
for order in self:
order.order_vehicle_count = len(order.vehicle_ids)

def action_view_order(self):
self.ensure_one()
return {
"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,
}

def action_view_vehicle(self, vehicles=False):
"""This function returns an action that display existing vehicles from
given purchase order ids. When only one found, show the vehicle immediately.
"""

if not vehicles:
self.invalidate_model(["vehicle_ids"])
vehicles = self.vehicle_ids

result = self.env["ir.actions.act_window"]._for_xml_id(
"fleet.fleet_vehicle_action"
)

if len(vehicles) > 1:
result["domain"] = [("id", "in", vehicles.ids)]
elif len(vehicles) == 1:
vehicle_id = vehicles.id
result = {
"type": "ir.actions.act_window",
"name": "Vehicle",
"res_model": "fleet.vehicle",
"res_id": vehicle_id,
"view_mode": "form",
"view_id": self.env.ref("fleet.fleet_vehicle_view_form").id,
"target": "current",
}
else:
result = {"type": "ir.actions.act_window_close"}

return result

@api.model
def action_view_vehicles_button(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"res_model": "fleet.vehicle",
"view_mode": "tree,form",
"domain": [("purchase_order_id", "=", self.id)],
"context": {"default_order_id": self.id},
"name": _("Vehicles from purchase order %s") % self.name,
}

@api.depends("vehicle_ids")
def _compute_vehicle_count(self):
for record in self:
record.vehicle_count = len(record.vehicle_ids)
19 changes: 19 additions & 0 deletions tms_purchase/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 - TODAY, Marcel Savegnago <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def _prepare_vehicle_values(self, move_line):
purchase_order = self.env["purchase.order"].search([("name", "=", self.origin)])
return {
"name": f"{move_line.product_id.name} ({move_line.lot_id.name})",
"model_id": move_line.product_id.model_id.id,
"product_id": move_line.product_id.id,
"stock_picking_id": self.picking_id.id,
"lot_id": move_line.lot_id.id,
"purchase_order_id": purchase_order.id,
}
38 changes: 38 additions & 0 deletions tms_purchase/models/tms_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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"

purchase_ids = fields.One2many("purchase.order", "trip_id", store=True)
purchase_order_count = fields.Integer(
compute="_compute_purchase_order_count", readonly=True
)

def action_view_purchase_orders(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"res_model": "purchase.order",
"view_mode": "tree,form",
"domain": [("trip_id", "=", self.id)],
"context": {"default_trip_id": self.id},
"name": _("Purchase orders for Trip %s") % self.name,
}

@api.depends("purchase_ids")
def _compute_purchase_order_count(self):
for order in self:
order.purchase_order_count = len(order.purchase_ids)

@api.model
def create(self, vals):
order = super().create(vals)
if len(order.purchase_ids) > 0:
for purchase in order.purchase_ids:
purchase.trip_id = order
return order
3 changes: 3 additions & 0 deletions tms_purchase/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_purchase/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Santiago Rodriguez <[email protected]>
- Edgar Martinez <[email protected]>
- Maxime Chambreuil <[email protected]>
1 change: 1 addition & 0 deletions tms_purchase/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Open Source Integrators <https://opensourceintegrators.com>
2 changes: 2 additions & 0 deletions tms_purchase/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The TMS - Purchase module manages purchase requests to drivers and other suppliers. This module provides features such
as create purchase orders from trips and purchase vehicles.
11 changes: 11 additions & 0 deletions tms_purchase/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 Trips block, enable the "Manage trip purchases" setting.

## Apps list
1. Go to Apps.
2. Search for TMS - Purchase module.
3. Install the module.
13 changes: 13 additions & 0 deletions tms_purchase/readme/MAINTAINERS.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.
14 changes: 14 additions & 0 deletions tms_purchase/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Purchase vehicles
1. Go to Purchase module.
2. Create a new purchase quotation.
3. Add a product that is marked as a vehicle (TMS - Product module).
4. Select the quantity and the unit of measure.
5. Confirm the order.
6. Click "Receive Products" or use the smart button to validate the receipt in the stock move.
7. The fleet vehicle records will be created with the quantity received.

## Purchase from trips
1. Go to Transport module.
2. Create or select a trip.
3. In the Purchase page add a new purchase.
4. The purchase will be linked to the trip automatically.
Binary file added tms_purchase/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 1ef9932

Please sign in to comment.