托盘打印出条形码功能
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
# -*-coding:utf-8-*-
|
# -*-coding:utf-8-*-
|
||||||
from . import models
|
from . import models
|
||||||
|
from . import report
|
||||||
|
|||||||
@@ -10,10 +10,11 @@
|
|||||||
""",
|
""",
|
||||||
'category': 'YZ',
|
'category': 'YZ',
|
||||||
'website': 'https://www.sf.cs.jikimo.com',
|
'website': 'https://www.sf.cs.jikimo.com',
|
||||||
'depends': ['mrp', 'sf_base'],
|
'depends': ['mrp', 'sf_base','hr_holidays'],
|
||||||
'data': [
|
'data': [
|
||||||
'views/sf_tray_view.xml',
|
'views/sf_tray_view.xml',
|
||||||
'views/sf_workorder.xml',
|
'views/sf_workorder.xml',
|
||||||
|
'report/sf_tray_report.xml'
|
||||||
],
|
],
|
||||||
'demo': [
|
'demo': [
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import qrcode
|
|||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
import barcode
|
||||||
|
from barcode.writer import ImageWriter
|
||||||
|
from pystrich.code128 import Code128Encoder
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
@@ -17,8 +20,8 @@ class Tray(models.Model):
|
|||||||
_description = '托盘'
|
_description = '托盘'
|
||||||
|
|
||||||
production_id = fields.Many2one('mrp.production', string='制造订单',
|
production_id = fields.Many2one('mrp.production', string='制造订单',
|
||||||
related='workorder_id.production_id')
|
)
|
||||||
workorder_id = fields.Many2one('mrp.workorder', string="工单")
|
|
||||||
qr_image = fields.Binary(string="托盘二维码", compute='compute_qr_image')
|
qr_image = fields.Binary(string="托盘二维码", compute='compute_qr_image')
|
||||||
|
|
||||||
@api.depends('code')
|
@api.depends('code')
|
||||||
@@ -27,17 +30,26 @@ class Tray(models.Model):
|
|||||||
if not item.code:
|
if not item.code:
|
||||||
item.qr_image = False
|
item.qr_image = False
|
||||||
continue
|
continue
|
||||||
qr = qrcode.QRCode(
|
# 根据code动态生成二维码图片
|
||||||
version=1,
|
# qr = qrcode.QRCode(
|
||||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
# version=1,
|
||||||
box_size=10,
|
# error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||||
border=4,
|
# box_size=10,
|
||||||
)
|
# border=4,
|
||||||
qr.add_data(item.code)
|
# )
|
||||||
qr.make(fit=True)
|
# qr.add_data(item.code)
|
||||||
img = qr.make_image()
|
# qr.make(fit=True)
|
||||||
|
# img = qr.make_image()
|
||||||
|
# 生成条形码文件
|
||||||
|
# bar = barcode.get("ean13", "123456789102", writer=ImageWriter())
|
||||||
|
# a = bar.get_fullcode()
|
||||||
|
# b = bar.save('occ')
|
||||||
|
# 生成条形码图片
|
||||||
|
partner_encoder = Code128Encoder(item.code)
|
||||||
|
# 转换bytes流
|
||||||
temp = BytesIO()
|
temp = BytesIO()
|
||||||
img.save(temp, format='PNG')
|
partner_encoder.save(temp)
|
||||||
|
# img.save(temp, format='PNG')
|
||||||
qr_image = base64.b64encode(temp.getvalue())
|
qr_image = base64.b64encode(temp.getvalue())
|
||||||
item.qr_image = qr_image
|
item.qr_image = qr_image
|
||||||
|
|
||||||
@@ -58,6 +70,23 @@ class MrpWorkOrder(models.Model):
|
|||||||
tray_state = fields.Selection(
|
tray_state = fields.Selection(
|
||||||
string='托盘状态',
|
string='托盘状态',
|
||||||
related='tray_id.state')
|
related='tray_id.state')
|
||||||
|
# def get_tray_info(self):
|
||||||
|
|
||||||
|
|
||||||
|
@api.depends('tray_id')
|
||||||
|
def updateTrayState(self):
|
||||||
|
|
||||||
|
for item in self:
|
||||||
|
if item.tray_code == False:
|
||||||
|
continue
|
||||||
|
trayInfo = self.env['sf.tray'].sudo.search([('code', '=', item.tray_code)])
|
||||||
|
if trayInfo:
|
||||||
|
trayInfo.update(
|
||||||
|
{
|
||||||
|
'production_id': item.production_id,
|
||||||
|
'state': "占用",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
43
sf_route_workcenter/report/sf_tray_report.xml
Normal file
43
sf_route_workcenter/report/sf_tray_report.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<record id="label_sf_tray_code" model="ir.actions.report">
|
||||||
|
<field name="name">打印条形码</field>
|
||||||
|
<field name="model">sf.tray</field>
|
||||||
|
<field name="report_type">qweb-pdf</field>
|
||||||
|
<field name="report_name">sf_route_workcenter.sf_tray_template</field>
|
||||||
|
<field name="report_file">sf_route_workcenter.sf_tray_template</field>
|
||||||
|
<field name="binding_model_id" ref="model_sf_tray"/>
|
||||||
|
<field name="binding_type">report</field>
|
||||||
|
<field name="paperformat_id" ref="hr_holidays.paperformat_hrsummary"/>
|
||||||
|
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<template id="sf_tray_template">
|
||||||
|
<t t-call="web.html_container">
|
||||||
|
<t t-call="web.external_layout">
|
||||||
|
<t t-foreach="docs" t-as="o">
|
||||||
|
<div class="page">
|
||||||
|
<div><h4>编码:<t t-esc="o.code" /></h4></div>
|
||||||
|
<div t-field="o.code" t-options="{'widget': 'barcode', 'width': 600, 'height': 100, 'img_style': 'width:350px;height:60px'}"/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
<record id="sf_tray1" model="report.paperformat">
|
||||||
|
<field name="name">European A4 for DIN5008 Type A</field>
|
||||||
|
<field name="default" eval="False" />
|
||||||
|
<field name="format">A5</field>
|
||||||
|
<field name="orientation">Portrait</field>
|
||||||
|
<field name="margin_top">27</field>
|
||||||
|
<field name="margin_bottom">40</field>
|
||||||
|
<field name="margin_left">20</field>
|
||||||
|
<field name="margin_right">10</field>
|
||||||
|
<field name="dpi">70</field>
|
||||||
|
<field name="header_line" eval="False" />
|
||||||
|
<field name="header_spacing">27</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
@@ -1,27 +1,18 @@
|
|||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
<record id="sf_tray_form_inherit" model="ir.ui.view">
|
<record id="sf_tray_form_inherit" model="ir.ui.view">
|
||||||
<field name="name">托盘二维码生成</field>
|
<field name="name">托盘条形码生成</field>
|
||||||
<field name="model">sf.tray</field>
|
<field name="model">sf.tray</field>
|
||||||
<field name="inherit_id" ref="sf_base.sf_tray_form"/>
|
<field name="inherit_id" ref="sf_base.sf_tray_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<xpath expr="//group[@name='group1']" position="after">
|
<xpath expr="//group[@name='group1']" position="after">
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="生成二维码">
|
<page string="生成条形码">
|
||||||
|
|
||||||
<field name='qr_image' widget="image"/>
|
<field name='qr_image' widget="image"/>
|
||||||
<field name='production_id' default="production_id.name"/>
|
<field name='production_id' default="production_id.name"/>
|
||||||
<field name = 'workorder_id' default="workorder_id.name"/>
|
|
||||||
|
|
||||||
|
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
|
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user