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][MIG] sale_automatic_workflow_job #2348

Merged
Merged
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
89 changes: 89 additions & 0 deletions sale_automatic_workflow_job/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
===========================
Sale Automatic Workflow Job
===========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/15.0/sale_automatic_workflow_job
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_automatic_workflow_job
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/15.0
:alt: Try me on Runbot

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

Use Queue Jobs to process the Sales Automatic Workflow actions.

The default behavior of the automatic workflow module is to use a
scheduled action that searches all the record that need a workflow
action and sequentially process all of them.

It can hit some limits when the number of records is too high.

This module keeps the scheduled action to search the records, but
instead of directly executing the actions (confirm a sales order,
create invoices for a sales order, validate invoices, ...), it
creates one job per operation to do.

It uses an identity key on the jobs so it will not create the same
job for the same record and same operation twice.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_automatic_workflow_job%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
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Saran Lim. <saranl@ecosoft.co.th>
* Kitti U. <kittiu@ecosoft.co.th>

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/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/sale_automatic_workflow_job>`_ 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 sale_automatic_workflow_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions sale_automatic_workflow_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 Camptocamp (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Automatic Workflow Job",
"summary": "Execute sale automatic workflows in queue jobs",
"version": "16.0.1.0.0",
"category": "Sales Management",
"license": "AGPL-3",
"author": "Camptocamp, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["sale_automatic_workflow", "queue_job"],
"data": [
"data/queue_job_data.xml",
],
}
74 changes: 74 additions & 0 deletions sale_automatic_workflow_job/data/queue_job_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Queue Job Channel -->
<record id="channel_sale_automatic_workflow" model="queue.job.channel">
<field name="name">channel.sale.automatic.workflow</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<!-- Queue Job Function -->
<record id="job_function_do_validate_sale_order" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_job.model_automatic_workflow_job"
/>
<field name="method">_do_validate_sale_order</field>
<field name="channel_id" ref="channel_sale_automatic_workflow" />
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>

<record id="job_function_do_create_invoice" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_job.model_automatic_workflow_job"
/>
<field name="method">_do_create_invoice</field>
<field name="channel_id" ref="channel_sale_automatic_workflow" />
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>

<record id="job_function_do_validate_invoice" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_job.model_automatic_workflow_job"
/>
<field name="method">_do_validate_invoice</field>
<field name="channel_id" ref="channel_sale_automatic_workflow" />
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>

<record id="job_function_do_validate_picking" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_job.model_automatic_workflow_job"
/>
<field name="method">_do_validate_picking</field>
<field name="channel_id" ref="channel_sale_automatic_workflow" />
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>

<record id="job_function_do_sale_done" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_job.model_automatic_workflow_job"
/>
<field name="method">_do_sale_done</field>
<field name="channel_id" ref="channel_sale_automatic_workflow" />
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>
</odoo>
62 changes: 62 additions & 0 deletions sale_automatic_workflow_job/i18n/sale_automatic_workflow_job.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_automatic_workflow_job
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/automatic_workflow_job.py:0
#, python-format
msgid "Create invoices for sales order {}"
msgstr ""

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/automatic_workflow_job.py:0
#, python-format
msgid "Mark sales order {} as done"
msgstr ""

#. module: sale_automatic_workflow_job
#: model:ir.model,name:sale_automatic_workflow_job.model_queue_job
msgid "Queue Job"
msgstr ""

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/queue_job.py:0
#, python-format
msgid "Sale Automatic Workflow Job"
msgstr ""

#. module: sale_automatic_workflow_job
#: model:ir.model,name:sale_automatic_workflow_job.model_automatic_workflow_job
msgid ""
"Scheduler that will play automatically the validation of invoices, "
"pickings..."
msgstr ""

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/automatic_workflow_job.py:0
#, python-format
msgid "Validate invoice {}"
msgstr ""

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/automatic_workflow_job.py:0
#, python-format
msgid "Validate sales order {}"
msgstr ""

#. module: sale_automatic_workflow_job
#: code:addons/sale_automatic_workflow_job/models/automatic_workflow_job.py:0
#, python-format
msgid "Validate transfer {}"
msgstr ""
2 changes: 2 additions & 0 deletions sale_automatic_workflow_job/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import automatic_workflow_job
from . import queue_job
85 changes: 85 additions & 0 deletions sale_automatic_workflow_job/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2020 Camptocamp (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, models

from odoo.addons.queue_job.job import identity_exact


class AutomaticWorkflowJob(models.Model):
_inherit = "automatic.workflow.job"

def _do_validate_sale_order_job_options(self, sale, domain_filter):
description = _("Validate sales order {}").format(sale.display_name)
return {
"description": description,
"identity_key": identity_exact,
}

def _validate_sale_orders(self, domain_filter):
with_context = self.with_context(auto_delay_do_validation=True)
return super(AutomaticWorkflowJob, with_context)._validate_sale_orders(
domain_filter
)

def _do_create_invoice_job_options(self, sale, domain_filter):
description = _("Create invoices for sales order {}").format(sale.display_name)
return {
"description": description,
"identity_key": identity_exact,
}

def _create_invoices(self, domain_filter):
with_context = self.with_context(auto_delay_do_create_invoice=True)
return super(AutomaticWorkflowJob, with_context)._create_invoices(domain_filter)

def _do_validate_invoice_job_options(self, invoice, domain_filter):
description = _("Validate invoice {}").format(invoice.display_name)
return {
"description": description,
"identity_key": identity_exact,
}

def _validate_invoices(self, domain_filter):
with_context = self.with_context(auto_delay_do_validation=True)
return super(AutomaticWorkflowJob, with_context)._validate_invoices(
domain_filter
)

def _do_validate_picking_job_options(self, picking, domain_filter):
description = _("Validate transfer {}").format(picking.display_name)
return {
"description": description,
"identity_key": identity_exact,
}

def _validate_pickings(self, domain_filter):
with_context = self.with_context(auto_delay_do_validation=True)
return super(AutomaticWorkflowJob, with_context)._validate_pickings(
domain_filter
)

def _do_sale_done_job_options(self, sale, domain_filter):
description = _("Mark sales order {} as done").format(sale.display_name)
return {
"description": description,
"identity_key": identity_exact,
}

def _sale_done(self, domain_filter):
with_context = self.with_context(auto_delay_do_sale_done=True)
return super(AutomaticWorkflowJob, with_context)._sale_done(domain_filter)

def _register_hook(self):
mapping = {
"_do_validate_sale_order": "auto_delay_do_validation",
"_do_create_invoice": "auto_delay_do_create_invoice",
"_do_validate_invoice": "auto_delay_do_validation",
"_do_validate_picking": "auto_delay_do_validation",
"_do_sale_done": "auto_delay_do_sale_done",
}
for method_name, context_key in mapping.items():
self._patch_method(
method_name,
self._patch_job_auto_delay(method_name, context_key=context_key),
)
return super()._register_hook()
21 changes: 21 additions & 0 deletions sale_automatic_workflow_job/models/queue_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models


class QueueJob(models.Model):
"""Job status and result"""

_inherit = "queue.job"

def _related_action_sale_automatic_workflow(self):
obj = self.args[0]
action = {
"name": _("Sale Automatic Workflow Job"),
"type": "ir.actions.act_window",
"res_model": obj._name,
"view_mode": "form",
"res_id": obj.id,
}
return action
3 changes: 3 additions & 0 deletions sale_automatic_workflow_job/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Saran Lim. <saranl@ecosoft.co.th>
* Kitti U. <kittiu@ecosoft.co.th>
15 changes: 15 additions & 0 deletions sale_automatic_workflow_job/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Use Queue Jobs to process the Sales Automatic Workflow actions.

The default behavior of the automatic workflow module is to use a
scheduled action that searches all the record that need a workflow
action and sequentially process all of them.

It can hit some limits when the number of records is too high.

This module keeps the scheduled action to search the records, but
instead of directly executing the actions (confirm a sales order,
create invoices for a sales order, validate invoices, ...), it
creates one job per operation to do.

It uses an identity key on the jobs so it will not create the same
job for the same record and same operation twice.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading