将fetchCNC移动到sf_mrs_connect模块
This commit is contained in:
@@ -740,86 +740,6 @@ class MrpProduction(models.Model):
|
|||||||
logging.info('change_programming_state error:%s' % e)
|
logging.info('change_programming_state error:%s' % e)
|
||||||
raise UserError("修改编程单状态失败,请联系管理员")
|
raise UserError("修改编程单状态失败,请联系管理员")
|
||||||
|
|
||||||
# cnc程序获取
|
|
||||||
def fetchCNC(self, production_names):
|
|
||||||
cnc = self.env['mrp.production'].search([('id', '=', self.id)])
|
|
||||||
quick_order = False
|
|
||||||
if cnc.product_id.default_code:
|
|
||||||
quick_order = self.env['quick.easy.order'].search(
|
|
||||||
[('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])])
|
|
||||||
programme_way = False
|
|
||||||
if cnc.manual_quotation is True:
|
|
||||||
programme_way = 'manual operation'
|
|
||||||
else:
|
|
||||||
programme_way = 'auto'
|
|
||||||
if cnc.production_type == '人工线下加工':
|
|
||||||
programme_way = 'manual operation'
|
|
||||||
if quick_order:
|
|
||||||
programme_way = 'manual operation'
|
|
||||||
try:
|
|
||||||
res = {
|
|
||||||
'production_no': production_names,
|
|
||||||
'machine_tool_code': '',
|
|
||||||
'product_name': cnc.product_id.name,
|
|
||||||
'remanufacture_type': '',
|
|
||||||
'model_code': cnc.product_id.model_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': '',
|
|
||||||
'embryo_long': cnc.product_id.bom_ids[0].bom_line_ids.product_id.length,
|
|
||||||
'embryo_height': cnc.product_id.bom_ids[0].bom_line_ids.product_id.height,
|
|
||||||
'embryo_width': cnc.product_id.bom_ids[0].bom_line_ids.product_id.width,
|
|
||||||
'order_no': cnc.origin,
|
|
||||||
'model_order_no': cnc.product_id.default_code,
|
|
||||||
'user': cnc.env.user.name,
|
|
||||||
'programme_way': programme_way,
|
|
||||||
# 'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
|
|
||||||
# cnc.product_id.model_file).decode('utf-8'),
|
|
||||||
# 'glb_url': cnc.product_id.glb_url,
|
|
||||||
'part_name': cnc.product_id.part_name,
|
|
||||||
'part_number': cnc.product_id.part_number,
|
|
||||||
'machining_drawings': base64.b64encode(cnc.product_id.machining_drawings).decode(
|
|
||||||
'utf-8') if cnc.product_id.machining_drawings else '',
|
|
||||||
'machining_drawings_name': cnc.product_id.machining_drawings_name,
|
|
||||||
'machining_drawings_mimetype': cnc.product_id.machining_drawings_mimetype,
|
|
||||||
# 'model_id': cnc.product_id.model_id,
|
|
||||||
}
|
|
||||||
# 打印出除了 model_file 之外的所有键值对
|
|
||||||
for key, value in res.items():
|
|
||||||
if key != 'model_file':
|
|
||||||
logging.info('%s: %s' % (key, value))
|
|
||||||
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': '编程中'})
|
|
||||||
# 生成编程记录
|
|
||||||
self.programming_record_ids.create({
|
|
||||||
'number': len(self.programming_record_ids) + 1,
|
|
||||||
'production_id': self.id,
|
|
||||||
'reason': '首次下发',
|
|
||||||
'programming_method': False,
|
|
||||||
'current_programming_count': False,
|
|
||||||
'target_production_id': False,
|
|
||||||
'apply_time': fields.Datetime.now(),
|
|
||||||
'send_time': False,
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
raise UserError(ret['message'])
|
|
||||||
except Exception as e:
|
|
||||||
logging.info('fetchCNC error:%s' % e)
|
|
||||||
raise UserError("cnc程序获取编程单失败,请联系管理员")
|
|
||||||
|
|
||||||
# 维修模块按钮
|
# 维修模块按钮
|
||||||
def button_maintenance_req(self):
|
def button_maintenance_req(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import base64
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
|
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from odoo import models, api
|
from odoo import models, api, fields
|
||||||
from odoo.tools.misc import OrderedSet
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
|
|
||||||
|
|
||||||
class MrpProduction(models.Model):
|
class MrpProduction(models.Model):
|
||||||
@@ -41,4 +46,84 @@ class MrpProduction(models.Model):
|
|||||||
'programming_no': grouped_product_programming_no[production.product_id.id],
|
'programming_no': grouped_product_programming_no[production.product_id.id],
|
||||||
'programming_state': '编程中'
|
'programming_state': '编程中'
|
||||||
})
|
})
|
||||||
return productions
|
return productions
|
||||||
|
|
||||||
|
# cnc程序获取
|
||||||
|
def fetchCNC(self, production_names):
|
||||||
|
cnc = self.env['mrp.production'].search([('id', '=', self.id)])
|
||||||
|
quick_order = False
|
||||||
|
if cnc.product_id.default_code:
|
||||||
|
quick_order = self.env['quick.easy.order'].search(
|
||||||
|
[('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])])
|
||||||
|
programme_way = False
|
||||||
|
if cnc.manual_quotation is True:
|
||||||
|
programme_way = 'manual operation'
|
||||||
|
else:
|
||||||
|
programme_way = 'auto'
|
||||||
|
if cnc.production_type == '人工线下加工':
|
||||||
|
programme_way = 'manual operation'
|
||||||
|
if quick_order:
|
||||||
|
programme_way = 'manual operation'
|
||||||
|
try:
|
||||||
|
res = {
|
||||||
|
'production_no': production_names,
|
||||||
|
'machine_tool_code': '',
|
||||||
|
'product_name': cnc.product_id.name,
|
||||||
|
'remanufacture_type': '',
|
||||||
|
'model_code': cnc.product_id.model_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': '',
|
||||||
|
'embryo_long': cnc.product_id.bom_ids[0].bom_line_ids.product_id.length,
|
||||||
|
'embryo_height': cnc.product_id.bom_ids[0].bom_line_ids.product_id.height,
|
||||||
|
'embryo_width': cnc.product_id.bom_ids[0].bom_line_ids.product_id.width,
|
||||||
|
'order_no': cnc.origin,
|
||||||
|
'model_order_no': cnc.product_id.default_code,
|
||||||
|
'user': cnc.env.user.name,
|
||||||
|
'programme_way': programme_way,
|
||||||
|
# 'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
|
||||||
|
# cnc.product_id.model_file).decode('utf-8'),
|
||||||
|
# 'glb_url': cnc.product_id.glb_url,
|
||||||
|
'part_name': cnc.product_id.part_name,
|
||||||
|
'part_number': cnc.product_id.part_number,
|
||||||
|
'machining_drawings': base64.b64encode(cnc.product_id.machining_drawings).decode(
|
||||||
|
'utf-8') if cnc.product_id.machining_drawings else '',
|
||||||
|
'machining_drawings_name': cnc.product_id.machining_drawings_name,
|
||||||
|
'machining_drawings_mimetype': cnc.product_id.machining_drawings_mimetype,
|
||||||
|
# 'model_id': cnc.product_id.model_id,
|
||||||
|
}
|
||||||
|
# 打印出除了 model_file 之外的所有键值对
|
||||||
|
for key, value in res.items():
|
||||||
|
if key != 'model_file':
|
||||||
|
logging.info('%s: %s' % (key, value))
|
||||||
|
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': '编程中'})
|
||||||
|
# 生成编程记录
|
||||||
|
self.programming_record_ids.create({
|
||||||
|
'number': len(self.programming_record_ids) + 1,
|
||||||
|
'production_id': self.id,
|
||||||
|
'reason': '首次下发',
|
||||||
|
'programming_method': False,
|
||||||
|
'current_programming_count': False,
|
||||||
|
'target_production_id': False,
|
||||||
|
'apply_time': fields.Datetime.now(),
|
||||||
|
'send_time': False,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
raise UserError(ret['message'])
|
||||||
|
except Exception as e:
|
||||||
|
logging.info('fetchCNC error:%s' % e)
|
||||||
|
raise UserError("cnc程序获取编程单失败,请联系管理员")
|
||||||
Reference in New Issue
Block a user