Skip to content

[18.0][MIG] sale_automatic_workflow_job: Migration to 18.0 #3460

Merged
OCA-git-bot merged 32 commits into
OCA:18.0from
chaule97:18.0-mig-sale_automatic_workflow_job
Apr 7, 2025
Merged

[18.0][MIG] sale_automatic_workflow_job: Migration to 18.0 #3460
OCA-git-bot merged 32 commits into
OCA:18.0from
chaule97:18.0-mig-sale_automatic_workflow_job

Conversation

@chaule97

@chaule97 chaule97 commented Dec 5, 2024

Copy link
Copy Markdown
Contributor
  • Depend on:
  • Because this commit separated the module stock from sale_automatic_workflow. I removed everything related to stock.
  • because _do_validate_sale_order will be run in job, I add _do_send_order_confirmation_mail in job and it will be run after 2 minutes
  • because queue_job affects test case in sale_automatic_workflow, I have removed tagged in TestAutomaticWorkflow

@chaule97 chaule97 force-pushed the 18.0-mig-sale_automatic_workflow_job branch from 3e8a3f0 to 1907b62 Compare January 9, 2025 04:00
@sebalix

sebalix commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

/ocabot migration sale_automatic_workflow_job

@OCA-git-bot OCA-git-bot added this to the 18.0 milestone Jan 14, 2025
Comment thread sale_automatic_workflow_job/models/automatic_workflow_job.py Outdated
@chaule97 chaule97 force-pushed the 18.0-mig-sale_automatic_workflow_job branch from 4aff9e4 to c4d794a Compare January 14, 2025 09:59
@chaule97 chaule97 requested a review from sebalix January 14, 2025 10:03

@yankinmax yankinmax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't get finally, why don't you replace existing string formatting with f-string. Instead you use old style.

Comment thread sale_automatic_workflow_job/models/automatic_workflow_job.py
Comment thread sale_automatic_workflow_job/models/automatic_workflow_job.py
Comment thread sale_automatic_workflow_job/models/automatic_workflow_job.py
Comment thread sale_automatic_workflow_job/models/automatic_workflow_job.py

def _do_sale_done_job_options(self, sale, domain_filter):
description = _("Mark sales order {} as done").format(sale.display_name)
description = self.env._("Mark sales order %s as done", sale.display_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
description = self.env._("Mark sales order %s as done", sale.display_name)
description = self.env._(f"Mark sales order {sale.display_name} as done")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vvrossem FTR using f strings will break translations because the string will be evaluated at run time making the string always different. Ideally we should have named placeholders like _("Foo %(baz)s", baz=self.baz), but is not a blocker.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other reviewers suggested to use a positional argument if there is only one (as is the case here), and switch to named arguments in case of multiple. I like that one myself, but maybe that's all that it is, a preference?

from odoo import fields
from odoo.tests import tagged

from .common import TestAutomaticWorkflowMixin, TestCommon

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would adapt TestCommon so it uses BaseCommon instead of TransactionCase

Use BaseCommon as base test class to reduce overhead from tracking and boost the test suite.

Comment thread sale_automatic_workflow/tests/test_automatic_workflow.py
@gurneyalex

gurneyalex commented Feb 26, 2025

Copy link
Copy Markdown
Member

I'm wondering why we are keeping the cron jobs in this module?

This seems so inefficient, when we could have the queue jobs created on creation of the various records (sale, picking, invoice) based on the configured automatic workflow.

Maybe I'm missing a use case...

[EDIT] use case I'm missing: external event changing something on the record which makes it match the configured domain to trigger the workflow. But this could be handled by an automated action.

@simahawk

Copy link
Copy Markdown
Contributor

I'm wondering why we are keeping the cron jobs in this module?

This seems so inefficient, when we could have the queue jobs created on creation of the various records (sale, picking, invoice) based on the configured automatic workflow.

Maybe I'm missing a use case...

[EDIT] use case I'm missing: external event changing something on the record which makes it match the configured domain to trigger the workflow. But this could be handled by an automated action.

I can give you another use case: having a delay between the creation of the SO and the automatic approval (real customer use case).

IMO it's better to keep the cron because it also helps not to spawn useless jobs and to not add too much overhead on save or confirm or whatever action you want to hook to.

@StefanRijnhart

Copy link
Copy Markdown
Member

Agreed. With the cron queuing the jobs, you can plan the load on your system.

@simahawk

simahawk commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 18.0-ocabot-merge-pr-3460-by-simahawk-bump-nobump, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Apr 2, 2025
Signed-off-by simahawk
@OCA-git-bot

Copy link
Copy Markdown
Contributor

@simahawk your merge command was aborted due to failed check(s), which you can inspect on this commit of 18.0-ocabot-merge-pr-3460-by-simahawk-bump-nobump.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

Guewen Baconnier and others added 8 commits April 2, 2025 14:12
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.

~

I needed to extract methods in `sale_automatic_workflow` in order
to be able to execute them as jobs.

A new decorator "job_auto_delay" (to eventually move in queue_job) makes
these methods automatically delayed when called.
OCA-git-bot and others added 17 commits April 2, 2025 14:12
Currently translated at 100.0% (8 of 8 strings)

Translation: sale-workflow-16.0/sale-workflow-16.0-sale_automatic_workflow_job
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_automatic_workflow_job/es/
Currently translated at 100.0% (8 of 8 strings)

Translation: sale-workflow-16.0/sale-workflow-16.0-sale_automatic_workflow_job
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_automatic_workflow_job/it/
Currently translated at 100.0% (8 of 8 strings)

Translation: sale-workflow-16.0/sale-workflow-16.0-sale_automatic_workflow_job
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_automatic_workflow_job/it/
@chaule97 chaule97 force-pushed the 18.0-mig-sale_automatic_workflow_job branch from c4d794a to c2fc43d Compare April 2, 2025 07:21
@chaule97 chaule97 force-pushed the 18.0-mig-sale_automatic_workflow_job branch from c2fc43d to 9893f3b Compare April 2, 2025 07:25
@chaule97

chaule97 commented Apr 2, 2025

Copy link
Copy Markdown
Contributor Author

Ciao @simahawk, can you review and merge again? I have found that module queue_job changed parameter _job_force_sync to queue_job__no_delay

@chaule97 chaule97 requested a review from simahawk April 7, 2025 04:44
@simahawk

simahawk commented Apr 7, 2025

Copy link
Copy Markdown
Contributor

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 18.0-ocabot-merge-pr-3460-by-simahawk-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 7905556 into OCA:18.0 Apr 7, 2025
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 4561ba4. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.