implement QZ Tray printer integration for POS configuration

This commit is contained in:
Alaguraj0361 2026-04-20 21:35:07 +05:30
parent eaf04218d9
commit 384852d839
7 changed files with 2996 additions and 0 deletions

View File

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

View File

@ -0,0 +1,19 @@
{
'name': 'Dine360 QZ Tray Printer',
'version': '1.0',
'category': 'Point of Sale',
'summary': 'Integrate Odoo POS with Star/Epson Printers via QZ Tray.',
'depends': ['point_of_sale'],
'data': [
'views/pos_config_views.xml',
],
'assets': {
'point_of_sale._assets_pos': [
'dine360_qz_printer/static/src/js/qz-tray.js',
'dine360_qz_printer/static/src/js/qz_wrapper.js',
],
},
'installable': True,
'application': False,
'license': 'LGPL-3',
}

View File

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

View File

@ -0,0 +1,7 @@
from odoo import fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
use_qz_printer = fields.Boolean("Use QZ Tray Printer", help="Print directly using QZ Tray locally")
qz_printer_name = fields.Char("QZ Printer Name", help="Name of the printer mapped in QZ Tray")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,88 @@
/** @odoo-module */
import { patch } from "@web/core/utils/patch";
import { ReceiptScreen } from "@point_of_sale/app/screens/receipt_screen/receipt_screen";
patch(ReceiptScreen.prototype, {
async printReceipt() {
if (this.pos.config.use_qz_printer && this.pos.config.qz_printer_name) {
try {
if (!window.qz) {
console.error("QZ Tray library not loaded.");
return false;
}
if (!qz.websocket.isActive()) {
await qz.websocket.connect({ retries: 2, delay: 1 });
}
const printerName = this.pos.config.qz_printer_name;
const config = qz.configs.create(printerName);
// Get inner HTML of receipt
const receiptElement = document.querySelector('.pos-receipt-container');
if (!receiptElement) {
return false;
}
const receiptHtml = receiptElement.innerHTML;
// Odoo receipt styling is necessary for QZ pixel print
const printData = `
<html>
<head>
<style>
@page { margin: 0; }
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
width: 300px; /* Adjust based on printer paper width, 80mm = ~300px */
margin: 0;
padding: 10px;
}
* { box-sizing: border-box; }
.pos-receipt { width: 100%; text-align: center; }
.pos-receipt .pos-receipt-logo { max-width: 50%; margin: 0 auto; }
.pos-receipt .pos-receipt-contact { text-align: center; font-size: 12px; margin-bottom: 10px; }
.pos-receipt .receipt-orderlines { width: 100%; text-align: left; }
.pos-receipt .receipt-orderlines td { padding: 2px 0; }
.pos-receipt .receipt-total { width: 100%; font-weight: bold; font-size: 16px; margin-top: 10px; text-align: right; }
</style>
</head>
<body>
<div class="pos-receipt">
${receiptHtml}
</div>
</body>
</html>
`;
await qz.print(config, [
{
type: 'pixel',
format: 'html',
flavor: 'plain',
data: printData
}
]);
if (this.currentOrder) {
this.currentOrder._printed = true;
}
return true;
} catch (err) {
console.error("QZ Tray Print Error:", err);
this.env.services.popup.add("ErrorPopup", {
title: "QZ Tray Printer Error",
body: "Failed to connect to local QZ Tray or printer. Make sure QZ Tray is running.",
});
return false;
}
} else {
// Fallback to default Odoo print behavior
return super.printReceipt(...arguments);
}
}
});

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="pos_config_view_form_inherit_qz" model="ir.ui.view">
<field name="name">pos.config.form.inherit.qz</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<setting id="other_devices" position="after">
<setting id="qz_tray_printer" string="QZ Tray Printer (Star/Epson Direct IP Override)" help="Local browser printing via QZ Tray.">
<field name="use_qz_printer"/>
<div class="content-group" invisible="not use_qz_printer">
<div class="row mt16">
<label string="Printer Name" for="qz_printer_name" class="col-lg-3 o_light_label"/>
<field name="qz_printer_name"/>
</div>
</div>
</setting>
</setting>
</field>
</record>
</odoo>