mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[FIX] support for attachment to record
This commit is contained in:
@@ -144,7 +144,8 @@ class ReportAsync(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def print_document_async(
|
def print_document_async(
|
||||||
self, record_ids, report_name, html=None, data=None, to_email=""
|
self, record_ids, report_name, html=None, data=None, to_email="",
|
||||||
|
save_attachment_to_records=False
|
||||||
):
|
):
|
||||||
"""Generate a document async, do not return the document file"""
|
"""Generate a document async, do not return the document file"""
|
||||||
user_email = to_email or self.env.user.email
|
user_email = to_email or self.env.user.email
|
||||||
@@ -157,6 +158,7 @@ class ReportAsync(models.Model):
|
|||||||
email_notify=True,
|
email_notify=True,
|
||||||
to_email=user_email,
|
to_email=user_email,
|
||||||
session_id=request.session.sid,
|
session_id=request.session.sid,
|
||||||
|
save_attachment_to_records=save_attachment_to_records
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -169,6 +171,7 @@ class ReportAsync(models.Model):
|
|||||||
email_notify=False,
|
email_notify=False,
|
||||||
to_email=None,
|
to_email=None,
|
||||||
session_id=None,
|
session_id=None,
|
||||||
|
save_attachment_to_records=False
|
||||||
):
|
):
|
||||||
report = self.env["ir.actions.report"].browse(report_id)
|
report = self.env["ir.actions.report"].browse(report_id)
|
||||||
func = REPORT_TYPES_FUNC[report.report_type]
|
func = REPORT_TYPES_FUNC[report.report_type]
|
||||||
@@ -199,6 +202,22 @@ class ReportAsync(models.Model):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# save attachment to records
|
||||||
|
if save_attachment_to_records:
|
||||||
|
model = report.model
|
||||||
|
records = self.env[model].browse(docids)
|
||||||
|
for record in records:
|
||||||
|
attachment = self.env["ir.attachment"].sudo().create(
|
||||||
|
{
|
||||||
|
"name": out_name,
|
||||||
|
"datas": out_file,
|
||||||
|
"type": "binary",
|
||||||
|
"res_model": model,
|
||||||
|
"res_id": record.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if hasattr(record, 'message_post'):
|
||||||
|
record.message_post(attachment_ids=[attachment.id])
|
||||||
self._cr.execute(
|
self._cr.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE ir_attachment SET create_uid = %s, write_uid = %s
|
UPDATE ir_attachment SET create_uid = %s, write_uid = %s
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ odoo.define("report_async.ActionMenus", function (require) {
|
|||||||
const is_report_async = this.$(
|
const is_report_async = this.$(
|
||||||
"#async_report_checker"
|
"#async_report_checker"
|
||||||
).prop("checked");
|
).prop("checked");
|
||||||
|
const save_report_attachment = this.$(
|
||||||
|
"#async-save-report-checker"
|
||||||
|
).prop("checked");
|
||||||
const user_email = this.$("#async-user-email").val();
|
const user_email = this.$("#async-user-email").val();
|
||||||
if (user_email !== "" && is_report_async) {
|
if (user_email !== "" && is_report_async) {
|
||||||
// Try basic email validation
|
// Try basic email validation
|
||||||
@@ -64,6 +67,7 @@ odoo.define("report_async.ActionMenus", function (require) {
|
|||||||
to_email: user_email,
|
to_email: user_email,
|
||||||
data: action.data || {},
|
data: action.data || {},
|
||||||
context: action.context || {},
|
context: action.context || {},
|
||||||
|
save_attachment_to_records: save_report_attachment
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@@ -20,6 +20,26 @@
|
|||||||
via queue job and sent to a below email address.
|
via queue job and sent to a below email address.
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Allow saving of attachment to record -->
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-check">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="form-check-input"
|
||||||
|
checked="checked"
|
||||||
|
id="async-save-report-checker"
|
||||||
|
/>
|
||||||
|
<label class="form-check-label"
|
||||||
|
for="async-save-report-checker">
|
||||||
|
Save attachment to records
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<small id="async-save-report-checker-help"
|
||||||
|
class="form-text text-muted">
|
||||||
|
Checker enables async report attachment to be created and
|
||||||
|
saved to the records. NB: Records should support attachments
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
<!-- Email Input -->
|
<!-- Email Input -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="async-user-email">Email Address</label>
|
<label for="async-user-email">Email Address</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user