托盘绑定工单,托盘生成二维码
This commit is contained in:
2
sf_route_workcenter/__init__.py
Normal file
2
sf_route_workcenter/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from . import models
|
||||
25
sf_route_workcenter/__manifest__.py
Normal file
25
sf_route_workcenter/__manifest__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫藏智能工厂 工序',
|
||||
'version': '1.0',
|
||||
'summary': '智能工厂工作中心工序',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
在本模块,同步资源库
|
||||
""",
|
||||
'category': 'YZ',
|
||||
'website': 'https://www.sf.cs.jikimo.com',
|
||||
'depends': ['mrp', 'sf_base'],
|
||||
'data': [
|
||||
'views/sf_tray_view.xml',
|
||||
'views/sf_workorder.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
'qweb': [
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
2
sf_route_workcenter/models/__init__.py
Normal file
2
sf_route_workcenter/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from . import workcenter
|
||||
70
sf_route_workcenter/models/workcenter.py
Normal file
70
sf_route_workcenter/models/workcenter.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- 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 = "制造订单"
|
||||
28
sf_route_workcenter/views/sf_tray_view.xml
Normal file
28
sf_route_workcenter/views/sf_tray_view.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="sf_tray_form_inherit" model="ir.ui.view">
|
||||
<field name="name">托盘二维码生成</field>
|
||||
<field name="model">sf.tray</field>
|
||||
<field name="inherit_id" ref="sf_base.sf_tray_form"/>
|
||||
<field name="arch" type="xml">
|
||||
|
||||
|
||||
|
||||
<xpath expr="//group[@name='group1']" position="after">
|
||||
<notebook>
|
||||
<page string="生成二维码">
|
||||
|
||||
<field name = 'qr_image' widget="image" />
|
||||
<field name = 'production_id' default="production_id.name" />
|
||||
<field name = 'workorder_id' default="workorder_id.name"/>
|
||||
|
||||
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
21
sf_route_workcenter/views/sf_workorder.xml
Normal file
21
sf_route_workcenter/views/sf_workorder.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="sf_install_the_tray_workorder_form_view" model="ir.ui.view">
|
||||
<field name="name">装夹工序工单</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[last()]" position="before">
|
||||
<page string="托盘参数" >
|
||||
<group>
|
||||
<field name="tray_id" domain="[('state', '!=', '占用'),('state', '!=', '报损')]"/>
|
||||
<field name="tray_code"/>
|
||||
<field name="tray_state"/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user