From cd5fed9ac70a7bea74085fdf4d33348dbda54983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Vi=20Or?= Date: Thu, 16 Feb 2023 18:07:11 +0100 Subject: [PATCH 1/2] [IMP] report_async: Add schedule time to decide queue eta when async reporting --- report_async/models/ir_report.py | 26 ++++++++++++-------------- report_async/models/report_async.py | 13 +++++++++++++ report_async/views/report_async.xml | 2 ++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/report_async/models/ir_report.py b/report_async/models/ir_report.py index e70988bdd8..ad8df751f8 100644 --- a/report_async/models/ir_report.py +++ b/report_async/models/ir_report.py @@ -3,26 +3,24 @@ from odoo import api, models - # Define all supported report_type -REPORT_TYPES = ['qweb-pdf', 'qweb-text', - 'qweb-xml', 'csv', - 'excel', 'xlsx'] +REPORT_TYPES = ["qweb-pdf", "qweb-text", "qweb-xml", "csv", "excel", "xlsx"] class Report(models.Model): - _inherit = 'ir.actions.report' + _inherit = "ir.actions.report" @api.noguess def report_action(self, docids, data=None, config=True): - res = super(Report, self).report_action(docids, data=data, - config=config) - if res['context'].get('async_process', False): - rpt_async_id = res['context']['active_id'] - report_async = self.env['report.async'].browse(rpt_async_id) - if res['report_type'] in REPORT_TYPES: - report_async.with_delay().run_report( - res['context'].get('active_ids', []), data, - self.id, self._uid) + res = super(Report, self).report_action(docids, data=data, config=config) + if res["context"].get("async_process", False): + rpt_async_id = res["context"]["active_id"] + report_async = self.env["report.async"].browse(rpt_async_id) + if res["report_type"] in REPORT_TYPES: + report_async.with_delay( + eta=res["context"].get("eta", False) + ).run_report( + res["context"].get("active_ids", []), data, self.id, self._uid + ) return {} return res diff --git a/report_async/models/report_async.py b/report_async/models/report_async.py index 376acc71c2..b5925abc53 100644 --- a/report_async/models/report_async.py +++ b/report_async/models/report_async.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) import base64 +from datetime import datetime, timedelta from odoo import api, fields, models, _ from odoo.tools.safe_eval import safe_eval from odoo.exceptions import UserError @@ -70,6 +71,8 @@ class ReportAsync(models.Model): help="List all files created by this report background process", ) + schedule_time = fields.Char(string='Schedule time') + @api.multi def _compute_job(self): for rec in self: @@ -110,6 +113,8 @@ def run_async(self): result = action.read()[0] ctx = safe_eval(result.get('context', {})) ctx.update({'async_process': True}) + if self.schedule_time: + ctx.update({'eta': self._get_next_schedule_time()}) result['context'] = ctx return result @@ -160,3 +165,11 @@ def _send_email(self, attachment): template.send_mail(attachment.id, notif_layout='mail.mail_notification_light', force_send=False) + + def _get_next_schedule_time(self): + target_time = datetime.strptime(self.schedule_time, "%H:%M").time() + now = fields.Datetime.now() + target_datetime = datetime.combine(now.date(), target_time) + if now.time() > target_time: + target_datetime += timedelta(days=1) + return target_datetime diff --git a/report_async/views/report_async.xml b/report_async/views/report_async.xml index f6d5f58f14..cbf6deaff0 100644 --- a/report_async/views/report_async.xml +++ b/report_async/views/report_async.xml @@ -73,6 +73,8 @@ + Date: Mon, 21 Aug 2023 12:38:26 +0200 Subject: [PATCH 2/2] [UPD] copier --- .copier-answers.yml | 3 ++- .github/workflows/pre-commit.yml | 2 +- .github/workflows/test.yml | 8 +++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 3eaec745a8..fa5101156b 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Do NOT update manually; changes here will be overwritten by Copier -_commit: v1.14.2 +_commit: v1.15.0 _src_path: https://github.com/OCA/oca-addons-repo-template.git ci: GitHub dependency_installation_mode: PIP @@ -11,6 +11,7 @@ github_enable_makepot: true github_enable_stale_action: true github_enforce_dev_status_compatibility: true include_wkhtmltopdf: false +odoo_test_flavor: OCB odoo_version: 12.0 org_name: Odoo Community Association (OCA) org_slug: OCA diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index f86d418269..6d54b60f45 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,7 +13,7 @@ jobs: pre-commit: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-python@v2 with: python-version: "3.6" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20bf055d40..ba6443d81e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest name: Detect unreleased dependencies steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: | for reqfile in requirements.txt test-requirements.txt ; do if [ -f ${reqfile} ] ; then @@ -35,11 +35,9 @@ jobs: fail-fast: false matrix: include: - - container: ghcr.io/oca/oca-ci/py3.6-odoo12.0:latest - makepot: "true" - name: test with Odoo - container: ghcr.io/oca/oca-ci/py3.6-ocb12.0:latest name: test with OCB + makepot: "true" services: postgres: image: postgres:9.6 @@ -50,7 +48,7 @@ jobs: ports: - 5432:5432 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: persist-credentials: false - name: Install addons and dependencies