generated from OCA/oca-addons-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #467 from ecosoft-odoo/15.0-add-budget_control-queue
[15.0][ADD] budget_control_queue
- Loading branch information
Showing
16 changed files
with
848 additions
and
0 deletions.
There are no files selected for viewing
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,78 @@ | ||
====================== | ||
Budget Control - Queue | ||
====================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:170b7aa450e2ccdfa27c0d5840cf49a8511a46198988caa073e23f03a6689384 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |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-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github | ||
:target: https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control_queue | ||
:alt: ecosoft-odoo/budgeting | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
# TODO | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
# TODO | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/ecosoft-odoo/budgeting/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/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control_queue%0Aversion:%2015.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 | ||
~~~~~~~ | ||
|
||
* Ecosoft | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Saran Lim. <saranl@ecosoft.co.th> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px | ||
:target: https://github.com/Saran440 | ||
:alt: Saran440 | ||
|
||
Current maintainer: | ||
|
||
|maintainer-Saran440| | ||
|
||
This module is part of the `ecosoft-odoo/budgeting <https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control_queue>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
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). | ||
|
||
from . import models |
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,24 @@ | ||
# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Budget Control - Queue", | ||
"version": "15.0.1.0.0", | ||
"category": "Accounting", | ||
"license": "AGPL-3", | ||
"author": "Ecosoft, Odoo Community Association (OCA)", | ||
"website": "https://github.com/ecosoft-odoo/budgeting", | ||
"depends": [ | ||
"budget_control", | ||
"queue_job", | ||
], | ||
"data": [ | ||
"data/ir_config_parameter_data.xml", | ||
"data/queue_data.xml", | ||
"views/budget_balance_forward_view.xml", | ||
"views/budget_commit_forward_view.xml", | ||
], | ||
"installable": True, | ||
"maintainers": ["Saran440"], | ||
"development_status": "Alpha", | ||
} |
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,10 @@ | ||
<odoo noupdate="1"> | ||
<record id="budget_control_forward_create_analytic" model="ir.config_parameter"> | ||
<field name="key">budget_control.forward_create_analytic</field> | ||
<field name="value">100</field> | ||
</record> | ||
<record id="budget_control_carry_forward" model="ir.config_parameter"> | ||
<field name="key">budget_control.carry_forward</field> | ||
<field name="value">10</field> | ||
</record> | ||
</odoo> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record id="channel_budget_forward" model="queue.job.channel"> | ||
<field name="name">budget_forward</field> | ||
<field name="parent_id" ref="queue_job.channel_root" /> | ||
</record> | ||
</odoo> |
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). | ||
|
||
from . import budget_balance_forward | ||
from . import budget_commit_forward |
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,80 @@ | ||
# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
from odoo.addons.queue_job.delay import group | ||
|
||
|
||
class BudgetBalanceForward(models.Model): | ||
_inherit = "budget.balance.forward" | ||
|
||
use_queue_job = fields.Boolean() | ||
still_running = fields.Boolean(copy=False) | ||
|
||
def _create_missing_analytic_job(self, lines): | ||
self.ensure_one() | ||
for line in lines: | ||
line.to_analytic_account_id = line.analytic_account_id.next_year_analytic() | ||
|
||
def create_missing_analytic(self): | ||
if not self.use_queue_job: | ||
return super().create_missing_analytic() | ||
|
||
ICP = self.env["ir.config_parameter"] | ||
chunk_size_create_analytic = ( | ||
int(ICP.sudo().get_param("budget_control.forward_create_analytic")) or 100 | ||
) | ||
|
||
for rec in self: | ||
lines = rec.forward_line_ids.filtered_domain( | ||
[("to_analytic_account_id", "=", False)] | ||
) | ||
job_create_missing = [] | ||
# Create analytic with chunk | ||
for i in range(0, len(lines), chunk_size_create_analytic): | ||
chunk_lines = lines[i : i + chunk_size_create_analytic] | ||
job1 = rec.delayable( | ||
channel="root.budget_forward" | ||
)._create_missing_analytic_job(chunk_lines) | ||
job_create_missing.append(job1) | ||
# Change state and still running flag | ||
rec.write({"still_running": True}) | ||
# Job delay, change state back to done | ||
job_run_done = rec.delayable(channel="root.budget_forward").write( | ||
{"still_running": False} | ||
) | ||
|
||
# Run queue job | ||
group_job_create_missing = group(*job_create_missing) | ||
group_job_create_missing.on_done(job_run_done) | ||
group_job_create_missing.delay() | ||
|
||
def _action_budget_balance_forward(self): | ||
for rec in self: | ||
for line in rec.forward_line_ids: | ||
if line.method_type == "extend": | ||
line.to_analytic_account_id.bm_date_to = ( | ||
rec.to_budget_period_id.bm_date_to | ||
) | ||
# -- | ||
self.write({"state": "done"}) | ||
self._do_update_initial_avaliable() | ||
|
||
def action_budget_balance_forward(self): | ||
if not self.use_queue_job: | ||
return super().action_budget_balance_forward() | ||
|
||
job_balance_forward = self.delayable( | ||
channel="root.budget_forward" | ||
)._action_budget_balance_forward() | ||
# Change state and still running flag | ||
self.write({"still_running": True}) | ||
# Job delay, change state back to done | ||
job_run_done = self.delayable(channel="root.budget_forward").write( | ||
{"still_running": False} | ||
) | ||
|
||
# Run queue job | ||
job_balance_forward.on_done(job_run_done) | ||
job_balance_forward.delay() |
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,153 @@ | ||
# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
from odoo.addons.queue_job.delay import chain, group | ||
|
||
|
||
class BudgetCommitForward(models.Model): | ||
_inherit = "budget.commit.forward" | ||
|
||
use_queue_job = fields.Boolean() | ||
still_running = fields.Boolean(copy=False) | ||
|
||
def _create_missing_analytic_job(self, lines): | ||
self.ensure_one() | ||
for line in lines: | ||
line.to_analytic_account_id = line.analytic_account_id.next_year_analytic() | ||
|
||
def create_missing_analytic(self): | ||
if not self.use_queue_job: | ||
return super().create_missing_analytic() | ||
|
||
ICP = self.env["ir.config_parameter"] | ||
chunk_size_create_analytic = ( | ||
int(ICP.sudo().get_param("budget_control.carry_forward_create_analytic")) | ||
or 100 | ||
) | ||
|
||
for rec in self: | ||
lines = rec.forward_line_ids.filtered_domain( | ||
[("to_analytic_account_id", "=", False)] | ||
) | ||
job_create_missing = [] | ||
# Create analytic with chunk | ||
for i in range(0, len(lines), chunk_size_create_analytic): | ||
chunk_lines = lines[i : i + chunk_size_create_analytic] | ||
job1 = rec.delayable( | ||
channel="root.budget_forward" | ||
)._create_missing_analytic_job(chunk_lines) | ||
job_create_missing.append(job1) | ||
# Change state and still running flag | ||
rec.write({"still_running": True}) | ||
# Job delay, change state back to done | ||
job_run_done = rec.delayable(channel="root.budget_forward").write( | ||
{"still_running": False} | ||
) | ||
|
||
# Run queue job | ||
group_job_create_missing = group(*job_create_missing) | ||
group_job_create_missing.on_done(job_run_done) | ||
group_job_create_missing.delay() | ||
|
||
def _job_do_forward_commit(self): | ||
self._do_forward_commit() | ||
self.write({"state": "done"}) | ||
self._do_update_initial_commit() | ||
|
||
def _job_recompute(self, chunk_lines): | ||
for line in chunk_lines: | ||
doc = line.document_number | ||
doc.recompute_budget_move() | ||
|
||
def action_budget_commit_forward(self): | ||
"""Use queue job will split function into multiple jobs""" | ||
if not self.use_queue_job: | ||
return super().action_budget_commit_forward() | ||
|
||
ICP = self.env["ir.config_parameter"] | ||
chunk_size_carry_forward = ( | ||
int(ICP.sudo().get_param("budget_control.carry_forward")) or 10 | ||
) | ||
|
||
# Job1: Do Forward Commit | ||
job_carry_commit = self.delayable( | ||
channel="root.budget_forward" | ||
)._job_do_forward_commit() | ||
|
||
# Recompute budget on document number | ||
job_recompute = [] | ||
lines = self.forward_line_ids | ||
for i in range(0, len(lines), chunk_size_carry_forward): | ||
chunk_lines = lines[i : i + chunk_size_carry_forward] | ||
|
||
# Job2: Recompute after carry forward and update line is done | ||
job2 = self.delayable(channel="root.budget_forward")._job_recompute( | ||
chunk_lines | ||
) | ||
job_recompute.append(job2) | ||
self.write({"still_running": True}) | ||
|
||
group_job_recompute = group(*job_recompute) | ||
|
||
# Job3: Update header is done | ||
job_run_done = self.delayable(channel="root.budget_forward").write( | ||
{"still_running": False} | ||
) | ||
|
||
# Run queue job | ||
chain_process = chain( | ||
job_carry_commit, | ||
group_job_recompute, | ||
job_run_done, | ||
) | ||
chain_process.delay() | ||
|
||
def _job_reverse_forward_commit(self): | ||
self.filtered(lambda l: l.state == "done")._do_forward_commit(reverse=True) | ||
self.write({"state": "cancel"}) | ||
self._do_update_initial_commit(reverse=True) | ||
|
||
def _action_cancel(self): | ||
"""Use queue job will split function into multiple jobs""" | ||
if not self.use_queue_job: | ||
return super().action_cancel() | ||
|
||
ICP = self.env["ir.config_parameter"] | ||
chunk_size_carry_forward_cancel = ( | ||
int(ICP.sudo().get_param("budget_control.carry_forward")) or 10 | ||
) | ||
|
||
# Job1: Reverse Forward Commit | ||
job_carry_commit = self.delayable( | ||
channel="root.budget_forward" | ||
)._job_reverse_forward_commit() | ||
|
||
# Recompute budget on document number | ||
job_recompute = [] | ||
lines = self.forward_line_ids | ||
for i in range(0, len(lines), chunk_size_carry_forward_cancel): | ||
chunk_lines = lines[i : i + chunk_size_carry_forward_cancel] | ||
|
||
# Job2: Recompute after carry forward and update line is done | ||
job2 = self.delayable(channel="root.budget_forward")._job_recompute( | ||
chunk_lines | ||
) | ||
job_recompute.append(job2) | ||
self.write({"still_running": True}) | ||
|
||
group_job_recompute = group(*job_recompute) | ||
|
||
# Job3: Update header is done | ||
job_run_done = self.delayable(channel="root.budget_forward").write( | ||
{"still_running": False} | ||
) | ||
|
||
# Run queue job | ||
chain_process = chain( | ||
job_carry_commit, | ||
group_job_recompute, | ||
job_run_done, | ||
) | ||
chain_process.delay() |
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 @@ | ||
* Saran Lim. <saranl@ecosoft.co.th> |
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 @@ | ||
# TODO |
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 @@ | ||
# TODO |
Oops, something went wrong.