From 99ae369d69b602f268442c251b335c4ca60d79ed Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Aug 2024 12:50:13 +0200 Subject: [PATCH] [FIX] runbot_merge: update freeze wizard widget for 17.0 It was all borken and the web client couldn't even load. The logic is basically the same, except the new client doesn't support forcing onchanges maybe, so we need to `read()` the entire thing if the form is not modified. --- runbot_merge/__manifest__.py | 2 +- runbot_merge/static/project_freeze/index.js | 62 ------------------- .../static/src/project_freeze/index.js | 36 +++++++++++ 3 files changed, 37 insertions(+), 63 deletions(-) delete mode 100644 runbot_merge/static/project_freeze/index.js create mode 100644 runbot_merge/static/src/project_freeze/index.js diff --git a/runbot_merge/__manifest__.py b/runbot_merge/__manifest__.py index a21ce712..3dba6c95 100644 --- a/runbot_merge/__manifest__.py +++ b/runbot_merge/__manifest__.py @@ -26,7 +26,7 @@ ], 'web.assets_backend': [ 'runbot_merge/static/scss/runbot_merge_backend.scss', - 'runbot_merge/static/project_freeze/index.js', + 'runbot_merge/static/src/project_freeze/index.js', ], }, 'post_load': 'enable_sentry', diff --git a/runbot_merge/static/project_freeze/index.js b/runbot_merge/static/project_freeze/index.js deleted file mode 100644 index a0568962..00000000 --- a/runbot_merge/static/project_freeze/index.js +++ /dev/null @@ -1,62 +0,0 @@ -odoo.define('runbot_merge.index', function (require) { -"use strict"; -const FormController = require('web.FormController'); -const FormView = require('web.FormView'); -const viewRegistry = require('web.view_registry'); - -/** - * Attept at a "smart" controller for the freeze wizard: keeps triggering - * onchange() on the form in order to try and update the error information, as - * some of the "errors" are not under direct operator control. Hopefully this - * allows the operator to just keep the wizard open and wait until the error - * messages disappear so they can proceed. - */ -const FreezeController = FormController.extend({ - async _checkState() { - const record = this.model.get(this.handle) - const requiredPrIds = record.data.required_pr_ids; - - // we're inside the form's mutex, so can use `_applyChange` directly - const changed = await this.model._applyChange(this.handle, { - required_pr_ids: { - operation: 'REPLACE_WITH', - ids: requiredPrIds.res_ids, - } - }); - // not sure why we need to wait for the round *after* the error update - // notification, but even debouncing the rest of the method is not - // sufficient (so it's not just a problem of being behind the mutex, - // there's something wonky going on) - if (!this._updateNext) { - this._updateNext = changed.includes('errors'); - return; - } - - this._updateNext = false; - for(const p of requiredPrIds.data) { - this.renderer.updateState(p.id, {fieldNames: ['state_color']}); - } - this.renderer.updateState(record, {fieldNames: ['errors', 'required_pr_ids']}); - }, - /** - * @override - */ - async start(...args) { - const checker = async () => { - if (this.isDestroyed()) { return; } - await this.model.mutex.exec(() => this._checkState()); - setTimeout(checker, 1000); - }; - const started = await this._super(...args); - const _ = checker(); - return started; - }, -}); - -viewRegistry.add('freeze_wizard', FormView.extend({ - config: Object.assign({}, FormView.prototype.config, { - Controller: FreezeController, - }) -})); -}); - diff --git a/runbot_merge/static/src/project_freeze/index.js b/runbot_merge/static/src/project_freeze/index.js new file mode 100644 index 00000000..8dca49bc --- /dev/null +++ b/runbot_merge/static/src/project_freeze/index.js @@ -0,0 +1,36 @@ +/** @odoo-module */ + +import {useEffect} from "@odoo/owl"; +import {x2ManyCommands} from "@web/core/orm_service"; +import {registry} from "@web/core/registry"; +import {FormController} from "@web/views/form/form_controller"; +import {formView} from "@web/views/form/form_view"; + +class FreezeController extends FormController { + setup() { + super.setup(); + + useEffect(() => { + const interval = setInterval(async () => { + const root = this.model.root; + if (await root.isDirty()) { + root.update({ + required_pr_ids: x2ManyCommands.set( + root.data.required_pr_ids.currentIds, + ), + }); + } else { + root.load(); + } + }, 1000); + return () => { + clearInterval(interval); + }; + }, () => []); + } +} + +registry.category("views").add('freeze_wizard', { + ...formView, + Controller: FreezeController, +});