mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
40
stock_helper/tests/test_location_source_from_route.py
Normal file
40
stock_helper/tests/test_location_source_from_route.py
Normal 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)
|
||||
Reference in New Issue
Block a user