-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[17.0][IMP] fieldservice_euipment_stock: add return order type
- Loading branch information
ilo
committed
Oct 21, 2024
1 parent
15a55b6
commit f63eb8c
Showing
10 changed files
with
191 additions
and
7 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
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
stock_move, | ||
stock_picking_type, | ||
fsm_equipment, | ||
fsm_order, | ||
fsm_order_type, | ||
product_template, | ||
stock_lot, | ||
) |
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
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,101 @@ | ||
# Copyright 2024 Camptocamp | ||
# 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): | ||
return { | ||
"name": self.display_name, | ||
"fsm_order_id": self.id, | ||
"move_type": "direct", | ||
} | ||
|
||
def _prepare_return_stock_picking_values(self): | ||
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): | ||
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, | ||
} | ||
|
||
def _get_equipment_current_location(self): | ||
self.ensure_one() | ||
if not self.equipment_id: | ||
raise ValidationError( | ||
_( | ||
"Cannot create Return Order because " | ||
"order does not have a current equipment." | ||
) | ||
) | ||
if self.equipment_id.location_id: | ||
return ( | ||
self.equipment_id.location_id | ||
and self.equipment_id.location_id.inventory_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( | ||
_( | ||
"Cannot create Return Order because " | ||
"equipment does not have a current location." | ||
) | ||
) | ||
|
||
@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 Return Order because " | ||
"order type does not have a current " | ||
"Picking Type." | ||
) | ||
) | ||
return order |
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,16 @@ | ||
# Copyright 2024 Camptocamp | ||
# 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
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
15 changes: 15 additions & 0 deletions
15
fieldservice_equipment_stock/views/fsm_order_type_view.xml
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<!-- Fields Service Orders Form View --> | ||
<record id="fsm_order_type_form_view" model="ir.ui.view"> | ||
<field name="model">fsm.order.type</field> | ||
<field name="inherit_id" ref="fieldservice.fsm_order_type_form_view" /> | ||
<field name="arch" type="xml"> | ||
<field name="internal_type" position="after"> | ||
<field name="picking_type_id" invisible="internal_type != 'return'" /> | ||
</field> | ||
</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,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<!-- Fields Service Orders Form View --> | ||
<record id="fsm_order_maintenance_form" model="ir.ui.view"> | ||
<field name="model">fsm.order</field> | ||
<field name="inherit_id" ref="fieldservice.fsm_order_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="equipment_id" position="attributes"> | ||
<attribute | ||
name="invisible" | ||
>internal_type not in ['repair', 'maintenance', 'return']</attribute> | ||
<attribute name="required">internal_type in ['return']</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |