Skip to content

Commit

Permalink
[16.0][ADD] stock_quant_task_deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed Nov 28, 2024
1 parent 54c9af4 commit f75969f
Show file tree
Hide file tree
Showing 20 changed files with 811 additions and 0 deletions.
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,
)
115 changes: 115 additions & 0 deletions stock_quant_task_deferred/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
=========================
Stock Quant Task Deferred
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b8e24044c7f7e50efbbb5f475083441d16cf963227abb08cd085419e7a7126b1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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]

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,
)
26 changes: 26 additions & 0 deletions stock_quant_task_deferred/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


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")._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.
1 change: 1 addition & 0 deletions stock_quant_task_deferred/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Denis Roussel <[email protected]>
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

0 comments on commit f75969f

Please sign in to comment.