Skip to content

Commit

Permalink
[ADD] sale_automatic_workflow_stock_job
Browse files Browse the repository at this point in the history
  • Loading branch information
chaule97 committed Dec 4, 2024
1 parent 762844b commit 3d58e86
Show file tree
Hide file tree
Showing 14 changed files with 670 additions and 0 deletions.
83 changes: 83 additions & 0 deletions sale_automatic_workflow_stock_job/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
=================================
Sale Automatic Workflow Stock Job
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bd3562a627db0bfdb3b29c599458ad13598e1ac435e11a076fe6fe03cde4a661
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/18.0/sale_automatic_workflow_stock_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-18-0/sale-workflow-18-0-sale_automatic_workflow_stock_job
: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/sale-workflow&target_branch=18.0
:alt: Try me on Runboat

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

This module use Queue Jobs to process stock-related workflows in sales.

**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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_automatic_workflow_stock_job%0Aversion:%2018.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
------------

- Chau Le <chaulb@trobz.com>

Other credits
-------------

The development of this module has been financially supported by:

- Camptocamp

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/18.0/sale_automatic_workflow_stock_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_stock_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions sale_automatic_workflow_stock_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2011 Akretion Sébastien BEAU <sebastien.beau@akretion.com>
# Copyright 2013 Camptocamp SA (author: Guewen Baconnier)
# Copyright 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Automatic Workflow Stock Job",
"version": "18.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_job", "sale_automatic_workflow_stock"],
"data": [
"data/queue_job_data.xml",
],
"auto_install": True,
}
18 changes: 18 additions & 0 deletions sale_automatic_workflow_stock_job/data/queue_job_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="job_function_do_validate_picking" model="queue.job.function">
<field
name="model_id"
ref="sale_automatic_workflow_stock.model_automatic_workflow_job"
/>
<field name="method">_do_validate_picking</field>
<field
name="channel_id"
ref="sale_automatic_workflow_job.channel_sale_automatic_workflow"
/>
<field
name="related_action"
eval='{"func_name": "_related_action_sale_automatic_workflow"}'
/>
</record>
</odoo>
2 changes: 2 additions & 0 deletions sale_automatic_workflow_stock_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 sale_order
42 changes: 42 additions & 0 deletions sale_automatic_workflow_stock_job/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020 Camptocamp (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools.safe_eval import safe_eval

from odoo.addons.queue_job.job import identity_exact


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

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

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

@api.model
def _handle_pickings(self, sale_workflow):
workflow_domain = self._sale_workflow_domain(sale_workflow)

if sale_workflow.validate_picking:
self._validate_pickings(
safe_eval(sale_workflow.picking_filter_id.domain) + workflow_domain
)

def _register_hook(self):
self._patch_method(
"_do_validate_picking",
self._patch_job_auto_delay(
"_do_validate_picking", context_key="auto_delay_do_validation"
),
)
return super()._register_hook()
20 changes: 20 additions & 0 deletions sale_automatic_workflow_stock_job/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 Camptocamp (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class SaleOrder(models.Model):
_inherit = "sale.order"

@api.depends("delivery_status")
def _compute_all_qty_delivered(self):
for order in self:
order.all_qty_delivered = order.delivery_status == "full"

@api.onchange("workflow_process_id")
def _onchange_workflow_process_id(self):
if self.workflow_process_id.picking_policy:
self.picking_policy = self.workflow_process_id.picking_policy

return super()._onchange_workflow_process_id()
3 changes: 3 additions & 0 deletions sale_automatic_workflow_stock_job/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions sale_automatic_workflow_stock_job/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Chau Le \<<chaulb@trobz.com>\>
3 changes: 3 additions & 0 deletions sale_automatic_workflow_stock_job/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- Camptocamp
1 change: 1 addition & 0 deletions sale_automatic_workflow_stock_job/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module use Queue Jobs to process stock-related workflows in sales.
Loading

0 comments on commit 3d58e86

Please sign in to comment.