Files
gsinghpal db4b9aa278 changes
2026-03-11 12:15:53 -04:00

41 lines
1.2 KiB
Python

# Copyright © 2025 Nexa Systems Inc (https://nexasystems.ca)
# @author: Nexa Systems Inc (support@nexasystems.ca)
# License OPL-1 (https://www.odoo.com/documentation/19.0/legal/licenses.html).
from odoo import http
from odoo.http import request
from ..wizard.print_product_label import LABEL_ATTACHMENT_NAME
class PrintPDF(http.Controller):
@http.route(
'/print_label/<string:attachment_id>',
type='http',
auth='user',
sitemap=False,
)
def print_label_pdf(self, attachment_id=None, **kwargs):
if not attachment_id:
return request.not_found()
try:
attachment_id = int(attachment_id)
except ValueError:
return request.not_found()
attachment = request.env['ir.attachment'].sudo().search([
('name', '=', LABEL_ATTACHMENT_NAME),
('mimetype', '=', 'application/pdf'),
('id', '=', attachment_id),
])
if not attachment:
return request.not_found()
pdf_url = f'/web/content/{attachment_id}'
return request.render(
'fusion_labels_print.print_product_label_pdf_template',
{'title': 'Print Product Labels', 'pdf_url': pdf_url},
)