Skip to content

Commit

Permalink
[ADD] stock_location_orderpoint_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed May 22, 2024
1 parent 4e3de1a commit ae6b488
Show file tree
Hide file tree
Showing 22 changed files with 1,269 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_location_orderpoint_cleanup/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,
)
125 changes: 125 additions & 0 deletions stock_location_orderpoint_cleanup/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
=================================
Stock Location Orderpoint Cleanup
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1d2edee5c7e9fe14d296fff5e6aeafbbe6463587afb0f17c7dd37d8a7d55646d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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--orderpoint-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-orderpoint/tree/16.0/stock_location_orderpoint_cleanup
:alt: OCA/stock-logistics-orderpoint
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-orderpoint-16-0/stock-logistics-orderpoint-16-0-stock_location_orderpoint_cleanup
: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-orderpoint&target_branch=16.0
:alt: Try me on Runboat

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

This module will help to clean generated moves from stock location
orderpoints.

**Table of contents**

.. contents::
:local:

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

Location orderpoints module was designed (first) to generate
replenishment moves for particular stock locations. e.g.: we have a
reserve stock and a preparation stock.

As warehouse life is not static, moves for a product can be cancelled,
preparation stock could have been refilled with another move, ...

So, generated moves from location orderpoints can become obsolete.

This module should help to clean orderpoint moves and regenerate moves.

Configuration
=============

- There is a security group 'Location Orderpoint Cleanup Group'. Users
that can have access to cleanup action should be in that group. By
default, all users that are in 'Inventory/Administrator' are in that
group.
- You can configure crons to execute cleanup actions.

- Enable debug mode, go to Settings > Technical > Scheduled Actions
- Add a cron with:

- base model 'Stock Location Orderpoint'
- In python code, add a line 'model.run_cleanup(orderpoints,
run_after)' where 'orderpoints' is a list of orderpoint ids and
'run_after' is True if you want to run the orderpoint(s) after
cleanup.
- If you want to cleanup ordepoints by replenish method, add a
line 'model.run_cleanup_method(replenish_method, run_after)'
where 'replenish_method' is 'fill_up' by default (depending on
extension modules you have installed)

Usage
=====

- You can have cron jobs to execute the cleanup actions (see
Configuration section).
- If you are in the 'Location Orderpoint Cleanup Group', you can launch
manually the cleanup on the orderpoint form level:

- Click on 'Cleanup replenishments'.
- In the wizard, check the 'Run After' box if you want the
orderpoint to be run after cleanup.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-orderpoint/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-orderpoint/issues/new?body=module:%20stock_location_orderpoint_cleanup%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 denis.roussel@acsone.eu

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.

This module is part of the `OCA/stock-logistics-orderpoint <https://github.com/OCA/stock-logistics-orderpoint/tree/16.0/stock_location_orderpoint_cleanup>`_ 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_orderpoint_cleanup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
18 changes: 18 additions & 0 deletions stock_location_orderpoint_cleanup/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Location Orderpoint Cleanup",
"summary": """
This module allows to clean moves generated by orderpoint""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-orderpoint",
"depends": ["base_partition", "stock_location_orderpoint", "queue_job"],
"data": [
"security/security.xml",
"wizards/stock_location_orderpoint_cleanup.xml",
"views/stock_location_orderpoint.xml",
],
}
1 change: 1 addition & 0 deletions stock_location_orderpoint_cleanup/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_location_orderpoint, stock_picking
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from odoo import _, api, models

from odoo.addons.queue_job.job import identity_exact

_logger = logging.getLogger(__name__)


class StockLocationOrderpoint(models.Model):

_inherit = "stock.location.orderpoint"

def _get_moves_to_cleanup_domain(self) -> list:
self.ensure_one()
return [
("location_orderpoint_id", "=", self.id),
("state", "not in", ("done", "cancel")),
("quantity_done", "<=", 0),
("picking_id.printed", "=", False),
]

def _get_moves_to_cleanup(self):
self.ensure_one()
moves = self.env["stock.move"].search(self._get_moves_to_cleanup_domain())
return moves

def cleanup(self, run_after=False):
"""
This method will launch the cleanup process as a queue job.
"""
for orderpoint in self:
description = _(
"Running the cleanup for the orderpoint %(orderpoint_name)s",
orderpoint_name=orderpoint.name,
)
orderpoint.with_delay(
description=description, identity_key=identity_exact
)._cleanup(run_after=run_after)

def _cleanup(self, run_after=False):
"""
run_after: Run the orderpoint after cleanup
"""

moves = self._get_moves_to_cleanup()
for picking, moves in moves.partition("picking_id").items():
moves.exists()._action_cancel()
picking._log_location_orderpoint_cleanup_message(self, moves)

if run_after:
self.run_replenishment()

@api.model
def run_cleanup(self, orderpoints=False, run_after=False):
"""
This method should be called by crons
"""
self.browse(orderpoints).cleanup(run_after=run_after)

@api.model
def run_cleanup_method(self, replenish_method="fill_up", run_after=False):
"""
This method should be called by crons.
e.g.: We have plenty of orderpoints but we know which replenish method
should be cleaned.
"""
if replenish_method not in self._fields["replenish_method"].get_values(
self.env
):
_logger.warning(
"You try to call 'run_cleanup_method' with an undefined replenish method '%s'",
replenish_method,
)
self.search([("replenish_method", "=", replenish_method)]).cleanup(
run_after=run_after
)

def get_cleanup_action(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_location_orderpoint_cleanup.stock_location_orderpoint_cleanup_act_window"
)
return action
25 changes: 25 additions & 0 deletions stock_location_orderpoint_cleanup/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models


class StockPicking(models.Model):

_inherit = "stock.picking"

def _log_location_orderpoint_cleanup_message(self, orderpoint, moves):
"""
This will log the moves that have been cancelled through the cleanup
process.
"""
self.ensure_one()
orderpoint_name = orderpoint.name
moves_name = ",".join(moves.mapped("product_id.name"))
message = _(
"These moves have been cleaned up for location orderpoint "
"%(orderpoint_name)s: %(moves_name)s",
orderpoint_name=orderpoint_name,
moves_name=moves_name,
)
self.message_post(body=message)
9 changes: 9 additions & 0 deletions stock_location_orderpoint_cleanup/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- There is a security group 'Location Orderpoint Cleanup Group'. Users
that can have access to cleanup action should be in that group. By default,
all users that are in 'Inventory/Administrator' are in that group.
- You can configure crons to execute cleanup actions.
- Enable debug mode, go to Settings > Technical > Scheduled Actions
- Add a cron with:
- base model 'Stock Location Orderpoint'
- In python code, add a line 'model.run_cleanup(orderpoints, run_after)' where 'orderpoints' is a list of orderpoint ids and 'run_after' is True if you want to run the orderpoint(s) after cleanup.
- If you want to cleanup ordepoints by replenish method, add a line 'model.run_cleanup_method(replenish_method, run_after)' where 'replenish_method' is 'fill_up' by default (depending on extension modules you have installed)
10 changes: 10 additions & 0 deletions stock_location_orderpoint_cleanup/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Location orderpoints module was designed (first) to generate replenishment moves
for particular stock locations. e.g.: we have a reserve stock and a preparation
stock.

As warehouse life is not static, moves for a product can be cancelled, preparation
stock could have been refilled with another move, ...

So, generated moves from location orderpoints can become obsolete.

This module should help to clean orderpoint moves and regenerate moves.
1 change: 1 addition & 0 deletions stock_location_orderpoint_cleanup/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Denis Roussel <denis.roussel@acsone.eu>
1 change: 1 addition & 0 deletions stock_location_orderpoint_cleanup/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module will help to clean generated moves from stock location orderpoints.
5 changes: 5 additions & 0 deletions stock_location_orderpoint_cleanup/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- You can have cron jobs to execute the cleanup actions (see Configuration section).
- If you are in the 'Location Orderpoint Cleanup Group', you can launch manually the cleanup
on the orderpoint form level:
- Click on 'Cleanup replenishments'.
- In the wizard, check the 'Run After' box if you want the orderpoint to be run after cleanup.
26 changes: 26 additions & 0 deletions stock_location_orderpoint_cleanup/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record model="res.groups" id="group_location_cleanup">
<field name="name">Location Orderpoint Cleanup Group</field>
</record>
<record model="res.groups" id="stock.group_stock_manager">
<field
name="implied_ids"
eval="[(4, ref('stock_location_orderpoint_cleanup.group_location_cleanup'))]"
/>
</record>

<record model="ir.model.access" id="stock_location_orderpoint_cleanup_access">
<field name="name">stock.location.orderpoint.cleanup access</field>
<field name="model_id" ref="model_stock_location_orderpoint_cleanup" />
<field name="group_id" ref="group_location_cleanup" />
<field name="perm_read" eval="1" />
<field name="perm_create" eval="1" />
<field name="perm_write" eval="1" />
<field name="perm_unlink" eval="1" />
</record>

</odoo>
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 ae6b488

Please sign in to comment.