-
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][IMP] fieldservice_euipment_stock: add return order type
- Loading branch information
ilo
committed
Oct 21, 2024
1 parent
15a55b6
commit a991d94
Showing
10 changed files
with
168 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,78 @@ | ||
# 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() | ||
return self.equipment_id and self.equipment_id.location_id.inventory_location_id | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,10 @@ | |
|
||
/* | ||
:Author: David Goodger ([email protected]) | ||
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ | ||
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ | ||
:Copyright: This stylesheet has been placed in the public domain. | ||
|
||
Default cascading style sheet for the HTML output of Docutils. | ||
Despite the name, some widely supported CSS2 features are used. | ||
|
||
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to | ||
customize this style sheet. | ||
|
@@ -275,7 +274,7 @@ | |
margin-left: 2em ; | ||
margin-right: 2em } | ||
|
||
pre.code .ln { color: gray; } /* line numbers */ | ||
pre.code .ln { color: grey; } /* line numbers */ | ||
pre.code, code { background-color: #eeeeee } | ||
pre.code .comment, code .comment { color: #5C6576 } | ||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } | ||
|
@@ -301,7 +300,7 @@ | |
span.pre { | ||
white-space: pre } | ||
|
||
span.problematic, pre.problematic { | ||
span.problematic { | ||
color: red } | ||
|
||
span.section-subtitle { | ||
|
@@ -461,9 +460,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Other credits</a></h2> | |
<div class="section" id="maintainers"> | ||
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2> | ||
<p>This module is maintained by the OCA.</p> | ||
<a class="reference external image-reference" href="https://odoo-community.org"> | ||
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> | ||
</a> | ||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> | ||
<p>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.</p> | ||
|
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> |