Skip to content

Commit

Permalink
[16.0][ADD] stock_location_occupancy
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed Nov 7, 2024
1 parent b94a8a1 commit 7cef800
Show file tree
Hide file tree
Showing 18 changed files with 749 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_location_occupancy/setup.py
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,
)
103 changes: 103 additions & 0 deletions stock_location_occupancy/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
======================
Stock Location Is Void
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:da80cfa737e6761c803d2647b6dd0e9b31c81bc0ad510164eec90a95d3b69a00
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_location_occupancy
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_location_occupancy
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to identify void (without product quantities or
quants) stock locations.

|occupancy|

.. |occupancy| image:: https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/16.0/stock_location_occupancy/static/description/occupancy.png

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Stock logistic managers need to know the void stock locations in order
to measure the capacity of the warehouse and be able to reorganize it if
it does not fit the current replenishment coverage.

Usage
=====

- Go to Inventory > Configuration > Warehouse Management > Locations
- In the list of locations, enable the column visibility 'Occupancy'
- You can filter the locations per 'Void' or 'Occupied' property.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_occupancy%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Denis Roussel [email protected]

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px
:target: https://github.com/rousseldenis
:alt: rousseldenis

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-rousseldenis|

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_location_occupancy>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_location_occupancy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
17 changes: 17 additions & 0 deletions stock_location_occupancy/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Location Is Void",
"summary": """This module allows to identify void stock locations""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"depends": ["base_partition", "stock"],
"maintainers": ["rousseldenis"],
"data": [
"views/stock_location.xml",
],
"pre_init_hook": "pre_init_hook",
}
30 changes: 30 additions & 0 deletions stock_location_occupancy/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade

from odoo import SUPERUSER_ID
from odoo.api import Environment


def pre_init_hook(cr):

if not openupgrade.column_exists(cr, "stock_location", "occupancy"):
env = Environment(cr, SUPERUSER_ID, {})
field_spec = [
(
"occupied",
"stock.location",
False,
"boolean",
"boolean",
"stock_location_occupancy",
False,
)
]
openupgrade.add_fields(env, field_spec)
# Compute the True values
query = """
UPDATE stock_location SET occupied = True
WHERE EXISTS (SELECT 1 FROM stock_quant WHERE location_id = stock_location.id)
"""
openupgrade.logged_query(env.cr, query)
1 change: 1 addition & 0 deletions stock_location_occupancy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_location
41 changes: 41 additions & 0 deletions stock_location_occupancy/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockLocation(models.Model):

_inherit = "stock.location"

occupied = fields.Boolean(
compute="_compute_occupied",
store=True,
index=True,
help="This will reflect if the stock location is void or not (no product quantities).",
)
# This field is used to display the state of the location using
# the 'state_selection' widget.
occupied_state = fields.Selection(
[("done", "Void"), ("blocked", "Occupied")],
string="Occupancy",
compute="_compute_occupied_state",
)

@api.depends("occupied")
def _compute_occupied_state(self):
for occupied, locations in self.partition("occupied").items():
locations.occupied_state = "blocked" if occupied else "done"

@api.depends("quant_ids.location_id")
def _compute_occupied(self):
"""
Compute the 'occupied' field.
It is True when location does not contain any quant.
"""
quants_result = self.env["stock.quant"].read_group(
[("location_id", "in", self.ids)], ["location_id"], ["location_id"]
)
counts = [r["location_id"][0] for r in quants_result]
location_with_quants = self.filtered(lambda location: location.id in counts)
location_with_quants.occupied = True
(self - location_with_quants).occupied = False
3 changes: 3 additions & 0 deletions stock_location_occupancy/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Stock logistic managers need to know the void stock locations in order to
measure the capacity of the warehouse and be able to reorganize it if
it does not fit the current replenishment coverage.
1 change: 1 addition & 0 deletions stock_location_occupancy/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Denis Roussel <[email protected]>
3 changes: 3 additions & 0 deletions stock_location_occupancy/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows to identify void (without product quantities or quants) stock locations.

![occupancy](../static/description/occupancy.png)
3 changes: 3 additions & 0 deletions stock_location_occupancy/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Go to Inventory > Configuration > Warehouse Management > Locations
- In the list of locations, enable the column visibility 'Occupancy'
- You can filter the locations per 'Void' or 'Occupied' property.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7cef800

Please sign in to comment.