This commit is contained in:
gsinghpal
2026-03-11 12:15:53 -04:00
parent f81e0cd918
commit db4b9aa278
1210 changed files with 173089 additions and 4044 deletions

View File

@@ -0,0 +1,14 @@
==================
Fusion Labels Print
==================
Product label printing without download - direct print to printer.
Features
--------
* Direct label printing without PDF download
* Seamless integration with Fusion Labels base module
Author
------
* Nexa Systems Inc - https://nexasystems.ca

View File

@@ -0,0 +1,2 @@
from . import wizard
from . import controllers

View File

@@ -0,0 +1,25 @@
{
# App information
"name": "Fusion Labels Print",
"version": "19.0.1.0.0",
"category": "Hidden",
"summary": "Product label printing without download.",
"license": "OPL-1",
"depends": [
"fusion_labels",
],
# Views
"data": [
"views/print_product_label_templates.xml",
"wizard/print_product_label_views.xml",
],
# Author
"author": "Nexa Systems Inc",
"website": "https://nexasystems.ca",
"maintainer": "Nexa Systems Inc",
"support": "support@nexasystems.ca",
# Technical
"installable": True,
"auto_install": False,
"application": False,
}

View File

@@ -0,0 +1 @@
from . import main

View File

@@ -0,0 +1,40 @@
# 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},
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="print_product_label_pdf_template" name="print_pdf_template">
<head>
<title><t t-out="title"/></title>
</head>
<body style="margin:auto;">
<iframe t-att-src="pdf_url" frameborder="0" scrolling="yes" seamless="seamless" style="display:block; width:100%; height:100vh;"></iframe>
</body>
<script>
printPdf = function (url) {
var iframe = this._printIframe;
if (!this._printIframe) {
iframe = this._printIframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.onload = function() {
setTimeout(function() {
iframe.focus();
iframe.contentWindow.print();
}, 1);
};
}
iframe.src = url;
}
printPdf("<t t-out="pdf_url"/>")
</script>
</template>
</odoo>

View File

@@ -0,0 +1 @@
from . import print_product_label

View File

@@ -0,0 +1,39 @@
# 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 datetime import datetime, timedelta
from odoo import api, models
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
LABEL_ATTACHMENT_NAME = 'Product Label Direct Printing'
class PrintProductLabel(models.TransientModel):
_inherit = "print.product.label"
def action_print_direct(self):
""" Print labels directly without download. """
self.ensure_one()
attachment = self.env['ir.attachment'].create({
'name': LABEL_ATTACHMENT_NAME,
'type': 'binary',
'datas': self.get_pdf(),
'mimetype': 'application/pdf',
'public': False,
})
return {
'type': 'ir.actions.act_url',
'url': f'/print_label/{attachment.id}',
'target': 'new',
}
@api.autovacuum
def _gc_print_label_attachments(self):
timeout_ago = datetime.utcnow() - timedelta(days=1)
domain = [
('name', '=', LABEL_ATTACHMENT_NAME),
('mimetype', '=', 'application/pdf'),
('create_date', '<', timeout_ago.strftime(DEFAULT_SERVER_DATETIME_FORMAT)),
]
return self.env['ir.attachment'].sudo().search(domain).unlink()

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="print_product_label_view_form" model="ir.ui.view">
<field name="name">print.product.label.view.form.inherit.fusion_labels_print</field>
<field name="model">print.product.label</field>
<field name="inherit_id" ref="fusion_labels.print_product_label_view_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_print']" position="before">
<button name="action_print_direct"
string="Print"
help="Print product labels"
type="object"
icon="fa-print"
class="btn-primary mr8"/>
</xpath>
<xpath expr="//button[@name='action_print']" position="attributes">
<attribute name="string">Download</attribute>
<attribute name="help">Download product labels</attribute>
<attribute name="icon">fa-download</attribute>
<attribute name="class" separator=" " remove="btn-primary" add="btn-light border"/>
</xpath>
</field>
</record>
</odoo>