修改cnc获取在制造订单的逻辑,制造订单所有工单完成时 制造订单自动完成,以及组件自动消耗掉
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import logging
|
||||
import re
|
||||
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 +21,9 @@ 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('编程状态')
|
||||
|
||||
def action_check(self):
|
||||
"""
|
||||
@@ -47,6 +54,47 @@ class MrpProduction(models.Model):
|
||||
for production in self:
|
||||
production.maintenance_count = len(production.request_ids)
|
||||
|
||||
# cnc程序获取
|
||||
def fetchCNC(self, requests=None):
|
||||
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_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()
|
||||
@@ -366,7 +414,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):
|
||||
|
||||
@@ -447,7 +447,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')
|
||||
@@ -571,6 +571,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):
|
||||
@@ -592,6 +604,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加工
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
<!-- <button name="archive" type="object" string="归档" icon="fa-archive" class="oe_highlight" attrs="{'invisible': [('active', '=', False)]}"/> -->
|
||||
<!-- <button name="unarchive" type="object" string="取消归档" icon="fa-archive" class="oe_highlight" attrs="{'invisible': [('active', '=', True)]}"/> -->
|
||||
<button name="action_check" string="审核" type="object" class="oe_highlight" attrs="{'invisible': [('check_status', '=', True)]}" groups="sf_base.group_plan_director"/>
|
||||
<div class="col-12 col-lg-6 o_setting_box" style="white-space: nowrap">
|
||||
<button type="object" class="oe_highlight" name="fetchCNC" string="获取CNC程序代码"
|
||||
/>
|
||||
</div>
|
||||
<!-- <button name="action_uncheck" string="禁用" type="object" class="oe_highlight" attrs="{'invisible': [('check_status', '=', False)]}" groups="sf_base.group_plan_director"/> -->
|
||||
</xpath>
|
||||
|
||||
|
||||
@@ -23,12 +23,10 @@ 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:
|
||||
cnc_production.glb_file = base64.b64encode(ret['glb_file'])
|
||||
# 拉取所有加工面的程序文件
|
||||
# i = 1
|
||||
for r in ret['processing_panel']:
|
||||
@@ -37,10 +35,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.production_id.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