From 6ac4998ff204dbf52249a458663d353e55833327 Mon Sep 17 00:00:00 2001 From: PauBForgeFlow Date: Fri, 23 Feb 2024 12:02:35 +0100 Subject: [PATCH] [IMP] sign_oca: preview requests --- sign_oca/models/sign_oca_request.py | 13 +++++ .../sign_oca_pdf_common_action.js | 48 +++++++++++++++++++ sign_oca/templates/assets.xml | 4 ++ sign_oca/views/sign_oca_request.xml | 2 + 4 files changed, 67 insertions(+) create mode 100644 sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common_action.js diff --git a/sign_oca/models/sign_oca_request.py b/sign_oca/models/sign_oca_request.py index cf7bc16b..9da9e673 100644 --- a/sign_oca/models/sign_oca_request.py +++ b/sign_oca/models/sign_oca_request.py @@ -76,6 +76,19 @@ def _compute_next_item_id(self): record.signatory_data and max(record.signatory_data.keys()) or 0 ) + 1 + def preview(self): + self.ensure_one() + self._set_action_log("view") + return { + "type": "ir.actions.client", + "tag": "sign_oca_preview", + "name": self.name, + "params": { + "res_model": self._name, + "res_id": self.id, + }, + } + def get_info(self): self.ensure_one() return { diff --git a/sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common_action.js b/sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common_action.js new file mode 100644 index 00000000..53235c7e --- /dev/null +++ b/sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common_action.js @@ -0,0 +1,48 @@ +odoo.define( + "sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common_action.js", + function (require) { + "use strict"; + + const {ComponentWrapper} = require("web.OwlCompatibility"); + const AbstractAction = require("web.AbstractAction"); + const core = require("web.core"); + const SignOcaPdfCommon = require("sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common.js"); + + const SignOcaPdfCommonAction = AbstractAction.extend({ + hasControlPanel: true, + init: function (parent, action) { + this._super.apply(this, arguments); + this.model = + (action.params.res_model !== undefined && + action.params.res_model) || + action.context.params.res_model; + this.res_id = + (action.params.res_id !== undefined && action.params.res_id) || + action.context.params.id; + }, + async start() { + await this._super(...arguments); + this.component = new ComponentWrapper(this, SignOcaPdfCommon, { + model: this.model, + res_id: this.res_id, + }); + this.$el.addClass("o_sign_oca_action"); + return this.component.mount(this.$(".o_content")[0]); + }, + getState: function () { + var result = this._super(...arguments); + result = _.extend({}, result, { + res_model: this.model, + res_id: this.res_id, + }); + return result; + }, + }); + + core.action_registry.add("sign_oca_preview", SignOcaPdfCommonAction); + + return { + SignOcaPdfCommonAction, + }; + } +); diff --git a/sign_oca/templates/assets.xml b/sign_oca/templates/assets.xml index d1d7f41d..7bd7eda4 100644 --- a/sign_oca/templates/assets.xml +++ b/sign_oca/templates/assets.xml @@ -11,6 +11,10 @@ type="text/javascript" src="/sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common.js" /> +