71 lines
1.8 KiB
Python
71 lines
1.8 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
|
|
from odoo.exceptions import UserError
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Tray(models.Model):
|
|
_inherit = 'sf.tray'
|
|
_description = '托盘'
|
|
|
|
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')
|
|
|
|
@api.depends('code')
|
|
def compute_qr_image(self):
|
|
for item in self:
|
|
if not item.code:
|
|
item.qr_image = False
|
|
continue
|
|
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()
|
|
temp = BytesIO()
|
|
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')
|
|
|
|
|
|
'''
|
|
制造订单绑定托盘信息
|
|
'''
|
|
|
|
|
|
class MrpProduction(models.Model):
|
|
_inherit = 'mrp.production'
|
|
_description = "制造订单"
|