[IMP] stock_helper: add location._get_source_location_from_route

returns the next source location of a location by the given route and procure_method
This commit is contained in:
Michael Tietz
2023-04-17 14:17:37 +02:00
parent 97689e6372
commit 1c85d1564e
3 changed files with 59 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
# Copyright 2020-2021 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2022 Michael Tietz (MT Software) <mtietz@mt-software.de>
# Copyright 2022-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
@@ -42,3 +42,20 @@ class StockLocation(models.Model):
if self.parent_path.startswith(warehouse.view_location_id.parent_path):
return warehouse
return warehouses.browse()
def _get_source_location_from_route(self, route, procure_method):
self.ensure_one()
route.ensure_one()
values = {
"route_ids": route,
}
current_location = self
while current_location:
rule = self.env["procurement.group"]._get_rule(
self.env["product.product"], current_location, values
)
if not rule:
return self.browse()
if rule.procure_method == procure_method:
return rule.location_src_id
current_location = rule.location_src_id

View File

@@ -1,2 +1,3 @@
from . import test_location_is_sublocation_of
from . import test_location_get_closest_warehouse
from . import test_location_source_from_route

View File

@@ -0,0 +1,40 @@
# Copyright 2022 Michael Tietz (MT Software) <mtietz@mt-software.de>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from .common import StockHelperCommonCase
class TestStockLocationSoruceFromRoute(StockHelperCommonCase):
def test_get_source_location_from_route(self):
self.wh.delivery_steps = "pick_pack_ship"
route = self.wh.delivery_route_id
location = self.env.ref("stock.stock_location_customers")
source_location = location._get_source_location_from_route(
route, "make_to_stock"
)
self.assertEqual(source_location, self.wh.lot_stock_id)
source_location = location._get_source_location_from_route(
route, "make_to_order"
)
self.assertEqual(source_location, self.wh.wh_output_stock_loc_id)
location = source_location
source_location = location._get_source_location_from_route(
route, "make_to_order"
)
self.assertEqual(source_location, self.wh.wh_pack_stock_loc_id)
location = source_location
source_location = location._get_source_location_from_route(
route, "make_to_stock"
)
self.assertEqual(source_location, self.wh.lot_stock_id)
location = source_location
source_location = location._get_source_location_from_route(
route, "make_to_stock"
)
self.assertFalse(source_location)