[IMP] : black, isort, prettier
parent
0bcdacb420
commit
fc38b430f9
|
@ -12,10 +12,7 @@
|
||||||
"depends": [
|
"depends": [
|
||||||
"web",
|
"web",
|
||||||
],
|
],
|
||||||
"data": [
|
"data": ["views/ir_actions_report.xml", "templates/assets.xml"],
|
||||||
"views/ir_actions_report.xml",
|
|
||||||
"templates/assets.xml"
|
|
||||||
],
|
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"maintainers": ["kittiu"],
|
"maintainers": ["kittiu"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
# Copyright 2020 Creu Blanca
|
# Copyright 2020 Creu Blanca
|
||||||
# Copyright 2020 Ecosoft Co., Ltd.
|
# Copyright 2020 Ecosoft Co., Ltd.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo.addons.web.controllers import main as report
|
|
||||||
from odoo.http import route, request
|
|
||||||
from werkzeug.urls import url_decode
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from werkzeug.urls import url_decode
|
||||||
|
|
||||||
|
from odoo.http import request, route
|
||||||
|
|
||||||
|
from odoo.addons.web.controllers import main as report
|
||||||
|
|
||||||
|
|
||||||
class ReportController(report.ReportController):
|
class ReportController(report.ReportController):
|
||||||
@route()
|
@route()
|
||||||
|
@ -17,9 +20,9 @@ class ReportController(report.ReportController):
|
||||||
requestcontent = json.loads(data)
|
requestcontent = json.loads(data)
|
||||||
url, ttype = requestcontent[0], requestcontent[1]
|
url, ttype = requestcontent[0], requestcontent[1]
|
||||||
if (
|
if (
|
||||||
ttype in ["qweb-pdf"] and
|
ttype in ["qweb-pdf"]
|
||||||
result.headers["Content-Type"] == "application/pdf" and
|
and result.headers["Content-Type"] == "application/pdf"
|
||||||
"?" in url
|
and "?" in url
|
||||||
):
|
):
|
||||||
url_data = dict(url_decode(url.split("?")[1]).items())
|
url_data = dict(url_decode(url.split("?")[1]).items())
|
||||||
if "context" in url_data:
|
if "context" in url_data:
|
||||||
|
@ -28,6 +31,7 @@ class ReportController(report.ReportController):
|
||||||
Report = request.env["ir.actions.report"]
|
Report = request.env["ir.actions.report"]
|
||||||
data = result.get_data()
|
data = result.get_data()
|
||||||
encrypted_data = Report._encrypt_pdf(
|
encrypted_data = Report._encrypt_pdf(
|
||||||
data, context["encrypt_password"])
|
data, context["encrypt_password"]
|
||||||
|
)
|
||||||
result.set_data(encrypted_data)
|
result.set_data(encrypted_data)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# Copyright 2020 Creu Blanca
|
# Copyright 2020 Creu Blanca
|
||||||
# Copyright 2020 Ecosoft Co., Ltd.
|
# Copyright 2020 Ecosoft Co., Ltd.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
from odoo import fields, models, _
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from odoo.tools.safe_eval import safe_eval
|
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
|
|
||||||
|
from odoo import _, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
|
@ -20,13 +20,12 @@ class IrActionsReport(models.Model):
|
||||||
_inherit = "ir.actions.report"
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
encrypt = fields.Selection(
|
encrypt = fields.Selection(
|
||||||
[("manual", "Manual Input Password"),
|
[("manual", "Manual Input Password"), ("auto", "Auto Generated Password")],
|
||||||
("auto", "Auto Generated Password")],
|
|
||||||
string="Encryption",
|
string="Encryption",
|
||||||
help="* Manual Input Password: allow user to key in password on the fly. "
|
help="* Manual Input Password: allow user to key in password on the fly. "
|
||||||
"This option available only on document print action.\n"
|
"This option available only on document print action.\n"
|
||||||
"* Auto Generated Password: system will auto encrypt password when PDF "
|
"* Auto Generated Password: system will auto encrypt password when PDF "
|
||||||
"created, based on provided python syntax."
|
"created, based on provided python syntax.",
|
||||||
)
|
)
|
||||||
encrypt_password = fields.Char(
|
encrypt_password = fields.Char(
|
||||||
help="Python code syntax to gnerate password.",
|
help="Python code syntax to gnerate password.",
|
||||||
|
@ -34,7 +33,8 @@ class IrActionsReport(models.Model):
|
||||||
|
|
||||||
def render_qweb_pdf(self, res_ids=None, data=None):
|
def render_qweb_pdf(self, res_ids=None, data=None):
|
||||||
document, ttype = super(IrActionsReport, self).render_qweb_pdf(
|
document, ttype = super(IrActionsReport, self).render_qweb_pdf(
|
||||||
res_ids=res_ids, data=data)
|
res_ids=res_ids, data=data
|
||||||
|
)
|
||||||
password = self._get_pdf_password(res_ids[:1])
|
password = self._get_pdf_password(res_ids[:1])
|
||||||
document = self._encrypt_pdf(document, password)
|
document = self._encrypt_pdf(document, password)
|
||||||
return document, ttype
|
return document, ttype
|
||||||
|
@ -51,12 +51,14 @@ class IrActionsReport(models.Model):
|
||||||
elif self.encrypt == "auto" and self.encrypt_password:
|
elif self.encrypt == "auto" and self.encrypt_password:
|
||||||
obj = self.env[self.model].browse(res_id)
|
obj = self.env[self.model].browse(res_id)
|
||||||
try:
|
try:
|
||||||
encrypt_password = safe_eval(self.encrypt_password,
|
encrypt_password = safe_eval(
|
||||||
{'object': obj, 'time': time})
|
self.encrypt_password, {"object": obj, "time": time}
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Python code used for encryption password is invalid.\n%s")
|
_("Python code used for encryption password is invalid.\n%s")
|
||||||
% self.encrypt_password)
|
% self.encrypt_password
|
||||||
|
)
|
||||||
return encrypt_password
|
return encrypt_password
|
||||||
|
|
||||||
def _encrypt_pdf(self, data, password):
|
def _encrypt_pdf(self, data, password):
|
||||||
|
|
|
@ -6,77 +6,91 @@ odoo.define("report_qweb_encrypt.Dialog", function (require) {
|
||||||
var ActionManager = require("web.ActionManager");
|
var ActionManager = require("web.ActionManager");
|
||||||
var framework = require("web.framework");
|
var framework = require("web.framework");
|
||||||
var Dialog = require("web.Dialog");
|
var Dialog = require("web.Dialog");
|
||||||
var core = require('web.core');
|
var core = require("web.core");
|
||||||
|
|
||||||
var _t = core._t;
|
var _t = core._t;
|
||||||
|
|
||||||
var EncryptDialog = Dialog.extend({
|
var EncryptDialog = Dialog.extend({
|
||||||
events: _.extend({}, Dialog.prototype.events, {
|
events: _.extend({}, Dialog.prototype.events, {
|
||||||
change: '_onChange',
|
change: "_onChange",
|
||||||
}),
|
}),
|
||||||
_setValue: function () {
|
_setValue: function () {
|
||||||
this.value = this.$el.find('.o_password').val()
|
this.value = this.$el.find(".o_password").val();
|
||||||
},
|
},
|
||||||
_onChange: function (event) {
|
_onChange: function (event) {
|
||||||
this._setValue();
|
this._setValue();
|
||||||
},
|
},
|
||||||
|
});
|
||||||
})
|
|
||||||
EncryptDialog.askPassword = function (owner, action, action_options, options) {
|
EncryptDialog.askPassword = function (owner, action, action_options, options) {
|
||||||
var buttons = [
|
var buttons = [
|
||||||
{
|
{
|
||||||
text: _t("Ok"),
|
text: _t("Ok"),
|
||||||
classes: 'btn-primary',
|
classes: "btn-primary",
|
||||||
close: true,
|
close: true,
|
||||||
click: function (event) {
|
click: function (event) {
|
||||||
var password = this.value || false;
|
var password = this.value || false;
|
||||||
owner._executeReportAction(action, action_options, password)
|
owner._executeReportAction(action, action_options, password);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: _t("Cancel"),
|
text: _t("Cancel"),
|
||||||
close: true,
|
close: true,
|
||||||
click: false,
|
click: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
return new EncryptDialog(owner, _.extend({
|
return new EncryptDialog(
|
||||||
size: 'small',
|
owner,
|
||||||
|
_.extend(
|
||||||
|
{
|
||||||
|
size: "small",
|
||||||
buttons: buttons,
|
buttons: buttons,
|
||||||
$content: $('<div><input class="o_password" type="password"/></div>'),
|
$content: $(
|
||||||
|
'<div><input class="o_password" type="password"/></div>'
|
||||||
|
),
|
||||||
title: _t("Encrypt"),
|
title: _t("Encrypt"),
|
||||||
}, options)).open();
|
},
|
||||||
|
options
|
||||||
|
)
|
||||||
|
).open();
|
||||||
};
|
};
|
||||||
|
|
||||||
ActionManager.include({
|
ActionManager.include({
|
||||||
_executeReportAction: function (action, options, password) {
|
_executeReportAction: function (action, options, password) {
|
||||||
if (action.encrypt === 'manual'
|
if (
|
||||||
&& action.report_type === 'qweb-pdf'
|
action.encrypt === "manual" &&
|
||||||
&& password === undefined) {
|
action.report_type === "qweb-pdf" &&
|
||||||
|
password === undefined
|
||||||
|
) {
|
||||||
EncryptDialog.askPassword(this, action, options);
|
EncryptDialog.askPassword(this, action, options);
|
||||||
return $.Deferred();
|
return $.Deferred();
|
||||||
}
|
} else if (action.encrypt === "manual") {
|
||||||
else if (action.encrypt === 'manual') {
|
|
||||||
action.context = _.extend({}, action.context, {
|
action.context = _.extend({}, action.context, {
|
||||||
encrypt_password: password,
|
encrypt_password: password,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return this._super(action, options, password)
|
return this._super(action, options, password);
|
||||||
},
|
},
|
||||||
_makeReportUrls: function (action) {
|
_makeReportUrls: function (action) {
|
||||||
var reportUrls = this._super.apply(this, arguments);
|
var reportUrls = this._super.apply(this, arguments);
|
||||||
if (action.encrypt === 'manual' && action.context.encrypt_password) {
|
if (action.encrypt === "manual" && action.context.encrypt_password) {
|
||||||
if (_.isUndefined(action.data) || _.isNull(action.data) ||
|
if (
|
||||||
(_.isObject(action.data) && _.isEmpty(action.data))) {
|
_.isUndefined(action.data) ||
|
||||||
var serializedOptionsPath = '?context=' + encodeURIComponent(JSON.stringify({
|
_.isNull(action.data) ||
|
||||||
|
(_.isObject(action.data) && _.isEmpty(action.data))
|
||||||
|
) {
|
||||||
|
var serializedOptionsPath =
|
||||||
|
"?context=" +
|
||||||
|
encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
encrypt_password: action.context.encrypt_password,
|
encrypt_password: action.context.encrypt_password,
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
reportUrls = _.mapObject(reportUrls, function (value) {
|
reportUrls = _.mapObject(reportUrls, function (value) {
|
||||||
return value += serializedOptionsPath;
|
return (value += serializedOptionsPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reportUrls;
|
return reportUrls;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,10 @@
|
||||||
-->
|
-->
|
||||||
<template id="assets_backend" inherit_id="web.assets_backend">
|
<template id="assets_backend" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/report_qweb_encrypt/static/src/js/report/action_manager_report.js"/>
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/report_qweb_encrypt/static/src/js/report/action_manager_report.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -5,7 +5,6 @@ from odoo.tests.common import HttpCase
|
||||||
|
|
||||||
|
|
||||||
class TestReportQwebEncrypt(HttpCase):
|
class TestReportQwebEncrypt(HttpCase):
|
||||||
|
|
||||||
def test_report_qweb_no_encrypt(self):
|
def test_report_qweb_no_encrypt(self):
|
||||||
ctx = {"force_report_rendering": True}
|
ctx = {"force_report_rendering": True}
|
||||||
report = self.env.ref("web.action_report_internalpreview")
|
report = self.env.ref("web.action_report_internalpreview")
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<!-- Copyright 2020 Creu Blanca
|
<!-- Copyright 2020 Creu Blanca
|
||||||
Copyright 2020 Ecosoft Co., LTd.
|
Copyright 2020 Ecosoft Co., LTd.
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="ir_actions_report_form_view">
|
<record model="ir.ui.view" id="ir_actions_report_form_view">
|
||||||
|
@ -11,12 +10,20 @@
|
||||||
<field name="inherit_id" ref="base.act_report_xml_view" />
|
<field name="inherit_id" ref="base.act_report_xml_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="paperformat_id" position="after">
|
<field name="paperformat_id" position="after">
|
||||||
<label for="encrypt" attrs="{'invisible': [('report_type', 'not in', ('qweb-pdf', 'qweb-html'))]}"/>
|
<label
|
||||||
<div name="encrypt" attrs="{'invisible': [('report_type', 'not in', ('qweb-pdf', 'qweb-html'))]}">
|
for="encrypt"
|
||||||
|
attrs="{'invisible': [('report_type', 'not in', ('qweb-pdf', 'qweb-html'))]}"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
name="encrypt"
|
||||||
|
attrs="{'invisible': [('report_type', 'not in', ('qweb-pdf', 'qweb-html'))]}"
|
||||||
|
>
|
||||||
<field name="encrypt" />
|
<field name="encrypt" />
|
||||||
<field name="encrypt_password"
|
<field
|
||||||
|
name="encrypt_password"
|
||||||
attrs="{'invisible': [('encrypt', '!=', 'auto')]}"
|
attrs="{'invisible': [('encrypt', '!=', 'auto')]}"
|
||||||
placeholder="python syntax, i.e., (object.default_code or 'secretcode')"/>
|
placeholder="python syntax, i.e., (object.default_code or 'secretcode')"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
|
|
Loading…
Reference in New Issue