Accept Merge Request #749: (feature/修改机床参数bug -> develop)
Merge Request: 修改获取cnc从工单到制造订单 Created By: @龚启豪 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @龚启豪 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/749
This commit is contained in:
@@ -92,7 +92,7 @@ class MachineTool(models.Model):
|
||||
type_id = fields.Many2one('sf.machine_tool.type', '型号')
|
||||
brand_id = fields.Many2one('sf.machine.brand', string='品牌')
|
||||
state = fields.Selection(
|
||||
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
||||
[("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"),("空闲", "空闲"),("封存(报废)", "封存(报废)")],
|
||||
default='正常', string="机床状态")
|
||||
# 0606新增字段
|
||||
machine_tool_picture = fields.Binary('图片')
|
||||
|
||||
@@ -139,7 +139,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
record.equipment_type = record.category_id.equipment_type
|
||||
|
||||
code = fields.Char('行业编码')
|
||||
name = fields.Char('机台号')
|
||||
name = fields.Char('机台号', required=False)
|
||||
knife_type = fields.Selection(
|
||||
[("BT40", "BT40"), ("BT30", "BT30"), ("BT50", "BT50")],
|
||||
default="", string="刀把类型")
|
||||
@@ -160,8 +160,9 @@ class SfMaintenanceEquipment(models.Model):
|
||||
type_id = fields.Many2one('sf.machine_tool.type', '型号')
|
||||
|
||||
state = fields.Selection(
|
||||
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
||||
[("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"),("空闲", "空闲"),("封存(报废)", "封存(报废)")],
|
||||
default='正常', string="机床状态")
|
||||
run_time = fields.Char('总运行时长')
|
||||
# 0606新增字段
|
||||
machine_tool_picture = fields.Binary('图片')
|
||||
heightened_way = fields.Selection([
|
||||
@@ -449,7 +450,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
sf_secret_key = sf_sync_config['sf_secret_key']
|
||||
headers = Common.get_headers(self, token, sf_secret_key)
|
||||
strurl = sf_sync_config['sf_url'] + self.crea_url
|
||||
objs_all = self.env['maintenance.equipment'].search([('MTcode', '=', self.MTcode)])
|
||||
objs_all = self.env['maintenance.equipment'].search([('id', '=', self.id)])
|
||||
machine_tool_list = []
|
||||
if objs_all:
|
||||
for item in objs_all:
|
||||
@@ -552,7 +553,7 @@ class SfMaintenanceEquipment(models.Model):
|
||||
kw = json.dumps(machine_tool_list, ensure_ascii=False)
|
||||
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
||||
ret = r.json()
|
||||
self.code = ret['message']
|
||||
self.code = ret['data']
|
||||
self.state_zc = "已注册"
|
||||
if r == 200:
|
||||
return "机床注册成功"
|
||||
|
||||
@@ -26,3 +26,4 @@ class SfMaintenanceLogs(models.Model):
|
||||
recovery_time = fields.Datetime(string='复原时间')
|
||||
fault_duration = fields.Float(string='故障时长')
|
||||
note = fields.Text(string='备注')
|
||||
active = fields.Boolean('Active', default=True)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<field name="inherit_id" ref="maintenance.hr_equipment_category_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='technician_user_id']" position="before">
|
||||
<field name="equipment_type" required='1'/>
|
||||
<field name="equipment_type"/>
|
||||
<field name="equipment_type_code" required='1'/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -105,9 +105,10 @@
|
||||
<!-- Action -->
|
||||
|
||||
<record id="action_maintenance_logs" model="ir.actions.act_window">
|
||||
<field name="name">设备故障日志</field>
|
||||
<field name="name">设备故障日志</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sf.maintenance.logs</field>
|
||||
<field name="search_view_id" ref="view_maintenance_logs_search"/>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_maintenance_logs_tree"/>
|
||||
<field name="help" type="html">
|
||||
@@ -117,6 +118,23 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- <record id="action_maintenance_logs_button" model="ir.actions.act_window">-->
|
||||
<!-- <field name="name">设备故障日志</field>-->
|
||||
<!-- <field name="type">ir.actions.act_window</field>-->
|
||||
<!-- <field name="res_model">sf.maintenance.logs</field>-->
|
||||
<!-- <field name="search_view_id" ref="view_maintenance_logs_search"/>-->
|
||||
<!-- <field name="view_mode">tree,form</field>-->
|
||||
<!-- <field name="view_id" ref="view_maintenance_logs_tree"/>-->
|
||||
<!-- <field name="context">{-->
|
||||
<!-- 'default_maintenance_equipment_id': active_id-->
|
||||
<!-- }</field>-->
|
||||
<!-- <field name="help" type="html">-->
|
||||
<!-- <p class="oe_view_nocontent_create">-->
|
||||
<!-- 设备故障日志-->
|
||||
<!-- </p>-->
|
||||
<!-- </field>-->
|
||||
<!-- </record>-->
|
||||
|
||||
<!-- <record id="action_maintenance_logs" model="ir.actions.act_window">-->
|
||||
<!-- <field name="name">设备故障日志</field>-->
|
||||
<!-- <field name="res_model">sf.maintenance.logs</field>-->
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<button name="%(action_maintenance_logs)d"
|
||||
type="action"
|
||||
class="oe_stat_button"
|
||||
context="{'default_sf_maintenance_logs_ids': sf_maintenance_logs_ids}"
|
||||
context="{'search_default_maintenance_equipment_id': [active_id]}"
|
||||
icon="fa-wrench">
|
||||
<field string="设备故障日志" name="sf_maintenance_logs_ids" widget="statinfo"/>
|
||||
</button>
|
||||
@@ -56,21 +56,22 @@
|
||||
domain="[('brand_id', '=', brand_id)]"/>
|
||||
<field name="machine_tool_category" readonly="1" attrs="{'invisible': [('type_id', '=', False)]}"
|
||||
force_save="1"/>
|
||||
<field name="run_time" force_save="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='description']" position="before">
|
||||
<page string="设备参数" name="sf_equipment"
|
||||
attrs="{'invisible': [('equipment_type', '!=', '机床')]}">
|
||||
<group>
|
||||
<group string="基础参数">
|
||||
<field name="control_system_id" required="1" options="{'no_create': True}"/>
|
||||
<field name="control_system_id" attrs="{'required': [('equipment_type', '=', '机床')]}" options="{'no_create': True}"/>
|
||||
<label for="workbench_L" string="工作台尺寸(mm)"/>
|
||||
<div class="test_model">
|
||||
<label for="workbench_L" string="长"/>
|
||||
<field name="workbench_L" class="o_address_zip" required="1"
|
||||
<field name="workbench_L" class="o_address_zip" attrs="{'required': [('equipment_type', '=', '机床')]}"
|
||||
options="{'format': false}"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="workbench_W" string="宽"/>
|
||||
<field name="workbench_W" class="o_address_zip" required="1"
|
||||
<field name="workbench_W" class="o_address_zip" attrs="{'required': [('equipment_type', '=', '机床')]}"
|
||||
options="{'format': false}"/>
|
||||
</div>
|
||||
<field name="workpiece_load"/>
|
||||
@@ -114,22 +115,22 @@
|
||||
|
||||
<!-- <field name="lead_screw" required="1"/>-->
|
||||
<!-- <field name="guide_rail" required="1"/>-->
|
||||
<field name="number_of_axles" required="1" widget="radio"
|
||||
<field name="number_of_axles" attrs="{'required': [('equipment_type', '=', '机床')]}" widget="radio"
|
||||
options="{'horizontal': true}"/>
|
||||
<label for="x_axis" string="加工行程(mm)"
|
||||
attrs="{'invisible': [('number_of_axles', '=', False)]}"/>
|
||||
<div class="test_model"
|
||||
attrs="{'invisible': [('number_of_axles', '=', False)]}">
|
||||
<label for="x_axis" string="x"/>
|
||||
<field name="x_axis" class="o_address_zip" required="1"
|
||||
<field name="x_axis" class="o_address_zip" attrs="{'required': [('equipment_type', '=', '机床')]}"
|
||||
options="{'format': false}"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="y_axis" string="y"/>
|
||||
<field name="y_axis" class="o_address_zip" required="1"
|
||||
<field name="y_axis" class="o_address_zip" attrs="{'required': [('equipment_type', '=', '机床')]}"
|
||||
options="{'format': false}"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="z_axis" string="z"/>
|
||||
<field name="z_axis" class="o_address_zip" required="1"
|
||||
<field name="z_axis" class="o_address_zip" attrs="{'required': [('equipment_type', '=', '机床')]}"
|
||||
options="{'format': false}"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="a_axis" string="a"
|
||||
@@ -152,7 +153,7 @@
|
||||
</div>
|
||||
</group>
|
||||
<group string="主轴">
|
||||
<field name="taper_type_id" required="1"/>
|
||||
<field name="taper_type_id" attrs="{'required': [('equipment_type', '=', '机床')]}"/>
|
||||
<label for="distance_min" string="主轴端面-工作台距离(mm)"/>
|
||||
<div class="test_model">
|
||||
<label for="distance_min" string="最小(min)"/>
|
||||
@@ -178,7 +179,7 @@
|
||||
</group>
|
||||
<group string="刀具">
|
||||
<!-- <field name="knife_type" required="1"/>-->
|
||||
<field name="number_of_knife_library" required="1" options="{'format': false}"/>
|
||||
<field name="number_of_knife_library" attrs="{'required': [('equipment_type', '=', '机床')]}" options="{'format': false}"/>
|
||||
<!-- <field name="tool_speed" required="1"/>-->
|
||||
<field name="tool_full_diameter_max"/>
|
||||
<field name="tool_perimeter_diameter_max"/>
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import logging
|
||||
import re
|
||||
import requests
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
@@ -17,6 +22,10 @@ class MrpProduction(models.Model):
|
||||
|
||||
check_status = fields.Boolean(string='启用状态', default=False, readonly=True)
|
||||
active = fields.Boolean(string='已归档', default=True)
|
||||
programming_no = fields.Char('编程单号')
|
||||
work_state = fields.Char('业务状态')
|
||||
programming_state = fields.Char('编程状态')
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
|
||||
def action_check(self):
|
||||
"""
|
||||
@@ -47,6 +56,48 @@ class MrpProduction(models.Model):
|
||||
for production in self:
|
||||
production.maintenance_count = len(production.request_ids)
|
||||
|
||||
# cnc程序获取
|
||||
def fetchCNC(self):
|
||||
cnc = self.env['mrp.production'].search([('id', '=', self.id)])
|
||||
try:
|
||||
res = {'model_code': '' if not cnc.product_id.model_code else cnc.product_id.model_code,
|
||||
'production_no': cnc.name,
|
||||
'machine_tool_code': "",
|
||||
'material_code': self.env['sf.production.materials'].search(
|
||||
[('id', '=', cnc.product_id.materials_id.id)]).materials_no,
|
||||
'material_type_code': self.env['sf.materials.model'].search(
|
||||
[('id', '=', cnc.product_id.materials_type_id.id)]).materials_no,
|
||||
'machining_processing_panel': cnc.product_id.model_processing_panel,
|
||||
'machining_precision': cnc.product_id.model_machining_precision,
|
||||
'embryo_long': cnc.product_id.bom_ids.bom_line_ids.product_id.length,
|
||||
'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height,
|
||||
'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width,
|
||||
'order_no': cnc.origin,
|
||||
'model_order_no': cnc.product_id.default_code.rsplit(' -', 1)[0],
|
||||
'user': cnc.env.user.name,
|
||||
'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
|
||||
cnc.product_id.model_file).decode('utf-8')
|
||||
}
|
||||
logging.info('res:%s' % res)
|
||||
configsettings = self.env['res.config.settings'].get_values()
|
||||
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
|
||||
url = '/api/intelligent_programming/create'
|
||||
config_url = configsettings['sf_url'] + url
|
||||
res['token'] = configsettings['token']
|
||||
# res_str = json.dumps(res)
|
||||
ret = requests.post(config_url, json={}, data=res, headers=config_header)
|
||||
ret = ret.json()
|
||||
logging.info('fetchCNC-ret:%s' % ret)
|
||||
if ret['status'] == 1:
|
||||
self.write(
|
||||
{'programming_no': ret['programming_no'], 'programming_state': '编程中', 'work_state': '编程中'})
|
||||
else:
|
||||
raise UserError(ret['message'])
|
||||
except Exception as e:
|
||||
logging.info('fetchCNC error:%s' % e)
|
||||
raise UserError("cnc程序获取编程单失败,请联系管理员")
|
||||
|
||||
|
||||
# 维修模块按钮
|
||||
def button_maintenance_req(self):
|
||||
self.ensure_one()
|
||||
@@ -134,6 +185,7 @@ class MrpProduction(models.Model):
|
||||
'state': 'pending',
|
||||
}]
|
||||
if production.product_id.categ_id.type == '成品':
|
||||
production.fetchCNC()
|
||||
# 根据加工面板的面数及对应的工序模板生成工单
|
||||
i = 0
|
||||
processing_panel_len = len(production.product_id.model_processing_panel.split(','))
|
||||
@@ -366,7 +418,8 @@ class MrpProduction(models.Model):
|
||||
current_sequence += 1
|
||||
if work.name == '获取CNC加工程序':
|
||||
work.button_start()
|
||||
work.fetchCNC()
|
||||
#work.fetchCNC()
|
||||
work.button_finish()
|
||||
|
||||
# 创建工单并进行排序
|
||||
def _create_workorder(self):
|
||||
|
||||
@@ -22,7 +22,7 @@ class ResWorkcenter(models.Model):
|
||||
|
||||
|
||||
equipment_status = fields.Selection(
|
||||
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
||||
[("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"),("空闲", "空闲"),("封存(报废)", "封存(报废)")],
|
||||
string="设备状态", related='equipment_id.state')
|
||||
|
||||
# @api.depends('equipment_id')
|
||||
|
||||
@@ -450,7 +450,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height,
|
||||
'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width,
|
||||
'order_no': cnc.production_id.origin,
|
||||
'model_order_no': cnc.product_id.default_code.rsplit('-', 1)[0],
|
||||
'model_order_no': cnc.product_id.default_code.rsplit(' -', 1)[0],
|
||||
'user': self.env.user.name,
|
||||
'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
|
||||
cnc.product_id.model_file).decode('utf-8')
|
||||
@@ -574,6 +574,18 @@ class ResMrpWorkOrder(models.Model):
|
||||
'order_line': order_line_ids,
|
||||
})
|
||||
super().button_finish()
|
||||
is_production_id = True
|
||||
for workorder in self.production_id.workorder_ids:
|
||||
if workorder.state != 'done':
|
||||
is_production_id = False
|
||||
if is_production_id == True and self.name == '解除装夹':
|
||||
for move_raw_id in self.production_id.move_raw_ids:
|
||||
move_raw_id.quantity_done = move_raw_id.product_uom_qty
|
||||
self.production_id.state = 'done'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
@@ -595,6 +607,7 @@ class CNCprocessing(models.Model):
|
||||
estimated_processing_time = fields.Char('预计加工时间')
|
||||
remark = fields.Text('备注')
|
||||
workorder_id = fields.Many2one('mrp.workorder', string="工单")
|
||||
workorder_id = fields.Many2one('mrp.production', string="制造定单")
|
||||
button_state = fields.Boolean(string='是否已经下发')
|
||||
|
||||
# mrs下发编程单创建CNC加工
|
||||
@@ -620,11 +633,11 @@ class CNCprocessing(models.Model):
|
||||
'remark': obj['remark']
|
||||
})
|
||||
self.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
|
||||
cnc_workorder.state = 'done'
|
||||
# cnc_workorder.state = 'done'
|
||||
cnc_workorder.work_state = '已编程'
|
||||
cnc_workorder.programming_state = '已编程'
|
||||
cnc_workorder.time_ids.date_end = datetime.now()
|
||||
cnc_workorder.button_finish()
|
||||
# cnc_workorder.time_ids.date_end = datetime.now()
|
||||
# cnc_workorder.button_finish()
|
||||
|
||||
# 根据程序名和加工面匹配到ftp里对应的Nc程序名
|
||||
def get_cnc_processing_file(self, folder_name, cnc_processing, processing_panel):
|
||||
|
||||
@@ -66,6 +66,11 @@
|
||||
<button name="action_check" string="审核" type="object" class="oe_highlight" attrs="{'invisible': [('check_status', '=', True)]}" groups="sf_base.group_plan_director"/>
|
||||
<!-- <button name="action_uncheck" string="禁用" type="object" class="oe_highlight" attrs="{'invisible': [('check_status', '=', False)]}" groups="sf_base.group_plan_director"/> -->
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='user_id']" position="after">
|
||||
<field name="programming_no"/>
|
||||
<field name="work_state" invisible="1"/>
|
||||
<field name="programming_state"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -23,12 +23,11 @@ class Sf_Mrs_Connect(http.Controller):
|
||||
ret = json.loads(datas)
|
||||
ret = json.loads(ret['result'])
|
||||
# 查询状态为进行中且类型为获取CNC加工程序的工单
|
||||
cnc_workorder = request.env['mrp.workorder'].with_user(
|
||||
request.env.ref("base.user_admin")).search([('production_id.name', '=', ret['production_order_no']),
|
||||
('routing_type', '=', '获取CNC加工程序'),
|
||||
('state', '=', 'progress')])
|
||||
if cnc_workorder:
|
||||
cnc_workorder.glb_file = base64.b64encode(ret['glb_file'])
|
||||
cnc_production = request.env['mrp.production'].with_user(
|
||||
request.env.ref("base.user_admin")).search([('name', '=', ret['production_order_no'])])
|
||||
if cnc_production:
|
||||
if ret['glb_file']:
|
||||
cnc_production.glb_file = base64.b64encode(ret['glb_file'])
|
||||
# 拉取所有加工面的程序文件
|
||||
# i = 1
|
||||
for r in ret['processing_panel']:
|
||||
@@ -37,10 +36,10 @@ class Sf_Mrs_Connect(http.Controller):
|
||||
ret['folder_name'], r)
|
||||
if not download_state:
|
||||
res['status'] = -2
|
||||
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_workorder.production_id.name)
|
||||
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name)
|
||||
return json.JSONEncoder().encode(res)
|
||||
request.env['sf.cnc.processing'].with_user(
|
||||
request.env.ref("base.user_admin")).cnc_processing_create(cnc_workorder, ret)
|
||||
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret)
|
||||
return json.JSONEncoder().encode(res)
|
||||
else:
|
||||
res = {'status': 0, 'message': '该制造订单暂未开始'}
|
||||
|
||||
Reference in New Issue
Block a user