Skip to content

Commit b17b846

Browse files
author
ilo
committed
[17.0][IMP] fieldservice_euipment_stock: add return order type
1 parent 15a55b6 commit b17b846

File tree

10 files changed

+168
-7
lines changed

10 files changed

+168
-7
lines changed

fieldservice_equipment_stock/__manifest__.py

+3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
],
1616
"data": [
1717
"security/ir.model.access.csv",
18+
"data/fsm_order_type.xml",
1819
"views/fsm_equipment.xml",
20+
"views/fsm_order_view.xml",
21+
"views/fsm_order_type_view.xml",
1922
"views/product_template.xml",
2023
"views/stock_picking_type.xml",
2124
"views/stock_lot.xml",
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>

fieldservice_equipment_stock/models/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
stock_move,
33
stock_picking_type,
44
fsm_equipment,
5+
fsm_order,
6+
fsm_order_type,
57
product_template,
68
stock_lot,
79
)

fieldservice_equipment_stock/models/fsm_equipment.py

+14
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,17 @@ def write(self, vals):
4444
if "lot_id" in vals:
4545
equipment.lot_id.fsm_equipment_id = equipment.id
4646
return res
47+
48+
def create_equip_order_return(self):
49+
self.ensure_one()
50+
order_type = self.env.ref("fieldservice_equipment_stock.fsm_order_type_return")
51+
return {
52+
"name": "Return Equipment",
53+
"type": "ir.actions.act_window",
54+
"res_model": "fsm.order",
55+
"view_mode": "form",
56+
"context": {
57+
"default_equipment_id": self.id,
58+
"default_type": order_type and order_type.id or False,
59+
},
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2024 Camptocamp
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class FSMOrder(models.Model):
9+
_inherit = "fsm.order"
10+
11+
def _prepare_return_procurement_group_values(self):
12+
return {
13+
"name": self.display_name,
14+
"fsm_order_id": self.id,
15+
"move_type": "direct",
16+
}
17+
18+
def _prepare_return_stock_picking_values(self):
19+
source_location_id = self._get_equipment_current_location()
20+
return {
21+
"picking_type_id": self.type.picking_type_id.id,
22+
"origin": self.display_name,
23+
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id,
24+
"location_id": source_location_id and source_location_id.id,
25+
"fsm_order_id": self.id,
26+
"group_id": self.procurement_group_id.id,
27+
}
28+
29+
def _prepare_return_stock_move_values(self):
30+
source_location_id = self._get_equipment_current_location()
31+
return {
32+
"name": self.display_name,
33+
"product_id": self.equipment_id.product_id.id,
34+
"product_uom_qty": 1,
35+
"product_uom": self.equipment_id.product_id.uom_id.id,
36+
"location_id": source_location_id.id,
37+
"location_dest_id": self.type.picking_type_id.default_location_dest_id.id,
38+
"group_id": self.procurement_group_id.id,
39+
"fsm_order_id": self.id,
40+
"lot_ids": [(4, self.equipment_id.lot_id.id)]
41+
if self.equipment_id.lot_id
42+
else False,
43+
}
44+
45+
def _get_equipment_current_location(self):
46+
self.ensure_one()
47+
return self.equipment_id and self.equipment_id.location_id.inventory_location_id
48+
49+
@api.model
50+
def create(self, vals):
51+
# if FSM order with type return is created then
52+
# create a picking order
53+
order = super().create(vals)
54+
if order.type.internal_type == "return":
55+
if order.equipment_id and order.type.picking_type_id:
56+
group = self.env["procurement.group"].search(
57+
[("fsm_order_id", "=", order.id)]
58+
)
59+
if not group:
60+
values = order._prepare_return_procurement_group_values()
61+
group = self.env["procurement.group"].create(values)
62+
order.procurement_group_id = group and group.id
63+
return_picking_values = order._prepare_return_stock_picking_values()
64+
new_picking = self.env["stock.picking"].create(return_picking_values)
65+
return_move_values = order._prepare_return_stock_move_values()
66+
return_move_values["picking_id"] = new_picking.id
67+
self.env["stock.move"].create(return_move_values)
68+
new_picking.action_confirm()
69+
70+
elif not order.type.pick_type_id:
71+
raise ValidationError(
72+
_(
73+
"Cannot create Return Order because "
74+
"order type does not have a current "
75+
"Picking Type."
76+
)
77+
)
78+
return order
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2024 Camptocamp
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class FsmOrderType(models.Model):
8+
_inherit = "fsm.order.type"
9+
10+
internal_type = fields.Selection(
11+
selection_add=[("return", "Return")],
12+
)
13+
picking_type_id = fields.Many2one(
14+
"stock.picking.type",
15+
domain=[("code", "=", "incoming")],
16+
)

fieldservice_equipment_stock/static/description/index.html

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -461,9 +460,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Other credits</a></h2>
461460
<div class="section" id="maintainers">
462461
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
463462
<p>This module is maintained by the OCA.</p>
464-
<a class="reference external image-reference" href="https://odoo-community.org">
465-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
466-
</a>
463+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
467464
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
468465
mission is to support the collaborative development of Odoo features and
469466
promote its widespread use.</p>

fieldservice_equipment_stock/views/fsm_equipment.xml

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
<field name="model">fsm.equipment</field>
66
<field name="inherit_id" ref="fieldservice.fsm_equipment_form_view" />
77
<field name="arch" type="xml">
8+
<button id="previous_stage" position="before">
9+
<button
10+
id="new_equip_return"
11+
name="create_equip_order_return"
12+
string="Create Return"
13+
class="oe_highlight"
14+
type="object"
15+
/>
16+
</button>
817
<group id="secondary" position="inside">
918
<group string="Inventory" groups="stock.group_stock_user">
1019
<field name="product_id" required="1" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
4+
<!-- Fields Service Orders Form View -->
5+
<record id="fsm_order_type_form_view" model="ir.ui.view">
6+
<field name="model">fsm.order.type</field>
7+
<field name="inherit_id" ref="fieldservice.fsm_order_type_form_view" />
8+
<field name="arch" type="xml">
9+
<field name="internal_type" position="after">
10+
<field name="picking_type_id" invisible="internal_type != 'return'" />
11+
</field>
12+
</field>
13+
</record>
14+
15+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
4+
<!-- Fields Service Orders Form View -->
5+
<record id="fsm_order_maintenance_form" model="ir.ui.view">
6+
<field name="model">fsm.order</field>
7+
<field name="inherit_id" ref="fieldservice.fsm_order_form" />
8+
<field name="arch" type="xml">
9+
<field name="equipment_id" position="attributes">
10+
<attribute
11+
name="invisible"
12+
>internal_type not in ['repair', 'maintenance', 'return']</attribute>
13+
<attribute name="required">internal_type in ['return']</attribute>
14+
</field>
15+
</field>
16+
</record>
17+
18+
</odoo>

0 commit comments

Comments
 (0)