一键打印功能
This commit is contained in:
3
zpl_print/__init__.py
Normal file
3
zpl_print/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from .import models
|
||||
from .import controllers
|
||||
23
zpl_print/__manifest__.py
Normal file
23
zpl_print/__manifest__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '一键打印功能',
|
||||
'version': '1.0',
|
||||
'summary': '一件打印',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
在本模块,实现了一键打印功能
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['base', 'web'],
|
||||
'data': [
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
'qweb': [
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
2
zpl_print/controllers/__init__.py
Normal file
2
zpl_print/controllers/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from .import report
|
||||
60
zpl_print/controllers/report.py
Normal file
60
zpl_print/controllers/report.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
import werkzeug
|
||||
import werkzeug.exceptions
|
||||
import werkzeug.utils
|
||||
import werkzeug.wrappers
|
||||
import werkzeug.wsgi
|
||||
from werkzeug.urls import url_parse
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import content_disposition, request
|
||||
from odoo.tools.safe_eval import safe_eval, time
|
||||
from odoo.addons.web.controllers.report import ReportController
|
||||
from ..models.common import Common
|
||||
|
||||
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ZplReportController(ReportController):
|
||||
|
||||
|
||||
#------------------------------------------------------
|
||||
# Report controllers
|
||||
#------------------------------------------------------
|
||||
@http.route([
|
||||
'/report/<converter>/<reportname>',
|
||||
'/report/<converter>/<reportname>/<docids>',
|
||||
], type='http', auth='user', website=True)
|
||||
def report_routes(self, reportname, docids=None, converter=None, **data):
|
||||
report = request.env['ir.actions.report']
|
||||
context = dict(request.env.context)
|
||||
|
||||
if docids:
|
||||
docids = [int(i) for i in docids.split(',')]
|
||||
if data.get('options'):
|
||||
data.update(json.loads(data.pop('options')))
|
||||
if data.get('context'):
|
||||
data['context'] = json.loads(data['context'])
|
||||
context.update(data['context'])
|
||||
if converter == 'html':
|
||||
html = report.with_context(context)._render_qweb_html(reportname, docids, data=data)[0]
|
||||
return request.make_response(html)
|
||||
elif converter == 'pdf':
|
||||
pdf = report.with_context(context)._render_qweb_pdf(reportname, docids, data=data)[0]
|
||||
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
|
||||
return request.make_response(pdf, headers=pdfhttpheaders)
|
||||
elif converter == 'text':
|
||||
text = report.with_context(context)._render_qweb_text(reportname, docids, data=data)[0]
|
||||
text_str = text.decode()
|
||||
Common.print_zpl(self, text_str)
|
||||
texthttpheaders = [('Content-Type', 'text/plain'), ('Content-Length', len(text))]
|
||||
return request.make_response(text, headers=texthttpheaders)
|
||||
else:
|
||||
raise werkzeug.exceptions.HTTPException(description='Converter %s not implemented.' % converter)
|
||||
0
zpl_print/libs/TSCLIB.dll
Normal file
0
zpl_print/libs/TSCLIB.dll
Normal file
2
zpl_print/models/__init__.py
Normal file
2
zpl_print/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from .import common
|
||||
24
zpl_print/models/common.py
Normal file
24
zpl_print/models/common.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models
|
||||
import ctypes
|
||||
|
||||
|
||||
class Common(models.Model):
|
||||
_name = 'sf.sync.common'
|
||||
_description = u'公用类'
|
||||
|
||||
def print_zpl(self, zpl_str):
|
||||
WinDll_path = "D://桌面//pythonZPL//tsc_python_sdk_example//TSC_Python_SDK_Example//tsc_sample//libs//TSCLIB.dll"
|
||||
try:
|
||||
tsclibrary = ctypes.WinDLL(WinDll_path)
|
||||
tsclibrary.openportW("USB")
|
||||
print(zpl_str)
|
||||
tsclibrary.sendcommandW(zpl_str)
|
||||
print('111222')
|
||||
tsclibrary.printlabelW("0", "1");
|
||||
tsclibrary.closeport();
|
||||
except Exception as e:
|
||||
raise UserWarning("错误警告")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user