Skip to content

Commit

Permalink
[MIG] : Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cvinh committed Oct 12, 2022
1 parent 9fbb548 commit a9c61b9
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 56 deletions.
2 changes: 1 addition & 1 deletion report_fillpdf/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Creu Blanca," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"category": "Reporting",
"version": "11.0.1.0.1",
"version": "14.0.1.0.1",
"license": "AGPL-3",
"external_dependencies": {
"python": [
Expand Down
4 changes: 3 additions & 1 deletion report_fillpdf/models/ir_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
class ReportAction(models.Model):
_inherit = "ir.actions.report"

report_type = fields.Selection(selection_add=[("fillpdf", "PDF Filler")])
report_type = fields.Selection(
selection_add=[("fillpdf", "PDF Filler")], ondelete={"fillpdf": "set default"}
)

@api.model
def render_fillpdf(self, docids, data):
Expand Down
2 changes: 1 addition & 1 deletion report_fillpdf/report/report_fill_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_document_values(self, data, objs):
@api.model
def fill_pdf_form(self, form, vals):
fdf = forge_fdf("", vals.items(), [], [], [])
document_fd, document_path = tempfile.mkstemp(suffix=".pdf", prefix="")
document_fd, document_path = tempfile.mkstemp(suffix=".pdf", prefix="", dir=".")
with closing(os.fdopen(document_fd, "wb")) as body_file:
body_file.write(form)
args = [
Expand Down
98 changes: 98 additions & 0 deletions report_fillpdf/static/src/js/report/action_manager_report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// © 2017 Creu Blanca
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
odoo.define("report_fillpdf.report", function (require) {
"use strict";

var core = require("web.core");
var ActionManager = require("web.ActionManager");
var framework = require("web.framework");
var session = require("web.session");
var _t = core._t;

ActionManager.include({
_downloadReportfillpdf: function (url, actions) {
var self = this;
framework.blockUI();
var type = "fillpdf";
var cloned_action = _.clone(actions);
var new_url = url;

if (
_.isUndefined(cloned_action.data) ||
_.isNull(cloned_action.data) ||
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data))
) {
if (cloned_action.context.active_ids) {
new_url += "/" + cloned_action.context.active_ids.join(",");
}
} else {
new_url +=
"?options=" +
encodeURIComponent(JSON.stringify(cloned_action.data));
new_url +=
"&context=" +
encodeURIComponent(JSON.stringify(cloned_action.context));
}

return new Promise(function (resolve, reject) {
var blocked = !session.get_file({
url: new_url,
data: {
data: JSON.stringify([new_url, type]),
},
success: resolve,
error: (error) => {
self.call("crash_manager", "rpc_error", error);
reject();
},
complete: framework.unblockUI,
});
if (blocked) {
// AAB: this check should be done in get_file service directly,
// should not be the concern of the caller (and that way, get_file
// could return a deferred)
var message = _t(
"A popup window with your report was blocked. You " +
"may need to change your browser settings to allow " +
"popup windows for this page."
);
this.do_warn(_t("Warning"), message, true);
}
});
},

_triggerDownload: function (action, options, type) {
var self = this;
var reportUrls = this._makeReportUrls(action);
if (type === "fillpdf") {
return this._downloadReportfillpdf(reportUrls[type], action).then(
function () {
if (action.close_on_report_download) {
var closeAction = {type: "ir.actions.act_window_close"};
return self.doAction(
closeAction,
_.pick(options, "on_close")
);
}
return options.on_close();
}
);
}
return this._super.apply(this, arguments);
},

_makeReportUrls: function (action) {
var reportUrls = this._super.apply(this, arguments);
reportUrls.fillpdf = "/report/fillpdf/" + action.report_name;
return reportUrls;
},

_executeReportAction: function (action, options) {
var self = this;
if (action.report_type === "fillpdf") {
return self._triggerDownload(action, options, "fillpdf");
}
return this._super.apply(this, arguments);
},
});
});
49 changes: 0 additions & 49 deletions report_fillpdf/static/src/js/report/qwebactionmanager.js

This file was deleted.

3 changes: 1 addition & 2 deletions report_fillpdf/views/webclient_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/report_fillpdf/static/src/js/report/qwebactionmanager.js"
src="/report_fillpdf/static/src/js/report/action_manager_report.js"
/>
</xpath>

</template>
</odoo>
2 changes: 0 additions & 2 deletions setup/report_fillpdf/setup.cfg

This file was deleted.

0 comments on commit a9c61b9

Please sign in to comment.