-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][ADD] stock_available_immediately_exclude_location
- Loading branch information
Showing
14 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ble_immediately_exclude_location/odoo/addons/stock_available_immediately_exclude_location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_available_immediately_exclude_location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
================================================== | ||
Exclude locations from immediately usable quantity | ||
================================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models |
13 changes: 13 additions & 0 deletions
13
stock_available_immediately_exclude_location/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Exclude locations from immediately usable quantity", | ||
"version": "16.0.1.0.0", | ||
"depends": ["stock_available_immediately"], | ||
"website": "https://github.com/OCA/stock-logistics-availability", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"category": "Hidden", | ||
"installable": True, | ||
} |
36 changes: 36 additions & 0 deletions
36
...ilable_immediately_exclude_location/i18n/stock_available_immediately_exclude_location.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * stock_available_immediately_exclude_location | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-01-18 10:17+0000\n" | ||
"PO-Revision-Date: 2023-01-18 10:17+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: stock_available_immediately_exclude_location | ||
#: model:ir.model.fields,field_description:stock_available_immediately_exclude_location.field_stock_location__exclude_from_immediately_usable_qty | ||
msgid "Exclude from immediately usable quantity" | ||
msgstr "" | ||
|
||
#. module: stock_available_immediately_exclude_location | ||
#: model:ir.model,name:stock_available_immediately_exclude_location.model_stock_location | ||
msgid "Inventory Locations" | ||
msgstr "" | ||
|
||
#. module: stock_available_immediately_exclude_location | ||
#: model:ir.model,name:stock_available_immediately_exclude_location.model_product_product | ||
msgid "Product Variant" | ||
msgstr "" | ||
|
||
#. module: stock_available_immediately_exclude_location | ||
#: model:ir.model.fields,help:stock_available_immediately_exclude_location.field_stock_location__exclude_from_immediately_usable_qty | ||
msgid "This property is not inherited by children locations" | ||
msgstr "" |
4 changes: 4 additions & 0 deletions
4
stock_available_immediately_exclude_location/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import product_product | ||
from . import stock_location |
73 changes: 73 additions & 0 deletions
73
stock_available_immediately_exclude_location/models/product_product.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models | ||
from odoo.osv import expression | ||
|
||
|
||
class ProductProduct(models.Model): | ||
|
||
_inherit = "product.product" | ||
|
||
def _compute_available_quantities_dict(self): | ||
""" | ||
change the way immediately_usable_qty is computed by deducing the quants | ||
in excluded locations | ||
""" | ||
res, stock_dict = super( | ||
ProductProduct, self | ||
)._compute_available_quantities_dict() | ||
exclude_location_ids = ( | ||
self._get_locations_excluded_from_immediately_usable_qty().ids | ||
) | ||
|
||
if exclude_location_ids: | ||
excluded_qty_dict = self.with_context( | ||
location=exclude_location_ids, compute_child=False | ||
)._compute_quantities_dict( | ||
self._context.get("lot_id"), | ||
self._context.get("owner_id"), | ||
self._context.get("package_id"), | ||
self._context.get("from_date"), | ||
self._context.get("to_date"), | ||
) | ||
|
||
for product_id in res: | ||
if exclude_location_ids: | ||
res[product_id]["immediately_usable_qty"] -= excluded_qty_dict[ | ||
product_id | ||
]["qty_available"] | ||
return res, stock_dict | ||
|
||
def _get_locations_excluded_from_immediately_usable_qty(self): | ||
return self.env["stock.location"].search( | ||
self._get_domain_location_excluded_from_immediately_usable_qty() | ||
) | ||
|
||
def _get_domain_location_excluded_from_immediately_usable_qty(self): | ||
""" | ||
Parses the context and returns a list of location_ids based on it that | ||
should be excluded from the immediately_usable_qty | ||
""" | ||
quant_domain = self.env["product.product"]._get_domain_locations()[0] | ||
# The only creteria on the quants are on company_id and location_id | ||
# fields. The same domain can be safely reused to get the precise list | ||
# of locations to exclude by adding the criteria on | ||
# exclude_from_immediately_usable_qty and adapting the domain to work | ||
# on stock.location. | ||
# In this way we are always sure that the computation of qties to | ||
# exclude is always done for locations part of the expected locations | ||
# provided by the context/ | ||
# replace location_id by id into the quant domain to get the | ||
# domain to apply to the locations | ||
location_domain = [] | ||
for element in quant_domain: | ||
if expression.is_leaf(element): | ||
location_domain.append( | ||
(element[0].replace("location_id.", ""), element[1], element[2]) | ||
) | ||
else: | ||
location_domain.append(element) | ||
return expression.AND( | ||
[location_domain, [("exclude_from_immediately_usable_qty", "=", True)]] | ||
) |
16 changes: 16 additions & 0 deletions
16
stock_available_immediately_exclude_location/models/stock_location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockLocation(models.Model): | ||
|
||
_inherit = "stock.location" | ||
|
||
exclude_from_immediately_usable_qty = fields.Boolean( | ||
"Exclude from immediately usable quantity", | ||
default=False, | ||
index=True, | ||
help="This property is not inherited by children locations", | ||
) |
1 change: 1 addition & 0 deletions
1
stock_available_immediately_exclude_location/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Author: Hughes Damry <[email protected]> |
2 changes: 2 additions & 0 deletions
2
stock_available_immediately_exclude_location/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module adds a boolean to exclude the tagged stock locations | ||
from the stock available immediately. |
Binary file added
BIN
+9.23 KB
stock_available_immediately_exclude_location/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_stock_exclude_location |
61 changes: 61 additions & 0 deletions
61
stock_available_immediately_exclude_location/tests/test_stock_exclude_location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestStockLogisticsWarehouse(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls) -> None: | ||
super().setUpClass() | ||
cls.move_model = cls.env["stock.move"] | ||
cls.uom_unit = cls.env.ref("uom.product_uom_unit") | ||
cls.product = cls.env["product.product"].create( | ||
{ | ||
"name": "Product Test", | ||
"uom_id": cls.uom_unit.id, | ||
"type": "product", | ||
} | ||
) | ||
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") | ||
cls.stock_location = cls.env.ref("stock.stock_location_stock") | ||
cls.pack_location = cls.env.ref("stock.location_pack_zone") | ||
(cls.stock_location | cls.pack_location).write({"active": True}) | ||
|
||
def test01(self): | ||
location_ids = (self.stock_location | self.pack_location).ids | ||
ctx_loc = {"location": location_ids} | ||
move_stock = self.move_model.create( | ||
{ | ||
"location_id": self.supplier_location.id, | ||
"location_dest_id": self.stock_location.id, | ||
"name": "MOVE STOCK ", | ||
"product_id": self.product.id, | ||
"product_uom": self.product.uom_id.id, | ||
"product_uom_qty": 15, | ||
} | ||
) | ||
move_pack = self.move_model.create( | ||
{ | ||
"location_id": self.supplier_location.id, | ||
"location_dest_id": self.pack_location.id, | ||
"name": "MOVE PACK ", | ||
"product_id": self.product.id, | ||
"product_uom": self.product.uom_id.id, | ||
"product_uom_qty": 5, | ||
} | ||
) | ||
(move_stock | move_pack)._action_confirm() | ||
(move_stock | move_pack)._action_assign() | ||
move_stock.move_line_ids.write({"qty_done": 7.0}) | ||
move_stock._action_done() | ||
q = self.product.with_context(**ctx_loc).immediately_usable_qty | ||
self.assertEqual(q, 7.0) | ||
move_pack.move_line_ids.write({"qty_done": 4.0}) | ||
move_pack._action_done() | ||
q = self.product.with_context(**ctx_loc).immediately_usable_qty | ||
self.assertEqual(q, 11.0) | ||
self.pack_location.exclude_from_immediately_usable_qty = True | ||
self.product.invalidate_recordset() # force recompute | ||
q = self.product.with_context(**ctx_loc).immediately_usable_qty | ||
self.assertEqual(q, 7.0) |