Files
stock-logistics-warehouse/stock_helper/models/stock_location.py
Guewen Baconnier f04c497a9e Add stock_helper: share common code used by stock modules
The first method is: StockLocation.is_sublocation_of()

This method is currently used in:

* wms/stock_dynamic_routing
* wms/shopfloor
* wms/stock_move_source_relocate
* stock-logistics-warehouse/stock_reserve_rule
* ddmrp/ddmrp

The goal will be to use this module as dependency instead of
reimplementing the method in each.

Other methods should follow in "stock_helper".

Note: I opened https://github.com/odoo/odoo/pull/53866 to propose a
generic version of this method, expecting odoo's opinion, but got no
answer.
2021-03-19 12:51:27 +01:00

21 lines
788 B
Python

# Copyright 2020-2021 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import models
class StockLocation(models.Model):
_inherit = "stock.location"
def is_sublocation_of(self, others, func=any):
"""Return True if self is a sublocation of others (or equal)
By default, it return True if any other is a parent or equal.
``all`` can be passed to ``func`` to require all the other locations
to be parent or equal to be True.
"""
self.ensure_one()
# 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)