对模型进行上色和特征识别及自动报价

This commit is contained in:
jinling.yang
2023-08-25 10:39:31 +08:00
parent e7d32e5041
commit 5de04449e4
8 changed files with 195 additions and 27 deletions

View File

@@ -18,11 +18,12 @@ class QuickEasyOrder(models.Model):
_description = '简易下单'
name = fields.Char('订单编号', default=lambda self: self.env['ir.sequence'].next_by_code('quick.easy.order'))
model_length = fields.Float('[mm]', digits=(16, 3))
model_width = fields.Float('[mm]', digits=(16, 3))
model_height = fields.Float('[mm]', digits=(16, 3))
model_volume = fields.Float('体积[mm³]', digits=(16, 3))
model_processing_side = fields.Char('加工面')
model_length = fields.Float('(mm)', digits=(16, 3))
model_width = fields.Float('(mm)', digits=(16, 3))
model_height = fields.Float('(mm)', digits=(16, 3))
model_volume = fields.Float('体积(mm³)', digits=(16, 3))
model_processing_side = fields.Char('加工面', default='A')
model_feature = fields.Char('特征')
machining_precision = fields.Selection([
('0.10', '±0.10mm'),
('0.05', '±0.05mm'),
@@ -44,6 +45,9 @@ class QuickEasyOrder(models.Model):
('待接单', '待接单'), ('加工中', '加工中'),
('物流中', '物流中'), ('已交付', '已交付')], string='订单状态', default='草稿',
readonly=True)
model_color_state = fields.Selection([
('success', '成功'),
('fail', '失败')], string='模型上色状态')
@api.depends('material_id', 'material_model_id')
def _compute_material_model(self):
@@ -69,23 +73,9 @@ class QuickEasyOrder(models.Model):
report_path = attachment._full_path(attachment.store_fname)
vals['model_file'] = self.transition_glb_file(report_path, model_code)
logging.info('create-model_file:%s' % len(vals['model_file']))
feature_path = self.env['jikimo.auto_quatotion.common'].sudo().get_feature_full_path()
# price_path = self.env['jikimo.auto_quatotion.common'].get_price_full_path()
process_time_db_path = self.env['jikimo.auto_quatotion.common'].sudo().get_process_time_db_path()
ret = self.env['jikimo.auto_quatotion.common'].sudo().get_auto_quatotion(report_path, feature_path,
process_time_db_path,
model_code)
logging.info("自动报价返回值: %s" % ret)
shapes = ret['boxshape'].tolist()
logging.info("自动报价boxshape: %s" % shapes)
target_faces = ','.join(ret['target_faces']),
# item.price = ret['price']
item.model_length = shapes[0] # 长 单位mm
item.model_width = shapes[1] # 宽
item.model_height = shapes[2] # 高
item.model_volume = shapes[0] * shapes[1] * shapes[2]
item.model_processing_side = target_faces[0]
obj = super(QuickEasyOrder, self).create(vals)
self.model_coloring()
self.distribute_to_factory(obj)
return obj
@@ -123,15 +113,32 @@ class QuickEasyOrder(models.Model):
model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest()
logging.info("模型编码: %s" % model_code)
item.model_file = self.transition_glb_file(report_path, model_code)
ret = self.feature_recognition(report_path, model_code)
logging.info("自动报价返回值: %s" % ret)
boxshape = ret['boxshape'].tolist()
logging.info("自动报价boxshape: %s" % boxshape)
logging.info('自动报价feature_infos:%s' % ret['feature_infos'])
item.model_length = boxshape[0] # 长 单位mm
item.model_width = boxshape[1] # 宽
item.model_height = boxshape[2] # 高
item.model_volume = boxshape[0] * boxshape[1] * boxshape[2]
item.model_feature = json.dumps(ret['feature_infos'], ensure_ascii=False)
self._get_price(item)
else:
item.model_file = False
item.model_feature = False
item.model_length = 0
item.model_width = 0
item.model_height = 0
item.model_volume = 0
def distribute_to_factory(self, obj):
"""
派单到工厂
:return:
"""
web_base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url', default=''),
web_base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='')
logging.info("自动报价返回值: %s" % ret)
url = '/api/bfm_process_order/list'
res = {'order_number': obj.name, 'delivery_end_date': str(datetime.now()),
'delivery_name': 'XXXXX', 'delivery_telephone': 'XXXXX',
@@ -181,3 +188,94 @@ class QuickEasyOrder(models.Model):
raise UserError(e)
else:
raise UserError("分配工厂失败,请联系管理员")
# 特征识别
def feature_recognition(self, report_path, model_code):
feature_path = self.env['sf.auto_quatotion.common'].sudo().get_feature_full_path()
# price_path = self.env['jikimo.auto_quatotion.common'].get_price_full_path()
process_time_db_path = self.env['sf.auto_quatotion.common'].sudo().get_process_time_db_path()
ret = self.env['sf.auto_quatotion.common'].sudo().get_auto_quatotion(report_path, feature_path,
process_time_db_path,
model_code)
return ret
# 模型上色
def model_coloring(self):
url = '/api/library_of_models/create'
config = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, config['sf_token'], config['sf_key_secret'])
order = self.search([('id', '=', self.id)])
logging.info('order: %s' % order.name)
if order:
attachment = order.upload_model_file[0]
base64_data = base64.b64encode(attachment.datas)
base64_datas = base64_data.decode('utf-8')
model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest()
logging.info('model_file-size: %s' % len(order.model_file))
logging.info('attachment.datas-size: %s' % len(attachment.datas))
vals = {
'model_code': model_code,
'model_data': base64_data,
'model_name': attachment.name,
'model_long': order.model_length,
'model_width': order.model_width,
'model_height': order.model_height,
'model_volume': order.model_volume,
'model_order_no': order.name,
'remark': '订单号:%s 客户:%s' % (order.name, order.customer_id.name)
}
try:
ret = requests.post((config['sf_url'] + url), json={}, data=vals, headers=config_header,
timeout=60)
ret = ret.json()
# result = json.loads(ret['result'])
if ret['status'] == 1:
order.model_color_state = 'success'
else:
order.model_color_state = 'fail'
raise UserError(ret['message'])
except Exception as e:
order.model_color_state = 'fail'
raise UserError("模型上色失败")
# 自动报价
def _get_price(self, order):
url = '/api/automatic_quotes'
config = self.env['res.config.settings'].sudo().get_values()
config_header = Common.get_headers(self, config['sf_token'], config['sf_key_secret'])
logging.info("报价接口..........% s" % order.name)
try:
if order:
vals = {}
# mrs合作伙伴token
vals['token'] = config['sf_token']
vals['accuracy'] = order.machining_precision
vals['number'] = order.quantity
vals['process_code'] = 0
vals['texture_code'] = order.material_model_id.code
vals['delivery_days'] = 15
if order.model_file:
attachment = self.env['ir.attachment'].sudo().search(
[('id', '=', order.upload_model_file[0])])
vals['attachment_id'] = attachment.id
else:
vals['attachment_id'] = ''
vals['feature_infos'] = order.model_feature
vals['model_long'] = order.model_length
vals['model_width'] = order.model_width
vals['model_height'] = order.model_height
logging.info('vals:%s' % vals)
ret = requests.post((config['sf_url'] + url), json={}, data=vals, headers=config_header)
result = json.dumps(json.loads(ret.text), ensure_ascii=False, indent=4, separators=(',', ':'))
logging.info('报价接口返回:%s' % result)
price_result = json.loads(result)
# random.randint(0, 10000)
order.write({'price': price_result.get('price')})
else:
raise UserError("订单不存在")
except Exception as e:
if ret['status'] != 1:
raise UserError(e)
else:
raise UserError("自动报价失败,请联系管理员")