Skip to content

Commit

Permalink
[FIX] 2665 popup wizard for async
Browse files Browse the repository at this point in the history
  • Loading branch information
KKamaa committed Mar 13, 2022
1 parent edd56b9 commit d53a28c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 33 deletions.
5 changes: 4 additions & 1 deletion report_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"views/assets.xml",
"views/ir_actions_report_xml.xml",
"views/report_async.xml",
"wizard/print_report_wizard.xml",
"wizard/print_report_wizard.xml"
],
'qweb': [
'static/src/xml/report_async.xml'
],
"demo": ["demo/report_async_demo.xml"],
"installable": True,
Expand Down
6 changes: 4 additions & 2 deletions report_async/models/report_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ def view_jobs(self):
return result

@api.model
def print_document_async(self, record_ids, report_name, html=None, data=None):
def print_document_async(self, record_ids, report_name, html=None,
data=None, to_email=''):
""" Generate a document async, do not return the document file """
user_email = to_email or self.env.user.email
report = self.env['report']._get_report_from_name(report_name)
self.with_delay().run_report(
record_ids, data or {}, report.id, self._uid, email_notify=True,
to_email=self.env.user.email, session_id=request.session.sid
to_email=user_email, session_id=request.session.sid
)

@api.model
Expand Down
94 changes: 64 additions & 30 deletions report_async/static/src/js/qweb_action_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,78 @@ odoo.define('report_async.print', function(require) {
var core = require('web.core');
var framework = require('web.framework');
var Model = require('web.Model');
var Dialog = require('web.Dialog');

var _t = core._t;
var QWeb = core.qweb;

ActionManager.include({
ir_actions_report_xml: function(action, options) {
var _action = _.clone(action);
var _t = core._t;
var self = this;
var _super = this._super;
var _action = _.clone(action);
var $content = $(QWeb.render("ReportAsyncConfiguration", {}));

if ('report_type' in _action && _action.report_type === 'qweb-pdf') {
framework.blockUI();
new Model('ir.actions.report.xml')
.call('is_report_async', [_action.report_name])
.then(function(result){
if (result.is_report_async) {
framework.unblockUI();
new Model('report.async')
.call('print_document_async',
[_action.context.active_ids,
_action.report_name,
],
{data: _action.data || {},
context: _action.context || {},
})
.then(function(){
self.do_notify(_t('Report'),
_t('Job started to generate report. Upon completion, mail sent to:') + result.mail_recipient);
}).fail(function() {
self.do_notify(_t('Report'),
_t('Failed, error on job creation.'));

});
} else {
return _super.apply(self, [_action, options]);
// Popup for async Configuration
new Dialog(self, {
title: _t("Async Report Configuration ") + '(' + action['display_name'] + ')',
size : "medium",
buttons: [{
text: _t("Print"),
classes: 'btn-primary',
close: true,
click: function () {
var is_report_async = this.$('#async_report_checker')
.prop('checked');
var user_email = this.$('#async-user-email').val();
if (user_email !== '' && is_report_async) {
// Try basic email validation
if (self._validate_email(user_email)) {
if ('report_type' in _action && _action.report_type === 'qweb-pdf') {
framework.unblockUI();
// Generate report async
new Model('report.async').call('print_document_async',
[_action.context.active_ids, _action.report_name],
{
to_email: user_email,
data: _action.data || {},
context: _action.context || {},
}).then(function() {
self.do_notify(_t('Report'),
_t('Job started to generate report. Upon ' +
'completion, mail sent to:') +
user_email, true);
}).fail(function() {
self.do_notify(_t('Report'),
_t('Failed, error on job creation.'), true);
});
}
else {
// default to normal approach to generate report
return _super.apply(self, [action, options]);
}
}
}
else {
// default to normal approach to generate report
return _super.apply(self, [action, options]);
}
});
} else {
return _super.apply(self, [_action, options]);
}},
{
text: _t("Discard"),
close: true
}],
$content: $content,
}).open();
},
_validate_email: function (email) {
var res = email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
if (!res) {
return this.do_notify(_("Email Validation Error"),
_("Please check your email syntax and try again"), true);
}
return true;
}
});
});
30 changes: 30 additions & 0 deletions report_async/static/src/xml/report_async.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>
<t t-name='ReportAsyncConfiguration'>
<div class="form">
<div class="form-group">
<label for="async-user-email">Email Address</label>
<input type="email" class="form-control" id="async-user-email"
aria-describedby="emailHelp"
placeholder="[email protected]"/>
<small id="async-user-email-help" class="form-text text-muted">
Email will be used to send the report after queue job is
done on the background
</small>
</div>
<div class="form-group">
<div class="form-check">
<input type="checkbox" class="form-check-input"
id="async_report_checker"/>
<label class="form-check-label" for="async_report_checker">
Async Report
</label>
</div>
<small id="async-report-checker-help" class="form-text text-muted">
Check enables async report to be created on the background
via queue job and sent to a valid email.
</small>
</div>
</div>
</t>
</templates>

0 comments on commit d53a28c

Please sign in to comment.