Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] stock_quant_task_deferred #2205

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_quant_task_deferred/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,
)
116 changes: 116 additions & 0 deletions stock_quant_task_deferred/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
=========================
Stock Quant Task Deferred
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d91c5b8474a86c4cfbb6bc0018af2553324d948cb619a9e1535f06ad76b49988
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_quant_task_deferred
: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_quant_task_deferred
: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 deactivate synchronuous quant tasks and use a cron
job instead.

The cron job will trigger queue jobs to do the tasks.

**Table of contents**

.. contents::
:local:

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

- In Odoo, product quantities are regularily reorganized:

- when opening the product stock from product form
- when unpacking products

This implies a lot of stock quants are deleted if you have a lot of
stock operations and users in parallel.

That can causes some DB locks.

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

- Go to Inventory > Configuration > Settings > Warehouse.
- Check the box 'Defer Quant Tasks' if you want to deactivate
synchronuous quant tasks.
- Go To Settings > Technical > Scheduled Actions > 'Launch quant tasks'.
- Set the desired cron job configuration.

Usage
=====

- After having configured the scheduled task, go to Queue Job and look
for "Executing Quant Tasks" queue job descriptions.

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_quant_task_deferred%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]
- Jacques-Étienne Baudoux [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_quant_task_deferred>`_ project on GitHub.

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

{
"name": "Stock Quant Task Deferred",
"summary": """This module allows to defer quant tasks (merge, delete)""",
"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",
"maintainers": ["rousseldenis"],
"depends": ["stock", "queue_job"],
"data": ["views/res_config_settings.xml", "data/ir_cron.xml"],
}
19 changes: 19 additions & 0 deletions stock_quant_task_deferred/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>
<record id="ir_cron_quant_task_deferred" model="ir.cron">
<field name="name">Launch quant tasks</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field
name="nextcall"
eval="(DateTime.now().replace(hour=2, minute=0) + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"
/>
<field name="doall" eval="False" />
<field name="model_id" ref="model_stock_quant" />
<field name="code">model._run_quant_tasks_deferred()</field>
<field name="state">code</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions stock_quant_task_deferred/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_quant
from . import res_company
from . import res_config_settings
13 changes: 13 additions & 0 deletions stock_quant_task_deferred/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):

_inherit = "res.company"

defer_quant_tasks = fields.Boolean(
help="Check this if you want to defer stock quant deletions and merges."
)
14 changes: 14 additions & 0 deletions stock_quant_task_deferred/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

defer_quant_tasks = fields.Boolean(
related="company_id.defer_quant_tasks",
readonly=False,
)
29 changes: 29 additions & 0 deletions stock_quant_task_deferred/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models

from odoo.addons.queue_job.job import identity_exact


class StockQuant(models.Model):

_inherit = "stock.quant"

def _quant_tasks(self):
# Introduce a parameter that enable to run the
# function even if disabled in company settings
if self.env.company.defer_quant_tasks and not self.env.context.get(
"run_defer_quant_tasks"
):
return
return super()._quant_tasks()

@api.model
def _quant_tasks_deferred(self):
self.with_context(run_defer_quant_tasks=True)._quant_tasks()

@api.model
def _run_quant_tasks_deferred(self):
self.with_delay(
description="Executing Quant Tasks", identity_key=identity_exact
)._quant_tasks_deferred()
5 changes: 5 additions & 0 deletions stock_quant_task_deferred/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Go to Inventory > Configuration > Settings > Warehouse.
- Check the box 'Defer Quant Tasks' if you want to deactivate
synchronuous quant tasks.
- Go To Settings > Technical > Scheduled Actions > 'Launch quant tasks'.
- Set the desired cron job configuration.
8 changes: 8 additions & 0 deletions stock_quant_task_deferred/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- In Odoo, product quantities are regularily reorganized:
- when opening the product stock from product form
- when unpacking products

This implies a lot of stock quants are deleted if you have a lot
of stock operations and users in parallel.

That can causes some DB locks.
2 changes: 2 additions & 0 deletions stock_quant_task_deferred/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Denis Roussel <[email protected]>
- Jacques-Étienne Baudoux <[email protected]>
Copy link
Contributor

@sebalix sebalix Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I should be listed as well? As I gave the idea to J-E (I implemented that for one of our customer).
EDIT: if not I don't really care, happy to see this consolidated in a module :)

4 changes: 4 additions & 0 deletions stock_quant_task_deferred/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module allows to deactivate synchronuous quant tasks and
use a cron job instead.

The cron job will trigger queue jobs to do the tasks.
3 changes: 3 additions & 0 deletions stock_quant_task_deferred/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- After having configured the scheduled task, go to Queue Job and look
for "Executing Quant Tasks" queue job descriptions.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading