Merge PR #1697 into 16.0

Signed-off-by rousseldenis
This commit is contained in:
OCA-git-bot
2023-04-26 07:35:58 +00:00
3 changed files with 59 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
# Copyright 2020-2021 Camptocamp SA (http://www.camptocamp.com)
# 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
@@ -18,3 +19,20 @@ class StockLocation(models.Model):
# Efficient way to verify that the current location is
# below one of the other location without using SQL.
return func(self.parent_path.startswith(other.parent_path) for other in others)
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 +1,2 @@
from . import test_location_is_sublocation_of
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)