mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
1
setup/stock_helper/odoo/addons/stock_helper
Symbolic link
1
setup/stock_helper/odoo/addons/stock_helper
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../../stock_helper
|
||||||
6
setup/stock_helper/setup.py
Normal file
6
setup/stock_helper/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
1
stock_helper/__init__.py
Normal file
1
stock_helper/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
15
stock_helper/__manifest__.py
Normal file
15
stock_helper/__manifest__.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Copyright 2020-2021 Camptocamp SA
|
||||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Stock Helpers",
|
||||||
|
"summary": "Add methods shared between various stock modules",
|
||||||
|
"version": "13.0.1.0.0",
|
||||||
|
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||||
|
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||||
|
"category": "Hidden",
|
||||||
|
"depends": ["stock"],
|
||||||
|
"data": [],
|
||||||
|
"installable": True,
|
||||||
|
"license": "LGPL-3",
|
||||||
|
}
|
||||||
1
stock_helper/models/__init__.py
Normal file
1
stock_helper/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import stock_location
|
||||||
20
stock_helper/models/stock_location.py
Normal file
20
stock_helper/models/stock_location.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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)
|
||||||
1
stock_helper/readme/CONTRIBUTORS.rst
Normal file
1
stock_helper/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
1
stock_helper/readme/DESCRIPTION.rst
Normal file
1
stock_helper/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Add methods to be used by other modules. This is not a functional module.
|
||||||
1
stock_helper/tests/__init__.py
Normal file
1
stock_helper/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_location_is_sublocation_of
|
||||||
19
stock_helper/tests/common.py
Normal file
19
stock_helper/tests/common.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Copyright 2020-2021 Camptocamp SA
|
||||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
|
from odoo.tests import SavepointCase
|
||||||
|
|
||||||
|
|
||||||
|
class StockHelperCommonCase(SavepointCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||||
|
|
||||||
|
cls.wh = cls.env.ref("stock.warehouse0")
|
||||||
|
|
||||||
|
cls.customer_loc = cls.env.ref("stock.stock_location_customers")
|
||||||
|
cls.supplier_loc = cls.env.ref("stock.stock_location_suppliers")
|
||||||
|
cls.stock_loc = cls.wh.lot_stock_id
|
||||||
|
cls.shelf1_loc = cls.env.ref("stock.stock_location_components")
|
||||||
|
cls.shelf2_loc = cls.env.ref("stock.stock_location_14")
|
||||||
48
stock_helper/tests/test_location_is_sublocation_of.py
Normal file
48
stock_helper/tests/test_location_is_sublocation_of.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Copyright 2020-2021 Camptocamp SA
|
||||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
|
|
||||||
|
from .common import StockHelperCommonCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestStockLocationIsSublocationOf(StockHelperCommonCase):
|
||||||
|
def test_is_sublocation_of_equal(self):
|
||||||
|
self.assertTrue(self.shelf1_loc.is_sublocation_of(self.shelf1_loc))
|
||||||
|
|
||||||
|
def test_is_sublocation_of_equal_child_ko(self):
|
||||||
|
bin_loc = self.env["stock.location"].create(
|
||||||
|
{"name": "bin", "location_id": self.shelf1_loc.id}
|
||||||
|
)
|
||||||
|
self.assertFalse(self.shelf1_loc.is_sublocation_of(bin_loc))
|
||||||
|
|
||||||
|
def test_is_sublocation_of_equal_child_sibling(self):
|
||||||
|
self.assertFalse(self.shelf1_loc.is_sublocation_of(self.shelf2_loc))
|
||||||
|
|
||||||
|
def test_is_sublocation_of_any_ok(self):
|
||||||
|
self.assertTrue(
|
||||||
|
self.shelf1_loc.is_sublocation_of(self.stock_loc | self.customer_loc)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_is_sublocation_of_any_ko(self):
|
||||||
|
self.assertFalse(
|
||||||
|
self.shelf1_loc.is_sublocation_of(self.supplier_loc | self.customer_loc)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_is_sublocation_of_all_ok(self):
|
||||||
|
self.assertTrue(
|
||||||
|
self.shelf1_loc.is_sublocation_of(
|
||||||
|
self.stock_loc | self.stock_loc.location_id, func=all
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_is_sublocation_of_all_ko(self):
|
||||||
|
self.assertFalse(
|
||||||
|
self.shelf1_loc.is_sublocation_of(
|
||||||
|
self.stock_loc | self.customer_loc, func=all
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.assertFalse(
|
||||||
|
self.shelf1_loc.is_sublocation_of(
|
||||||
|
self.supplier_loc | self.customer_loc, func=all
|
||||||
|
)
|
||||||
|
)
|
||||||
@@ -7,7 +7,11 @@
|
|||||||
"author": "Camptocamp, Odoo Community Association (OCA)",
|
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||||
"category": "Stock Management",
|
"category": "Stock Management",
|
||||||
"depends": ["stock", "product_packaging_type"], # OCA/product-attribute
|
"depends": [
|
||||||
|
"stock",
|
||||||
|
"stock_helper",
|
||||||
|
"product_packaging_type", # OCA/product-attribute
|
||||||
|
],
|
||||||
"demo": [
|
"demo": [
|
||||||
"demo/product_demo.xml",
|
"demo/product_demo.xml",
|
||||||
"demo/stock_location_demo.xml",
|
"demo/stock_location_demo.xml",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from . import stock_move
|
from . import stock_move
|
||||||
from . import stock_location
|
|
||||||
from . import stock_quant
|
from . import stock_quant
|
||||||
from . import stock_picking_type
|
from . import stock_picking_type
|
||||||
from . import stock_reserve_rule
|
from . import stock_reserve_rule
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
# Copyright 2019 Camptocamp SA
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
from odoo import models
|
|
||||||
|
|
||||||
|
|
||||||
class StockLocation(models.Model):
|
|
||||||
_inherit = "stock.location"
|
|
||||||
|
|
||||||
def is_sublocation_of(self, others):
|
|
||||||
"""Return True if self is a sublocation of at least one other"""
|
|
||||||
self.ensure_one()
|
|
||||||
# Efficient way to verify that the current location is
|
|
||||||
# below one of the other location without using SQL.
|
|
||||||
return any(self.parent_path.startswith(other.parent_path) for other in others)
|
|
||||||
Reference in New Issue
Block a user