-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[17.0][ADD] fieldservice_equipment_stock_return: add return order type
- Loading branch information
ilo
committed
Oct 29, 2024
1 parent
0f9586a
commit 755ae2b
Showing
21 changed files
with
924 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
====================================== | ||
Field Service - Stock Equipment Return | ||
====================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:ccef108ff488fd2820ce9403b90512a866de4e4edaa606f7f03418b70520b741 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Ffield--service-lightgray.png?logo=github | ||
:target: https://github.com/OCA/field-service/tree/17.0/fieldservice_equipment_stock_return | ||
:alt: OCA/field-service | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/field-service-17-0/field-service-17-0-fieldservice_equipment_stock_return | ||
: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/field-service&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows you to return FSM equipments creating a new picking. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
Check ``Field Service - Stock Equipment`` module configuration. | ||
|
||
To configure this module, you need to: | ||
|
||
- Go to Field Service > Configuration > Order Types | ||
- Check if you have at least one ``return`` order type | ||
- Set the ``Picking Type`` linked to the ``return`` order type | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/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/field-service/issues/new?body=module:%20fieldservice_equipment_stock_return%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 | ||
------- | ||
|
||
* Camptocamp | ||
* Italo LOPES | ||
|
||
Contributors | ||
------------ | ||
|
||
- Italo LOPES <[email protected]> | ||
|
||
Other credits | ||
------------- | ||
|
||
The development of this module has been financially supported by: | ||
|
||
- Camptocamp SA <https://camptocamp.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-brian10048| image:: https://github.com/brian10048.png?size=40px | ||
:target: https://github.com/brian10048 | ||
:alt: brian10048 | ||
.. |maintainer-wolfhall| image:: https://github.com/wolfhall.png?size=40px | ||
:target: https://github.com/wolfhall | ||
:alt: wolfhall | ||
.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px | ||
:target: https://github.com/max3903 | ||
:alt: max3903 | ||
.. |maintainer-smangukiya| image:: https://github.com/smangukiya.png?size=40px | ||
:target: https://github.com/smangukiya | ||
:alt: smangukiya | ||
.. |maintainer-imlopes| image:: https://github.com/imlopes.png?size=40px | ||
:target: https://github.com/imlopes | ||
:alt: imlopes | ||
|
||
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-brian10048| |maintainer-wolfhall| |maintainer-max3903| |maintainer-smangukiya| |maintainer-imlopes| | ||
|
||
This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/17.0/fieldservice_equipment_stock_return>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). | ||
# @author: Italo Lopes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Field Service - Stock Equipment Return", | ||
"summary": "Integrate return orders for field service equipments", | ||
"version": "17.0.1.0.0", | ||
"category": "Field Service", | ||
"author": "Camptocamp, " "Italo LOPES, " "Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/field-service", | ||
"depends": [ | ||
"fieldservice_equipment_stock", | ||
], | ||
"data": [ | ||
"data/fsm_order_type.xml", | ||
"views/fsm_equipment.xml", | ||
"views/fsm_order_view.xml", | ||
"views/fsm_order_type_view.xml", | ||
], | ||
"license": "AGPL-3", | ||
"development_status": "Beta", | ||
"maintainers": [ | ||
"brian10048", | ||
"wolfhall", | ||
"max3903", | ||
"smangukiya", | ||
"imlopes", | ||
], | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
|
||
<record id="fsm_order_type_return" model="fsm.order.type"> | ||
<field name="name">Return</field> | ||
<field name="internal_type">return</field> | ||
</record> | ||
|
||
</odoo> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import ( | ||
fsm_equipment, | ||
fsm_order, | ||
fsm_order_type, | ||
) |
33 changes: 33 additions & 0 deletions
33
fieldservice_equipment_stock_return/models/fsm_equipment.py
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). | ||
# @author: Italo Lopes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class FSMEquipment(models.Model): | ||
_inherit = "fsm.equipment" | ||
|
||
def create_equipment_order_return(self): | ||
self.ensure_one() | ||
order_type = self.env.ref( | ||
"fieldservice_equipment_stock_return.fsm_order_type_return", | ||
raise_if_not_found=False, | ||
) | ||
if not order_type: | ||
order_type = self.env["fsm.order.type"].search( | ||
[("internal_type", "=", "return")], limit=1 | ||
) | ||
if not order_type: | ||
raise UserError(_("No return order type found.")) | ||
return { | ||
"name": "Return Equipment", | ||
"type": "ir.actions.act_window", | ||
"res_model": "fsm.order", | ||
"view_mode": "form", | ||
"context": { | ||
"default_equipment_id": self.id, | ||
"default_type": order_type and order_type.id or False, | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). | ||
# @author: Italo Lopes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class FSMOrder(models.Model): | ||
_inherit = "fsm.order" | ||
|
||
def _prepare_return_procurement_group_values(self): | ||
self.ensure_one() | ||
return { | ||
"name": self.display_name, | ||
"fsm_order_id": self.id, | ||
"move_type": "direct", | ||
} | ||
|
||
def _get_equipment_current_location(self): | ||
self.ensure_one() | ||
if not self.equipment_id: | ||
raise ValidationError(_("Cannot create return order without an equipment.")) | ||
if self.equipment_id.current_stock_location_id: | ||
return self.equipment_id.current_stock_location_id | ||
elif self.equipment_id.current_location_id: | ||
return ( | ||
self.equipment_id.current_location_id | ||
and self.equipment_id.current_location_id.inventory_location_id | ||
) | ||
else: | ||
raise ValidationError( | ||
_("Impossible to find the equipment current location.") | ||
) | ||
|
||
def _prepare_return_stock_picking_values(self): | ||
self.ensure_one() | ||
source_location_id = self._get_equipment_current_location() | ||
return { | ||
"picking_type_id": self.type.picking_type_id.id, | ||
"origin": self.display_name, | ||
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id, | ||
"location_id": source_location_id and source_location_id.id, | ||
"fsm_order_id": self.id, | ||
"group_id": self.procurement_group_id.id, | ||
} | ||
|
||
def _prepare_return_stock_move_values(self): | ||
self.ensure_one() | ||
source_location_id = self._get_equipment_current_location() | ||
return { | ||
"name": self.display_name, | ||
"product_id": self.equipment_id.product_id.id, | ||
"product_uom_qty": 1, | ||
"product_uom": self.equipment_id.product_id.uom_id.id, | ||
"location_id": source_location_id.id, | ||
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id, | ||
"group_id": self.procurement_group_id.id, | ||
"fsm_order_id": self.id, | ||
"lot_ids": [(4, self.equipment_id.lot_id.id)] | ||
if self.equipment_id.lot_id | ||
else False, | ||
} | ||
|
||
@api.model | ||
def create(self, vals): | ||
# if FSM order with type return is created then | ||
# create a picking order | ||
order = super().create(vals) | ||
if order.type.internal_type == "return": | ||
if order.equipment_id and order.type.picking_type_id: | ||
group = self.env["procurement.group"].search( | ||
[("fsm_order_id", "=", order.id)] | ||
) | ||
if not group: | ||
values = order._prepare_return_procurement_group_values() | ||
group = self.env["procurement.group"].create(values) | ||
order.procurement_group_id = group and group.id | ||
return_picking_values = order._prepare_return_stock_picking_values() | ||
new_picking = self.env["stock.picking"].create(return_picking_values) | ||
return_move_values = order._prepare_return_stock_move_values() | ||
return_move_values["picking_id"] = new_picking.id | ||
self.env["stock.move"].create(return_move_values) | ||
new_picking.action_confirm() | ||
|
||
elif not order.type.picking_type_id: | ||
raise ValidationError( | ||
_( | ||
"Cannot create a return order because " | ||
"order type does not have a current " | ||
"Picking Type." | ||
) | ||
) | ||
return order |
17 changes: 17 additions & 0 deletions
17
fieldservice_equipment_stock_return/models/fsm_order_type.py
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). | ||
# @author: Italo Lopes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class FsmOrderType(models.Model): | ||
_inherit = "fsm.order.type" | ||
|
||
internal_type = fields.Selection( | ||
selection_add=[("return", "Return")], | ||
) | ||
picking_type_id = fields.Many2one( | ||
"stock.picking.type", | ||
domain=[("code", "=", "incoming")], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Check `Field Service - Stock Equipment` module configuration. | ||
|
||
|
||
To configure this module, you need to: | ||
|
||
- Go to Field Service \> Configuration \> Order Types | ||
- Check if you have at least one `return` order type | ||
- Set the `Picking Type` linked to the `return` order type |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
- Italo LOPES \<<[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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The development of this module has been financially supported by: | ||
|
||
- Camptocamp SA \<<https://camptocamp.com>\> |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows you to return FSM equipments creating a new picking. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.