优化快读订单

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

@@ -54,8 +54,9 @@ class MrpProduction(models.Model):
glb_file = fields.Binary("glb模型文件")
production_line_id = fields.Many2one('sf.production.line', string='生产线')
plan_start_processing_time = fields.Datetime('计划开始加工时间')
production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')],
string='/下产线', default='待上产线')
production_line_state = fields.Selection(
[('待上产线', '待上产线'), ('已上产线', '上产线'), ('已下产线', '已下产线')],
string='上/下产线', default='待上产线')
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
@@ -156,6 +157,7 @@ class MrpProduction(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.origin,
'quick_order_no': quick_order.name if quick_order else False,
'model_order_no': cnc.product_id.default_code,
'user': cnc.env.user.name,
'programme_way': programme_way,

View File

@@ -1186,7 +1186,7 @@ class WorkPieceDelivery(models.Model):
logging.info('config-e:%s' % e)
raise UserError("工件配送请求agv失败")
@api.depends('production_id.production_line_id')
@api.onchange('production_id.production_line_id')
def _compute_production_line_id(self):
if self.production_id.production_line_id:
self.production_line_id = self.production_id.production_line_id.id

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("模型上色失败")