Skip to content

Commit 755ae2b

Browse files
author
ilo
committed
[17.0][ADD] fieldservice_equipment_stock_return: add return order type
1 parent 0f9586a commit 755ae2b

21 files changed

+924
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
======================================
2+
Field Service - Stock Equipment Return
3+
======================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:ccef108ff488fd2820ce9403b90512a866de4e4edaa606f7f03418b70520b741
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github
20+
:target: https://github.com/OCA/field-service/tree/17.0/fieldservice_equipment_stock_return
21+
:alt: OCA/field-service
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/field-service-17-0/field-service-17-0-fieldservice_equipment_stock_return
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows you to return FSM equipments creating a new picking.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Configuration
39+
=============
40+
41+
Check ``Field Service - Stock Equipment`` module configuration.
42+
43+
To configure this module, you need to:
44+
45+
- Go to Field Service > Configuration > Order Types
46+
- Check if you have at least one ``return`` order type
47+
- Set the ``Picking Type`` linked to the ``return`` order type
48+
49+
Bug Tracker
50+
===========
51+
52+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/issues>`_.
53+
In case of trouble, please check there if your issue has already been reported.
54+
If you spotted it first, help us to smash it by providing a detailed and welcomed
55+
`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**>`_.
56+
57+
Do not contact contributors directly about support or help with technical issues.
58+
59+
Credits
60+
=======
61+
62+
Authors
63+
-------
64+
65+
* Camptocamp
66+
* Italo LOPES
67+
68+
Contributors
69+
------------
70+
71+
- Italo LOPES <italo.lopes@camptocamp.com>
72+
73+
Other credits
74+
-------------
75+
76+
The development of this module has been financially supported by:
77+
78+
- Camptocamp SA <https://camptocamp.com>
79+
80+
Maintainers
81+
-----------
82+
83+
This module is maintained by the OCA.
84+
85+
.. image:: https://odoo-community.org/logo.png
86+
:alt: Odoo Community Association
87+
:target: https://odoo-community.org
88+
89+
OCA, or the Odoo Community Association, is a nonprofit organization whose
90+
mission is to support the collaborative development of Odoo features and
91+
promote its widespread use.
92+
93+
.. |maintainer-brian10048| image:: https://github.com/brian10048.png?size=40px
94+
:target: https://github.com/brian10048
95+
:alt: brian10048
96+
.. |maintainer-wolfhall| image:: https://github.com/wolfhall.png?size=40px
97+
:target: https://github.com/wolfhall
98+
:alt: wolfhall
99+
.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px
100+
:target: https://github.com/max3903
101+
:alt: max3903
102+
.. |maintainer-smangukiya| image:: https://github.com/smangukiya.png?size=40px
103+
:target: https://github.com/smangukiya
104+
:alt: smangukiya
105+
.. |maintainer-imlopes| image:: https://github.com/imlopes.png?size=40px
106+
:target: https://github.com/imlopes
107+
:alt: imlopes
108+
109+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
110+
111+
|maintainer-brian10048| |maintainer-wolfhall| |maintainer-max3903| |maintainer-smangukiya| |maintainer-imlopes|
112+
113+
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.
114+
115+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

fieldservice_equipment_stock_return/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# @author: Italo Lopes <italo.lopes@camptocamp.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Field Service - Stock Equipment Return",
7+
"summary": "Integrate return orders for field service equipments",
8+
"version": "17.0.1.0.0",
9+
"category": "Field Service",
10+
"author": "Camptocamp, " "Italo LOPES, " "Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/field-service",
12+
"depends": [
13+
"fieldservice_equipment_stock",
14+
],
15+
"data": [
16+
"data/fsm_order_type.xml",
17+
"views/fsm_equipment.xml",
18+
"views/fsm_order_view.xml",
19+
"views/fsm_order_type_view.xml",
20+
],
21+
"license": "AGPL-3",
22+
"development_status": "Beta",
23+
"maintainers": [
24+
"brian10048",
25+
"wolfhall",
26+
"max3903",
27+
"smangukiya",
28+
"imlopes",
29+
],
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
4+
<record id="fsm_order_type_return" model="fsm.order.type">
5+
<field name="name">Return</field>
6+
<field name="internal_type">return</field>
7+
</record>
8+
9+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import (
2+
fsm_equipment,
3+
fsm_order,
4+
fsm_order_type,
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# @author: Italo Lopes <italo.lopes@camptocamp.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from odoo import _, models
6+
from odoo.exceptions import UserError
7+
8+
9+
class FSMEquipment(models.Model):
10+
_inherit = "fsm.equipment"
11+
12+
def create_equipment_order_return(self):
13+
self.ensure_one()
14+
order_type = self.env.ref(
15+
"fieldservice_equipment_stock_return.fsm_order_type_return",
16+
raise_if_not_found=False,
17+
)
18+
if not order_type:
19+
order_type = self.env["fsm.order.type"].search(
20+
[("internal_type", "=", "return")], limit=1
21+
)
22+
if not order_type:
23+
raise UserError(_("No return order type found."))
24+
return {
25+
"name": "Return Equipment",
26+
"type": "ir.actions.act_window",
27+
"res_model": "fsm.order",
28+
"view_mode": "form",
29+
"context": {
30+
"default_equipment_id": self.id,
31+
"default_type": order_type and order_type.id or False,
32+
},
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# @author: Italo Lopes <italo.lopes@camptocamp.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from odoo import _, api, models
6+
from odoo.exceptions import ValidationError
7+
8+
9+
class FSMOrder(models.Model):
10+
_inherit = "fsm.order"
11+
12+
def _prepare_return_procurement_group_values(self):
13+
self.ensure_one()
14+
return {
15+
"name": self.display_name,
16+
"fsm_order_id": self.id,
17+
"move_type": "direct",
18+
}
19+
20+
def _get_equipment_current_location(self):
21+
self.ensure_one()
22+
if not self.equipment_id:
23+
raise ValidationError(_("Cannot create return order without an equipment."))
24+
if self.equipment_id.current_stock_location_id:
25+
return self.equipment_id.current_stock_location_id
26+
elif self.equipment_id.current_location_id:
27+
return (
28+
self.equipment_id.current_location_id
29+
and self.equipment_id.current_location_id.inventory_location_id
30+
)
31+
else:
32+
raise ValidationError(
33+
_("Impossible to find the equipment current location.")
34+
)
35+
36+
def _prepare_return_stock_picking_values(self):
37+
self.ensure_one()
38+
source_location_id = self._get_equipment_current_location()
39+
return {
40+
"picking_type_id": self.type.picking_type_id.id,
41+
"origin": self.display_name,
42+
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id,
43+
"location_id": source_location_id and source_location_id.id,
44+
"fsm_order_id": self.id,
45+
"group_id": self.procurement_group_id.id,
46+
}
47+
48+
def _prepare_return_stock_move_values(self):
49+
self.ensure_one()
50+
source_location_id = self._get_equipment_current_location()
51+
return {
52+
"name": self.display_name,
53+
"product_id": self.equipment_id.product_id.id,
54+
"product_uom_qty": 1,
55+
"product_uom": self.equipment_id.product_id.uom_id.id,
56+
"location_id": source_location_id.id,
57+
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id,
58+
"group_id": self.procurement_group_id.id,
59+
"fsm_order_id": self.id,
60+
"lot_ids": [(4, self.equipment_id.lot_id.id)]
61+
if self.equipment_id.lot_id
62+
else False,
63+
}
64+
65+
@api.model
66+
def create(self, vals):
67+
# if FSM order with type return is created then
68+
# create a picking order
69+
order = super().create(vals)
70+
if order.type.internal_type == "return":
71+
if order.equipment_id and order.type.picking_type_id:
72+
group = self.env["procurement.group"].search(
73+
[("fsm_order_id", "=", order.id)]
74+
)
75+
if not group:
76+
values = order._prepare_return_procurement_group_values()
77+
group = self.env["procurement.group"].create(values)
78+
order.procurement_group_id = group and group.id
79+
return_picking_values = order._prepare_return_stock_picking_values()
80+
new_picking = self.env["stock.picking"].create(return_picking_values)
81+
return_move_values = order._prepare_return_stock_move_values()
82+
return_move_values["picking_id"] = new_picking.id
83+
self.env["stock.move"].create(return_move_values)
84+
new_picking.action_confirm()
85+
86+
elif not order.type.picking_type_id:
87+
raise ValidationError(
88+
_(
89+
"Cannot create a return order because "
90+
"order type does not have a current "
91+
"Picking Type."
92+
)
93+
)
94+
return order
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# @author: Italo Lopes <italo.lopes@camptocamp.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from odoo import fields, models
6+
7+
8+
class FsmOrderType(models.Model):
9+
_inherit = "fsm.order.type"
10+
11+
internal_type = fields.Selection(
12+
selection_add=[("return", "Return")],
13+
)
14+
picking_type_id = fields.Many2one(
15+
"stock.picking.type",
16+
domain=[("code", "=", "incoming")],
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Check `Field Service - Stock Equipment` module configuration.
2+
3+
4+
To configure this module, you need to:
5+
6+
- Go to Field Service \> Configuration \> Order Types
7+
- Check if you have at least one `return` order type
8+
- Set the `Picking Type` linked to the `return` order type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Italo LOPES \<<italo.lopes@camptocamp.com>\>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The development of this module has been financially supported by:
2+
3+
- Camptocamp SA \<<https://camptocamp.com>\>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module allows you to return FSM equipments creating a new picking.

fieldservice_equipment_stock_return/static/description/icon.png

Loading

0 commit comments

Comments
 (0)