[FIX] point_of_sale,account: use Send & Print to generate pdfs
When a customer requests an invoice in the `point_of_sale`, use the same flow as in `account`: the "Send & Print" button. It generates the pdf, the EDI attachments (Factur-X, Peppol Bis 3, etc) and send it to the customers/governement. Indeed, in some countries, it is required to sign the invoice to the government upon validation (e.g. CFDI in Mexico). closes odoo/odoo#131317 X-original-commit: 2cc9a35860b59063f536eea9234a1e9c5fa2f00e Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -4322,6 +4322,15 @@ class AccountMove(models.Model):
|
||||
# from_cron=True to log errors in chatter instead of raise
|
||||
composer.action_send_and_print(from_cron=from_cron, allow_fallback_pdf=allow_fallback_pdf)
|
||||
|
||||
def generate_pdf_and_send_invoice(self):
|
||||
""" Calls `_generate_pdf_and_send_invoice` and returns the (pdf, filename)"""
|
||||
template = self.env.ref(self._get_mail_template())
|
||||
self.with_context(skip_invoice_sync=True)._generate_pdf_and_send_invoice(template)
|
||||
if len(self) < 2:
|
||||
return self.invoice_pdf_report_id.raw, self.invoice_pdf_report_id.name
|
||||
else:
|
||||
return self.env['ir.actions.report']._render('account.account_invoices', self.ids)[0], "Invoices.pdf"
|
||||
|
||||
def _get_invoice_pdf_report_filename(self):
|
||||
""" Get the filename of the generated PDF invoice report. """
|
||||
self.ensure_one()
|
||||
|
||||
@@ -1,27 +1,45 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { downloadFile } from "@web/core/network/download";
|
||||
import { downloadReport } from "@web/webclient/actions/reports/utils";
|
||||
|
||||
export const reportService = {
|
||||
dependencies: ["rpc", "user", "ui"],
|
||||
start(env, { rpc, user, ui }) {
|
||||
dependencies: ["rpc", "user", "ui", "orm"],
|
||||
start(env, { rpc, user, ui, orm }) {
|
||||
const reportActionsCache = {};
|
||||
return {
|
||||
async download(reportXmlId, active_ids) {
|
||||
ui.block();
|
||||
try {
|
||||
reportActionsCache[reportXmlId] ||= rpc("/web/action/load", {
|
||||
if (reportXmlId === "account.account_invoices"){
|
||||
// Send and Print the invoices
|
||||
let [pdf, filename] = await orm.call(
|
||||
"account.move",
|
||||
"generate_pdf_and_send_invoice",
|
||||
[active_ids],
|
||||
);
|
||||
// Convert pdf to a Blob
|
||||
const byteArray = new Uint8Array(pdf.length);
|
||||
for (let i = 0; i < pdf.length; i++) {
|
||||
byteArray[i] = pdf.charCodeAt(i);
|
||||
}
|
||||
const blob = new Blob([byteArray], {type: "application/pdf"});
|
||||
// Show the popup to save the pdf
|
||||
await downloadFile(blob, filename, "application/pdf");
|
||||
} else {
|
||||
reportActionsCache[reportXmlId] ||= rpc("/web/action/load", {
|
||||
action_id: reportXmlId,
|
||||
});
|
||||
const reportAction = await reportActionsCache[reportXmlId];
|
||||
// await instead of return because we want the ui to stay blocked
|
||||
await downloadReport(
|
||||
rpc,
|
||||
{ ...reportAction, context: { active_ids } },
|
||||
"pdf",
|
||||
user.context
|
||||
);
|
||||
});
|
||||
const reportAction = await reportActionsCache[reportXmlId];
|
||||
// await instead of return because we want the ui to stay blocked
|
||||
await downloadReport(
|
||||
rpc,
|
||||
{ ...reportAction, context: { active_ids } },
|
||||
"pdf",
|
||||
user.context
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
ui.unblock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user