142 lines
4.6 KiB
Python
142 lines
4.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of SmartGo. See LICENSE file for full copyright and licensing details.
|
|
import base64
|
|
import logging
|
|
|
|
import qrcode
|
|
|
|
from io import BytesIO
|
|
from odoo import api, fields, models
|
|
import barcode
|
|
from barcode.writer import ImageWriter
|
|
from pystrich.code128 import Code128Encoder
|
|
from odoo.exceptions import UserError
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Tray(models.Model):
|
|
_inherit = 'sf.tray'
|
|
_description = '托盘'
|
|
qr_image = fields.Binary(string="托盘二维码", compute='compute_qr_image')
|
|
|
|
production_id = fields.Many2one('mrp.production', string='制造订单',
|
|
related='workorder_id.production_id'
|
|
)
|
|
workorder_id = fields.Many2one('mrp.workorder', string="工单"
|
|
)
|
|
|
|
@api.onchange('production_id')
|
|
def updateTrayState(self):
|
|
|
|
if self.workorder_id != False:
|
|
self.state = '占用'
|
|
else:
|
|
self.state = '空闲'
|
|
|
|
def unclamp(self):
|
|
self.workorder_id = False
|
|
self.production_id = False
|
|
self.state = '空闲'
|
|
|
|
@api.depends('code')
|
|
def compute_qr_image(self):
|
|
for item in self:
|
|
if not item.code:
|
|
item.qr_image = False
|
|
continue
|
|
# 根据code动态生成二维码图片
|
|
# qr = qrcode.QRCode(
|
|
# version=1,
|
|
# error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
# box_size=10,
|
|
# border=4,
|
|
# )
|
|
# qr.add_data(item.code)
|
|
# 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()
|
|
partner_encoder.save(temp)
|
|
# img.save(temp, format='PNG')
|
|
qr_image = base64.b64encode(temp.getvalue())
|
|
item.qr_image = qr_image
|
|
|
|
|
|
'''
|
|
工单绑定托盘信息
|
|
'''
|
|
|
|
|
|
class MrpWorkOrder(models.Model):
|
|
_inherit = 'mrp.workorder'
|
|
_description = '工单'
|
|
|
|
tray_id = fields.Many2one('sf.tray', string="托盘")
|
|
tray_code = fields.Char(
|
|
string='托盘编码',
|
|
related='tray_id.code')
|
|
tray_state = fields.Selection(
|
|
string='托盘状态',
|
|
related='tray_id.state')
|
|
|
|
# def get_tray_info(self):
|
|
@api.onchange('X_axis', 'Y_axis', 'Z_axis')
|
|
def get_center_point(self):
|
|
return 'X:%s,Y:%s,Z:%s' % (self.X_axis, self.Y_axis, self.Z_axis)
|
|
|
|
surface = fields.Selection([("上面", "上面"), ("下面", "下面"), ("左面", "左面"), ("右面", "右面"),
|
|
("顶面", "顶面")], required=True, default="顶面")
|
|
material_center_point = fields.Char(string='配料中心点', default=get_center_point)
|
|
X1_axis = fields.Integer(string='x1', default=0)
|
|
Y1_axis = fields.Integer(string='y1', default=0)
|
|
X2_axis = fields.Integer(string='x2', default=0)
|
|
Y2_axis = fields.Integer(string='y2', default=0)
|
|
X3_axis = fields.Integer(string='x3', default=0)
|
|
Y3_axis = fields.Integer(string='y3', default=0)
|
|
X4_axis = fields.Integer(string='x4', default=0)
|
|
Y4_axis = fields.Integer(string='y4', default=0)
|
|
X5_axis = fields.Integer(string='x5', default=0)
|
|
Y5_axis = fields.Integer(string='y5', default=0)
|
|
X6_axis = fields.Integer(string='x6', default=0)
|
|
Y6_axis = fields.Integer(string='y6', default=0)
|
|
X7_axis = fields.Integer(string='x7', default=0)
|
|
Y7_axis = fields.Integer(string='y7', default=0)
|
|
X8_axis = fields.Integer(string='x8', default=0)
|
|
Y8_axis = fields.Integer(string='y8', default=0)
|
|
|
|
X_deviation_angle = fields.Integer(string="X轴偏差度", default=0)
|
|
|
|
# @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': "占用",
|
|
# }
|
|
# )
|
|
|
|
|
|
'''
|
|
制造订单绑定托盘信息
|
|
'''
|
|
|
|
|
|
class MrpProduction(models.Model):
|
|
_inherit = 'mrp.production'
|
|
_description = "制造订单"
|
|
|
|
tray_ids = fields.One2many('sf.tray', 'production_id', string="托盘")
|