-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility between dynamic routing and source relocate
- Loading branch information
Showing
16 changed files
with
255 additions
and
38 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ve_source_relocate_dynamic_routing/odoo/addons/stock_move_source_relocate_dynamic_routing
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 @@ | ||
../../../../stock_move_source_relocate_dynamic_routing |
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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
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
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 @@ | ||
from . import models |
16 changes: 16 additions & 0 deletions
16
stock_move_source_relocate_dynamic_routing/__manifest__.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,16 @@ | ||
# Copyright 2019 Camptocamp (https://www.camptocamp.com) | ||
{ | ||
"name": "Stock Source Relocate - Dynamic Routing", | ||
"summary": "Glue module", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/stock-logistics-warehouse", | ||
"category": "Warehouse Management", | ||
"version": "13.0.1.0.0", | ||
"license": "AGPL-3", | ||
"depends": ["stock_dynamic_routing", "stock_move_source_relocate"], | ||
"demo": [], | ||
"data": ["views/stock_routing_views.xml", "views/stock_source_relocate_views.xml"], | ||
"auto_install": True, | ||
"installable": True, | ||
"development_status": "Alpha", | ||
} |
3 changes: 3 additions & 0 deletions
3
stock_move_source_relocate_dynamic_routing/models/__init__.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,3 @@ | ||
from . import stock_move | ||
from . import stock_source_relocate | ||
from . import stock_routing |
21 changes: 21 additions & 0 deletions
21
stock_move_source_relocate_dynamic_routing/models/stock_move.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,21 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
def _apply_source_relocate_rule(self, relocation, reserved_availability, roundings): | ||
relocated = super( | ||
StockMove, | ||
# disable application of routing in write() method of | ||
# stock_dynamic_routing, we'll apply it here whatever the state of | ||
# the move is | ||
self.with_context(__applying_routing_rule=True), | ||
)._apply_source_relocate_rule(relocation, reserved_availability, roundings) | ||
# restore the previous context without "__applying_routing_rule", otherwise | ||
# it wouldn't properly apply the routing in chain in the further moves | ||
relocated.with_context(self.env.context)._chain_apply_routing() | ||
return relocated |
28 changes: 28 additions & 0 deletions
28
stock_move_source_relocate_dynamic_routing/models/stock_routing.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,28 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models | ||
|
||
|
||
class StockRouting(models.Model): | ||
|
||
_inherit = "stock.routing" | ||
|
||
def action_view_source_relocate(self): | ||
picking_types = self.mapped("picking_type_id") | ||
routing = self.env["stock.routing"].search( | ||
[("picking_type_id", "in", picking_types.ids)] | ||
) | ||
context = self.env.context | ||
if len(picking_types) == 1: | ||
context = dict(context, default_picking_type_id=picking_types.id) | ||
return { | ||
"name": _("Source Relocation"), | ||
"domain": [("id", "in", routing.ids)], | ||
"res_model": "stock.source.relocate", | ||
"type": "ir.actions.act_window", | ||
"view_id": False, | ||
"view_mode": "tree,form", | ||
"limit": 20, | ||
"context": context, | ||
} |
28 changes: 28 additions & 0 deletions
28
stock_move_source_relocate_dynamic_routing/models/stock_source_relocate.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,28 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models | ||
|
||
|
||
class StockSourceRelocate(models.Model): | ||
|
||
_inherit = "stock.source.relocate" | ||
|
||
def action_view_dynamic_routing(self): | ||
picking_types = self.mapped("picking_type_id") | ||
routing = self.env["stock.routing"].search( | ||
[("picking_type_id", "in", picking_types.ids)] | ||
) | ||
context = self.env.context | ||
if len(picking_types) == 1: | ||
context = dict(context, default_picking_type_id=picking_types.id) | ||
return { | ||
"name": _("Dynamic Routing"), | ||
"domain": [("id", "in", routing.ids)], | ||
"res_model": "stock.routing", | ||
"type": "ir.actions.act_window", | ||
"view_id": False, | ||
"view_mode": "tree,form", | ||
"limit": 20, | ||
"context": context, | ||
} |
1 change: 1 addition & 0 deletions
1
stock_move_source_relocate_dynamic_routing/readme/CONTRIBUTORS.rst
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 @@ | ||
* Guewen Baconnier <guewen.baconnier@camptocamp.com> |
2 changes: 2 additions & 0 deletions
2
stock_move_source_relocate_dynamic_routing/readme/DESCRIPTION.rst
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,2 @@ | ||
Glue module between ``stock_move_source_relocate`` and | ||
``stock_dynamic_routing``. |
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 @@ | ||
from . import test_dynamic_relocate |
57 changes: 57 additions & 0 deletions
57
stock_move_source_relocate_dynamic_routing/tests/test_dynamic_relocate.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,57 @@ | ||
from odoo.addons.stock_move_source_relocate.tests.test_source_relocate import ( | ||
SourceRelocateCommon, | ||
) | ||
|
||
|
||
class TestSourceRelocate(SourceRelocateCommon): | ||
def test_relocate_with_routing(self): | ||
"""Check that routing is applied when a relocation happen""" | ||
# Relocation: for unavailable move in Stock, relocate to Replenish | ||
self._create_relocate_rule( | ||
self.wh.lot_stock_id, self.loc_replenish, self.wh.pick_type_id | ||
) | ||
# Routing: a move with source location in replenishment is classified | ||
# in picking type Replenish | ||
pick_type_replenish = self.env["stock.picking.type"].create( | ||
{ | ||
"name": "Replenish", | ||
"code": "internal", | ||
"sequence_code": "R", | ||
"warehouse_id": self.wh.id, | ||
"use_create_lots": False, | ||
"use_existing_lots": True, | ||
"default_location_src_id": self.loc_replenish.id, | ||
"default_location_dest_id": self.wh.lot_stock_id.id, | ||
} | ||
) | ||
self.env["stock.routing"].create( | ||
{ | ||
"location_id": self.loc_replenish.id, | ||
"picking_type_id": self.wh.pick_type_id.id, | ||
"rule_ids": [ | ||
( | ||
0, | ||
0, | ||
{"method": "pull", "picking_type_id": pick_type_replenish.id}, | ||
) | ||
], | ||
} | ||
) | ||
move = self._create_single_move(self.product, self.wh.pick_type_id) | ||
move._assign_picking() | ||
move._action_assign() | ||
self.assertRecordValues( | ||
move, | ||
[ | ||
{ | ||
"state": "confirmed", | ||
"product_qty": 10.0, | ||
"reserved_availability": 0.0, | ||
# routing changed the picking type | ||
"picking_type_id": pick_type_replenish.id, | ||
"location_id": self.loc_replenish.id, | ||
} | ||
], | ||
) | ||
# routing created a new move | ||
self.assertTrue(move.move_dest_ids) |
19 changes: 19 additions & 0 deletions
19
stock_move_source_relocate_dynamic_routing/views/stock_routing_views.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,19 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="view_stock_routing_form" model="ir.ui.view"> | ||
<field name="name">stock.routing.form</field> | ||
<field name="model">stock.routing</field> | ||
<field name="inherit_id" ref="stock_dynamic_routing.view_stock_routing_form" /> | ||
<field name="arch" type="xml"> | ||
<div name="button_box" position="inside"> | ||
<button | ||
name="action_view_source_relocate" | ||
string="Source Relocation" | ||
icon="fa-refresh" | ||
class="oe_stat_button" | ||
type="object" | ||
/> | ||
</div> | ||
</field> | ||
</record> | ||
</odoo> |
22 changes: 22 additions & 0 deletions
22
stock_move_source_relocate_dynamic_routing/views/stock_source_relocate_views.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,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="view_stock_source_relocate_form" model="ir.ui.view"> | ||
<field name="name">stock.source.relocate.form</field> | ||
<field name="model">stock.source.relocate</field> | ||
<field | ||
name="inherit_id" | ||
ref="stock_move_source_relocate.view_stock_source_relocate_form" | ||
/> | ||
<field name="arch" type="xml"> | ||
<div name="button_box" position="inside"> | ||
<button | ||
name="action_view_dynamic_routing" | ||
string="Dynamic Routing" | ||
icon="fa-refresh" | ||
class="oe_stat_button" | ||
type="object" | ||
/> | ||
</div> | ||
</field> | ||
</record> | ||
</odoo> |