优化快读订单

This commit is contained in:
jinling.yang
2024-04-19 16:50:38 +08:00
parent bcba08042b
commit a30c620823
3 changed files with 54 additions and 6 deletions

View File

@@ -1,12 +1,14 @@
import logging
import base64
import hashlib
import requests
import os
from datetime import datetime
from stl import mesh
# from OCC.Core.GProp import GProp_GProps
from OCC.Extend.DataExchange import read_step_file
from OCC.Extend.DataExchange import write_stl_file
# from OCC.Extend.DataExchange import read_step_file
# from OCC.Extend.DataExchange import write_stl_file
from odoo.addons.sf_base.commons.common import Common
from odoo import models, fields, api
from odoo.modules import get_resource_path
from odoo.exceptions import ValidationError, UserError
@@ -79,6 +81,8 @@ class QuickEasyOrder(models.Model):
report_path = attachment._full_path(attachment.store_fname)
vals['model_file'] = self.transition_glb_file(report_path, model_code)
obj = super(QuickEasyOrder, self).create(vals)
logging.info('---------向cloud生成模型库-------')
self.model_coloring()
logging.info('---------开始派单到工厂-------')
self.distribute_to_factory(obj)
obj.state = '待接单'
@@ -160,7 +164,7 @@ class QuickEasyOrder(models.Model):
try:
logging.info('---------派单到工厂-------')
res = {'bfm_process_order_list': []}
for item in obj:
for item in self:
attachment = item.upload_model_file[0]
base64_data = base64.b64encode(attachment.datas)
base64_datas = base64_data.decode('utf-8')
@@ -262,3 +266,45 @@ class QuickEasyOrder(models.Model):
except Exception as e:
# self.cr.rollback()
return UserError('工厂创建销售订单和产品失败,请联系管理员')
# 模型上色
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['token'], config['sf_secret_key'])
logging.info('order: %s' % self.name)
if self:
attachment = self.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(self.model_file))
logging.info('attachment.datas-size: %s' % len(attachment.datas))
vals = {
'programme_way': 'manual operation',
'model_code': model_code,
'model_data': base64.b64decode(attachment.datas),
'model_color_data': '',
'model_name': attachment.name,
'model_long': self.model_length,
'model_width': self.model_width,
'model_height': self.model_height,
'model_volume': self.model_volume,
'color_model_path': '/tmp/' + str(model_code) + ".step",
'model_order_no': self.name,
'remark': '订单号:%s 客户:%s' % (self.name, self.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:
self.model_color_state = 'success'
else:
self.model_color_state = 'fail'
raise UserError(ret['message'])
except Exception as e:
self.model_color_state = 'fail'
raise UserError("模型上色失败")