Repository: OCA/stock-logistics-warehouse
Pull request #2283: [18.0][MIG] stock_helper: Migration to 18.0. (split feature to stock_route_location_source)
Author: login: mt-software-de
Labels: name: approved
name: ready to merge
name: merged 🎉
Created: 2025-03-07T12:43:17Z | Merged: 2025-03-24T08:00:01Z

To complete the Migration of `stock_helper` started with https://github.com/OCA/stock-logistics-warehouse/pull/2223
This PR split the method for getting the source location of a route into a own addon. 
The initial method `_get_source_location_from_route` was moved to `stock.route` and renamed to `_get_source_location`. 

cc @ThiagoMForgeFlow @jbaudoux @LoisRForgeFlow @JasminSForgeFlow


Diff:
diff --git a/stock_route_location_source/README.rst b/stock_route_location_source/README.rst
new file mode 100644
index 000000000000..8c677cba77b1
--- /dev/null
+++ b/stock_route_location_source/README.rst
@@ -0,0 +1,78 @@
+===========================
+Stock Route Location Source
+===========================
+
+.. 
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   !! This file is generated by oca-gen-addon-readme !!
+   !! changes will be overwritten.                   !!
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   !! source digest: sha256:a664ab61d30f26747d004db1f98084e755c1a3434a16ddc4898f5b31c91344d2
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
+    :target: https://odoo-community.org/page/development-status
+    :alt: Production/Stable
+.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
+    :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
+    :alt: License: LGPL-3
+.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
+    :target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_route_location_source
+    :alt: OCA/stock-logistics-warehouse
+.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
+    :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_route_location_source
+    :alt: Translate me on Weblate
+.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
+    :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=18.0
+    :alt: Try me on Runboat
+
+|badge1| |badge2| |badge3| |badge4| |badge5|
+
+Add methods to be used by other modules. This is not a functional
+module.
+
+**Table of contents**
+
+.. contents::
+   :local:
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us to smash it by providing a detailed and welcomed
+`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_route_location_source%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
+
+Do not contact contributors directly about support or help with technical issues.
+
+Credits
+=======
+
+Authors
+-------
+
+* MT Software
+
+Contributors
+------------
+
+- Guewen Baconnier <guewen.baconnier@camptocamp.com>
+- Christopher Ormaza <chris.ormaza@forgeflow.com>
+
+Maintainers
+-----------
+
+This module is maintained by the OCA.
+
+.. image:: https://odoo-community.org/logo.png
+   :alt: Odoo Community Association
+   :target: https://odoo-community.org
+
+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.
+
+This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_route_location_source>`_ project on GitHub.
+
+You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_route_location_source/__init__.py b/stock_route_location_source/__init__.py
new file mode 100644
index 000000000000..0650744f6bc6
--- /dev/null
+++ b/stock_route_location_source/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/stock_route_location_source/__manifest__.py b/stock_route_location_source/__manifest__.py
new file mode 100644
index 000000000000..fd7dc97c4349
--- /dev/null
+++ b/stock_route_location_source/__manifest__.py
@@ -0,0 +1,14 @@
+# Copyright 2025 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+{
+    "name": "Stock Route Location Source",
+    "summary": "Add method to get source location of Inventory Routes",
+    "version": "18.0.1.0.0",
+    "development_status": "Production/Stable",
+    "author": "MT Software, Odoo Community Association (OCA)",
+    "website": "https://github.com/OCA/stock-logistics-warehouse",
+    "category": "Hidden",
+    "depends": ["stock"],
+    "license": "LGPL-3",
+}
diff --git a/stock_route_location_source/models/__init__.py b/stock_route_location_source/models/__init__.py
new file mode 100644
index 000000000000..a0f9bedeea4e
--- /dev/null
+++ b/stock_route_location_source/models/__init__.py
@@ -0,0 +1 @@
+from . import stock_route
diff --git a/stock_route_location_source/models/stock_route.py b/stock_route_location_source/models/stock_route.py
new file mode 100644
index 000000000000..5da9976e8a35
--- /dev/null
+++ b/stock_route_location_source/models/stock_route.py
@@ -0,0 +1,27 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, dest_location):
+        self.ensure_one()
+        dest_location.ensure_one()
+        src_location = self.env["stock.location"]
+        while True:
+            values = {}
+            _dest_location = src_location or dest_location
+            if not src_location:
+                values["route_ids"] = self
+            rule = self.env["procurement.group"]._get_rule(
+                self.env["product.product"], _dest_location, values
+            )
+            if not rule or rule.action not in ["pull", "pull_push"]:
+                break
+            src_location = rule.location_src_id
+            if rule.procure_method == "make_to_stock":
+                break
+        return src_location
diff --git a/stock_route_location_source/pyproject.toml b/stock_route_location_source/pyproject.toml
new file mode 100644
index 000000000000..4231d0cccb3d
--- /dev/null
+++ b/stock_route_location_source/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["whool"]
+build-backend = "whool.buildapi"
diff --git a/stock_route_location_source/readme/CONTRIBUTORS.md b/stock_route_location_source/readme/CONTRIBUTORS.md
new file mode 100644
index 000000000000..446fd1d57697
--- /dev/null
+++ b/stock_route_location_source/readme/CONTRIBUTORS.md
@@ -0,0 +1 @@
+* Michael Tietz (MT Software) <mtietz@mt-software.de>
diff --git a/stock_route_location_source/readme/DESCRIPTION.md b/stock_route_location_source/readme/DESCRIPTION.md
new file mode 100644
index 000000000000..a7d44965232c
--- /dev/null
+++ b/stock_route_location_source/readme/DESCRIPTION.md
@@ -0,0 +1 @@
+Add method to get source location of Inventory Routes
diff --git a/stock_route_location_source/static/description/icon.png b/stock_route_location_source/static/description/icon.png
new file mode 100644
index 000000000000..3a0328b516c4
Binary files /dev/null and b/stock_route_location_source/static/description/icon.png differ
diff --git a/stock_route_location_source/static/description/index.html b/stock_route_location_source/static/description/index.html
new file mode 100644
index 000000000000..3cb99f94fee5
--- /dev/null
+++ b/stock_route_location_source/static/description/index.html
@@ -0,0 +1,422 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
+<title>Stock Route Location Source</title>
+<style type="text/css">
+
+/*
+:Author: David Goodger (goodger@python.org)
+:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
+:Copyright: This stylesheet has been placed in the public domain.
+
+Default cascading style sheet for the HTML output of Docutils.
+
+See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
+customize this style sheet.
+*/
+
+/* used to remove borders from tables and images */
+.borderless, table.borderless td, table.borderless th {
+  border: 0 }
+
+table.borderless td, table.borderless th {
+  /* Override padding for "table.docutils td" with "! important".
+     The right padding separates the table cells. */
+  padding: 0 0.5em 0 0 ! important }
+
+.first {
+  /* Override more specific margin styles with "! important". */
+  margin-top: 0 ! important }
+
+.last, .with-subtitle {
+  margin-bottom: 0 ! important }
+
+.hidden {
+  display: none }
+
+.subscript {
+  vertical-align: sub;
+  font-size: smaller }
+
+.superscript {
+  vertical-align: super;
+  font-size: smaller }
+
+a.toc-backref {
+  text-decoration: none ;
+  color: black }
+
+blockquote.epigraph {
+  margin: 2em 5em ; }
+
+dl.docutils dd {
+  margin-bottom: 0.5em }
+
+object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
+  overflow: hidden;
+}
+
+/* Uncomment (and remove this text!) to get bold-faced definition list terms
+dl.docutils dt {
+  font-weight: bold }
+*/
+
+div.abstract {
+  margin: 2em 5em }
+
+div.abstract p.topic-title {
+  font-weight: bold ;
+  text-align: center }
+
+div.admonition, div.attention, div.caution, div.danger, div.error,
+div.hint, div.important, div.note, div.tip, div.warning {
+  margin: 2em ;
+  border: medium outset ;
+  padding: 1em }
+
+div.admonition p.admonition-title, div.hint p.admonition-title,
+div.important p.admonition-title, div.note p.admonition-title,
+div.tip p.admonition-title {
+  font-weight: bold ;
+  font-family: sans-serif }
+
+div.attention p.admonition-title, div.caution p.admonition-title,
+div.danger p.admonition-title, div.error p.admonition-title,
+div.warning p.admonition-title, .code .error {
+  color: red ;
+  font-weight: bold ;
+  font-family: sans-serif }
+
+/* Uncomment (and remove this text!) to get reduced vertical space in
+   compound paragraphs.
+div.compound .compound-first, div.compound .compound-middle {
+  margin-bottom: 0.5em }
+
+div.compound .compound-last, div.compound .compound-middle {
+  margin-top: 0.5em }
+*/
+
+div.dedication {
+  margin: 2em 5em ;
+  text-align: center ;
+  font-style: italic }
+
+div.dedication p.topic-title {
+  font-weight: bold ;
+  font-style: normal }
+
+div.figure {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+div.footer, div.header {
+  clear: both;
+  font-size: smaller }
+
+div.line-block {
+  display: block ;
+  margin-top: 1em ;
+  margin-bottom: 1em }
+
+div.line-block div.line-block {
+  margin-top: 0 ;
+  margin-bottom: 0 ;
+  margin-left: 1.5em }
+
+div.sidebar {
+  margin: 0 0 0.5em 1em ;
+  border: medium outset ;
+  padding: 1em ;
+  background-color: #ffffee ;
+  width: 40% ;
+  float: right ;
+  clear: right }
+
+div.sidebar p.rubric {
+  font-family: sans-serif ;
+  font-size: medium }
+
+div.system-messages {
+  margin: 5em }
+
+div.system-messages h1 {
+  color: red }
+
+div.system-message {
+  border: medium outset ;
+  padding: 1em }
+
+div.system-message p.system-message-title {
+  color: red ;
+  font-weight: bold }
+
+div.topic {
+  margin: 2em }
+
+h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
+h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
+  margin-top: 0.4em }
+
+h1.title {
+  text-align: center }
+
+h2.subtitle {
+  text-align: center }
+
+hr.docutils {
+  width: 75% }
+
+img.align-left, .figure.align-left, object.align-left, table.align-left {
+  clear: left ;
+  float: left ;
+  margin-right: 1em }
+
+img.align-right, .figure.align-right, object.align-right, table.align-right {
+  clear: right ;
+  float: right ;
+  margin-left: 1em }
+
+img.align-center, .figure.align-center, object.align-center {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
+
+table.align-center {
+  margin-left: auto;
+  margin-right: auto;
+}
+
+.align-left {
+  text-align: left }
+
+.align-center {
+  clear: both ;
+  text-align: center }
+
+.align-right {
+  text-align: right }
+
+/* reset inner alignment in figures */
+div.align-right {
+  text-align: inherit }
+
+/* div.align-center * { */
+/*   text-align: left } */
+
+.align-top    {
+  vertical-align: top }
+
+.align-middle {
+  vertical-align: middle }
+
+.align-bottom {
+  vertical-align: bottom }
+
+ol.simple, ul.simple {
+  margin-bottom: 1em }
+
+ol.arabic {
+  list-style: decimal }
+
+ol.loweralpha {
+  list-style: lower-alpha }
+
+ol.upperalpha {
+  list-style: upper-alpha }
+
+ol.lowerroman {
+  list-style: lower-roman }
+
+ol.upperroman {
+  list-style: upper-roman }
+
+p.attribution {
+  text-align: right ;
+  margin-left: 50% }
+
+p.caption {
+  font-style: italic }
+
+p.credits {
+  font-style: italic ;
+  font-size: smaller }
+
+p.label {
+  white-space: nowrap }
+
+p.rubric {
+  font-weight: bold ;
+  font-size: larger ;
+  color: maroon ;
+  text-align: center }
+
+p.sidebar-title {
+  font-family: sans-serif ;
+  font-weight: bold ;
+  font-size: larger }
+
+p.sidebar-subtitle {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+p.topic-title {
+  font-weight: bold }
+
+pre.address {
+  margin-bottom: 0 ;
+  margin-top: 0 ;
+  font: inherit }
+
+pre.literal-block, pre.doctest-block, pre.math, pre.code {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+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 }
+pre.code .literal.string, code .literal.string { color: #0C5404 }
+pre.code .name.builtin, code .name.builtin { color: #352B84 }
+pre.code .deleted, code .deleted { background-color: #DEB0A1}
+pre.code .inserted, code .inserted { background-color: #A3D289}
+
+span.classifier {
+  font-family: sans-serif ;
+  font-style: oblique }
+
+span.classifier-delimiter {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+span.interpreted {
+  font-family: sans-serif }
+
+span.option {
+  white-space: nowrap }
+
+span.pre {
+  white-space: pre }
+
+span.problematic {
+  color: red }
+
+span.section-subtitle {
+  /* font-size relative to parent (h1..h6 element) */
+  font-size: 80% }
+
+table.citation {
+  border-left: solid 1px gray;
+  margin-left: 1px }
+
+table.docinfo {
+  margin: 2em 4em }
+
+table.docutils {
+  margin-top: 0.5em ;
+  margin-bottom: 0.5em }
+
+table.footnote {
+  border-left: solid 1px black;
+  margin-left: 1px }
+
+table.docutils td, table.docutils th,
+table.docinfo td, table.docinfo th {
+  padding-left: 0.5em ;
+  padding-right: 0.5em ;
+  vertical-align: top }
+
+table.docutils th.field-name, table.docinfo th.docinfo-name {
+  font-weight: bold ;
+  text-align: left ;
+  white-space: nowrap ;
+  padding-left: 0 }
+
+/* "booktabs" style (no vertical lines) */
+table.docutils.booktabs {
+  border: 0px;
+  border-top: 2px solid;
+  border-bottom: 2px solid;
+  border-collapse: collapse;
+}
+table.docutils.booktabs * {
+  border: 0px;
+}
+table.docutils.booktabs th {
+  border-bottom: thin solid;
+  text-align: left;
+}
+
+h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
+h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
+  font-size: 100% }
+
+ul.auto-toc {
+  list-style-type: none }
+
+</style>
+</head>
+<body>
+<div class="document" id="stock-route-location-source">
+<h1 class="title">Stock Route Location Source</h1>
+
+<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! This file is generated by oca-gen-addon-readme !!
+!! changes will be overwritten.                   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! source digest: sha256:a664ab61d30f26747d004db1f98084e755c1a3434a16ddc4898f5b31c91344d2
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
+<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_route_location_source"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_route_location_source"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
+<p>Add methods to be used by other modules. This is not a functional
+module.</p>
+<p><strong>Table of contents</strong></p>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
+<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
+<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
+<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
+<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="bug-tracker">
+<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
+<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us to smash it by providing a detailed and welcomed
+<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_route_location_source%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
+<p>Do not contact contributors directly about support or help with technical issues.</p>
+</div>
+<div class="section" id="credits">
+<h1><a class="toc-backref" href="#id2">Credits</a></h1>
+<div class="section" id="authors">
+<h2><a class="toc-backref" href="#id3">Authors</a></h2>
+<ul class="simple">
+<li>MT Software</li>
+</ul>
+</div>
+<div class="section" id="contributors">
+<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
+<ul class="simple">
+<li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li>
+<li>Christopher Ormaza &lt;<a class="reference external" href="mailto:chris.ormaza&#64;forgeflow.com">chris.ormaza&#64;forgeflow.com</a>&gt;</li>
+</ul>
+</div>
+<div class="section" id="maintainers">
+<h2><a class="toc-backref" href="#id5">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>
+<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>
+<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_route_location_source">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
+<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
+</div>
+</div>
+</div>
+</body>
+</html>
diff --git a/stock_route_location_source/tests/__init__.py b/stock_route_location_source/tests/__init__.py
new file mode 100644
index 000000000000..9ec942f46e4f
--- /dev/null
+++ b/stock_route_location_source/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_get_source_location
diff --git a/stock_route_location_source/tests/test_get_source_location.py b/stock_route_location_source/tests/test_get_source_location.py
new file mode 100644
index 000000000000..73e7f18f7205
--- /dev/null
+++ b/stock_route_location_source/tests/test_get_source_location.py
@@ -0,0 +1,92 @@
+# Copyright 2022 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+from odoo.tests import TransactionCase
+
+
+class TestStockRouteGetSourceLocation(TransactionCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.wh = cls.env.ref("stock.warehouse0")
+        cls.stock_loc = cls.wh.lot_stock_id
+        cls.view_loc = cls.stock_loc.location_id
+        cls.customer_loc = cls.env.ref("stock.stock_location_customers")
+        cls.location4, cls.operation_type4, cls.route4 = cls.create_type_route_and_rule(
+            "4", cls.customer_loc
+        )
+        cls.location3, cls.operation_type3, cls.route3 = cls.create_type_route_and_rule(
+            "3", cls.location4
+        )
+        cls.location2, cls.operation_type2, cls.route2 = cls.create_type_route_and_rule(
+            "2", cls.location3
+        )
+        cls.location1, cls.operation_type1, cls.route1 = cls.create_type_route_and_rule(
+            "1",
+            cls.location2,
+        )
+        _, cls.operation_type_pick, cls.route_pick = cls.create_type_route_and_rule(
+            "pick", cls.location1, "make_to_stock", location_src=cls.stock_loc
+        )
+
+    @classmethod
+    def create_type_route_and_rule(
+        cls, suffix, location_dest, procure_method="make_to_order", location_src=None
+    ):
+        location_src = location_src or cls.stock_loc.create(
+            {"name": f"location{suffix}", "location_id": cls.view_loc.id}
+        )
+        operation_type_name = f"operationtype{suffix}"
+        operation_type = cls.env["stock.picking.type"].create(
+            {
+                "name": operation_type_name,
+                "sequence_code": operation_type_name,
+                "code": "internal",
+                "default_location_src_id": location_src.id,
+                "default_location_dest_id": location_dest.id,
+            }
+        )
+        route_name = f"route{suffix}"
+        rule_name = f"{route_name} rule{suffix}"
+        route = cls.env["stock.route"].create(
+            {
+                "name": route_name,
+                "warehouse_ids": [(6, 0, cls.wh.ids)],
+                "rule_ids": [
+                    (
+                        0,
+                        0,
+                        {
+                            "name": rule_name,
+                            "location_src_id": location_src.id,
+                            "location_dest_id": location_dest.id,
+                            "picking_type_id": operation_type.id,
+                            "procure_method": procure_method,
+                        },
+                    )
+                ],
+            }
+        )
+        return location_src, operation_type, route
+
+    def test_get_source_location(self):
+        source_location = self.route4._get_source_location(self.location4)
+        self.assertEqual(source_location, self.stock_loc)
+
+        source_location = self.route3._get_source_location(self.location3)
+        self.assertEqual(source_location, self.stock_loc)
+
+        source_location = self.route2._get_source_location(self.location2)
+        self.assertEqual(source_location, self.stock_loc)
+
+        source_location = self.route1._get_source_location(self.location1)
+        self.assertEqual(source_location, self.stock_loc)
+
+        # Location is not in route but a valid route is found
+        # and will return stock location
+        source_location = self.route1._get_source_location(self.location4)
+        self.assertEqual(source_location, self.stock_loc)
+
+        # Changing the procure_method on rule2
+        self.route2.rule_ids.procure_method = "make_to_stock"
+        source_location = self.route4._get_source_location(self.location4)
+        self.assertEqual(source_location, self.location2)


Reviews:
user: login: LoisRForgeFlow
body: Thanks! looks like the tests are failing, could you check?
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T12:57:31Z
user: login: jbaudoux
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T21:38:46Z
user: login: mt-software-de
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T21:51:58Z
user: login: mt-software-de
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T10:46:35Z
user: login: mt-software-de
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T11:02:29Z
user: login: mt-software-de
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T11:18:46Z
user: login: mt-software-de
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T07:57:09Z
user: login: jbaudoux
body: LG. Just write a nice commit msg :)
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T08:56:21Z
user: login: LoisRForgeFlow
body: Good enough :+1: 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T07:54:03Z

Review comments:
diff_hunk: @@ -0,0 +1,25 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, location, procure_method):
path: stock_route_location_source/models/stock_route.py
user: login: jbaudoux
body: What about having this as a computed field?
created_at: 2025-03-07T21:38:40Z
author_association: CONTRIBUTOR
path: stock_route_location_source/i18n/hr.po
user: login: mt-software-de
body: Needs to be removed
created_at: 2025-03-07T21:49:37Z
author_association: CONTRIBUTOR
path: stock_route_location_source/readme/CONTRIBUTORS.md
user: login: mt-software-de
body: Needs to be changed. 
created_at: 2025-03-07T21:50:26Z
author_association: CONTRIBUTOR
path: stock_route_location_source/readme/DESCRIPTION.md
user: login: mt-software-de
body: Needs to be updated
created_at: 2025-03-07T21:51:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,25 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, location, procure_method):
path: stock_route_location_source/models/stock_route.py
user: login: mt-software-de
body: At the moment it is just used here. And here it is just quite specific. 
https://github.com/OCA/stock-logistics-orderpoint/blob/31cfed56eebf1cef7422f2adda4b40b876832554/stock_location_orderpoint/models/stock_location_orderpoint.py#L128

But it is not possible to implement it as computed method, because you need a least a location as argument otherwise you cannot find a src location. 

But after thinking about your question, i don't know it this method is needed at all. 
Because it is only once used and very specific. And for `stock_location_orderpoint` it also easier to figure out what the src location is. 
For example in `stock_location_orderpoint` we could just filter the rules of the route.  
`location_src = orderpoint.route_id.rule_ids.filtered(lambda rule: rule.location_id == orderpoint.location_id and rule.procure_method == 'make_to_stock').location_src_id`
created_at: 2025-03-08T10:46:34Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,25 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, location, procure_method):
path: stock_route_location_source/models/stock_route.py
user: login: mt-software-de
body: Also this is not correct that it can be simplified. Because the main issue is here that i'm just talking from a very easy route rule configuration. So something a need is created in Stock take it from stock2. 
But if it it would be a more complex configuration this is not working it all. 
If it is a more complex route we need to set from the last make_to_stock rule the location src.
This also would mean that we need to remove the route from the call. 
created_at: 2025-03-08T11:02:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,25 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, location, procure_method):
path: stock_route_location_source/models/stock_route.py
user: login: mt-software-de
body: I will update this feature and propose a change. 
created_at: 2025-03-08T11:18:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,25 @@
+# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+
+from odoo import models
+
+
+class StockRoute(models.Model):
+    _inherit = "stock.route"
+
+    def _get_source_location(self, location, procure_method):
path: stock_route_location_source/models/stock_route.py
user: login: mt-software-de
body: Could you please check the last commit. 
created_at: 2025-03-13T07:57:08Z
author_association: CONTRIBUTOR

PR comments:
user: login: LoisRForgeFlow
created_at: 2025-03-24T07:54:16Z
body: /ocabot merge nobump
author_association: CONTRIBUTOR
user: login: OCA-git-bot
created_at: 2025-03-24T07:54:26Z
body: What a great day to merge this nice PR. Let's do it!
Prepared branch [18.0-ocabot-merge-pr-2283-by-LoisRForgeFlow-bump-nobump](https://github.com/OCA/stock-logistics-warehouse/commits/18.0-ocabot-merge-pr-2283-by-LoisRForgeFlow-bump-nobump), awaiting test results.
author_association: CONTRIBUTOR
user: login: OCA-git-bot
created_at: 2025-03-24T08:00:02Z
body: This PR has the `approved` label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖
author_association: CONTRIBUTOR
user: login: OCA-git-bot
created_at: 2025-03-24T08:00:02Z
body: Congratulations, your PR was merged at 348d847c37cf4476f57a057298e15d0c0246f1cb. Thanks a lot for contributing to OCA. ❤️
author_association: CONTRIBUTOR