1.模型为上色Bug修复(cloud代码注释引起)

2.创建产品和订单未成功Bug修复
This commit is contained in:
jinling.yang
2023-08-28 17:40:19 +08:00
parent df650edefd
commit fb717c22ad
5 changed files with 123 additions and 66 deletions

View File

@@ -179,3 +179,9 @@ class MrsProductionProcessParameter(models.Model):
def get_gain_way(self, item):
process_parameter = self.env['sf.production.process.parameter'].search([('id', '=', item.id)])
return process_parameter
def _json_production_process_item_code(self, item):
code_arr = []
for i in item.parameter_ids:
code_arr.append(i.code)
return code_arr

View File

@@ -115,7 +115,7 @@
<record model="ir.ui.view" id="sf_production_process_form">
<field name="model">sf.production.process</field>
<field name="arch" type="xml">
<form string="表面工艺" create="0" edit="0" delete="1">
<form string="表面工艺" create="0" edit="1" delete="1">
<sheet>
<div class="oe_title">
<h1>

View File

@@ -32,8 +32,8 @@ class QuickEasyOrder(models.Model):
('0.01', '±0.01mm')], string='加工精度', default='0.10')
material_id = fields.Many2one('sf.production.materials', '材料', compute='_compute_material_model', store=True)
material_model_id = fields.Many2one('sf.materials.model', '型号', compute='_compute_material_model', store=True)
process_id = fields.Many2one('sf.production.process', string='表面工艺')
parameter_ids = fields.One2many('sf.production.process.parameter', 'process_id', string='可选参数')
# process_id = fields.Many2one('sf.production.process', string='表面工艺')
parameter_ids = fields.Many2many('sf.production.process.parameter', 'process_item_order_rel', string='可选参数')
quantity = fields.Integer('数量', default=1)
unit_price = fields.Float('单价')
price = fields.Float('总价')
@@ -49,6 +49,11 @@ class QuickEasyOrder(models.Model):
('success', '成功'),
('fail', '失败')], string='模型上色状态')
@api.depends('unit_price', 'quantity')
def _compute_total_amount(self):
for item in self:
item.price = item.unit_price * item.quantity
@api.depends('material_id', 'material_model_id')
def _compute_material_model(self):
for item in self:
@@ -75,18 +80,18 @@ class QuickEasyOrder(models.Model):
logging.info('create-model_file:%s' % len(vals['model_file']))
obj = super(QuickEasyOrder, self).create(vals)
self.model_coloring()
self.model_coloring(obj)
self.distribute_to_factory(obj)
return obj
# 将attach的datas内容转为glb文件
def transition_glb_file(self, report_path, model_code):
shapes = read_step_file(report_path)
#output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl')
# output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl')
output_file = os.path.join('/tmp', str(model_code) + '.stl')
write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)
# 转化为glb
#output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb')
# output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb')
output_glb_file = os.path.join('/tmp', str(model_code) + '.glb')
util_path = get_resource_path('sf_dlm', 'static/util')
cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file)
@@ -137,62 +142,106 @@ class QuickEasyOrder(models.Model):
派单到工厂
:return:
"""
web_base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='')
logging.info("web_base_url: %s" % web_base_url)
url = '/api/bfm_process_order/list'
res = {'order_number': obj.name, 'delivery_end_date': str(datetime.now()),
'delivery_name': 'XXXXX', 'delivery_telephone': 'XXXXX',
'delivery_address': 'XXXXX',
'bfm_process_order_list': []}
factory = self.env['res.partner'].sudo().search([], limit=1, order='id desc')
config_header = Common.get_headers(self, factory.sf_token, factory.sf_secret_key)
for item in obj:
attachment = item.upload_model_file[0]
base64_data = base64.b64encode(attachment.datas)
base64_datas = base64_data.decode('utf-8')
barcode = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest()
logging.info('model_file-size: %s' % len(item.model_file))
val = {
'model_long': item.model_length,
'model_width': item.model_width,
'model_height': item.model_height,
'model_volume': item.model_volume,
'model_machining_precision': item.machining_precision,
'model_name': attachment.name,
'model_data': base64_datas,
'model_file': base64.b64encode(item.model_file).decode('utf-8'),
'texture_code': item.material_id.materials_no,
'texture_type_code': item.material_model_id.materials_no,
# 'surface_process_code': self.env['jikimo.surface.process']._json_surface_process_code(item),
# 'process_parameters_code': self.env['jikimo.surface.process.item']._json_surface_process_item_code(
# item),
'price': item.price,
'number': item.quantity,
'total_amount': item.price,
'remark': '',
'barcode': barcode
}
res['bfm_process_order_list'].append(val)
res['bfm_process_order_list'] = json.dumps(res['bfm_process_order_list'])
try:
ret = requests.post((web_base_url[0] + url), json={}, data=res,
headers=config_header)
ret = ret.json()
if ret['status'] == 1:
self.write(
{'state': '待接单'})
else:
raise UserError(ret['message'])
res = {'bfm_process_order_list': []}
for item in obj:
attachment = item.upload_model_file[0]
base64_data = base64.b64encode(attachment.datas)
base64_datas = base64_data.decode('utf-8')
barcode = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest()
logging.info('model_file-size: %s' % len(item.model_file))
res['bfm_process_order_list'].append({
'model_long': item.model_length,
'model_width': item.model_width,
'model_height': item.model_height,
'model_volume': item.model_volume,
'model_machining_precision': item.machining_precision,
'model_name': attachment.name,
'model_data': base64_datas,
'model_file': base64.b64encode(item.model_file).decode('utf-8'),
'texture_code': item.material_id.materials_no,
'texture_type_code': item.material_model_id.materials_no,
# 'surface_process_code': self.env['jikimo.surface.process']._json_surface_process_code(item),
'process_parameters_code': self.env[
'sf.production.process.parameter']._json_production_process_item_code(
item),
'price': item.price,
'number': item.quantity,
'total_amount': item.price,
'remark': '',
'barcode': barcode
})
# res['bfm_process_order_list'] = json.dumps(res['bfm_process_order_list'])
product_id = self.env.ref('sf_dlm.product_template_sf').sudo()
self_machining_id = self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
outsource_id = self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
purchase_id = self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
company_id = self.env.ref('base.main_company').sudo()
# user_id = request.env.ref('base.user_admin').sudo()
order_id = self.env['sale.order'].sale_order_create(company_id, 'XXXXX', 'XXXXX', 'XXXXX',
str(datetime.now()))
i = 1
# 给sale_order的default_code字段赋值
aa = self.env['sale.order'].sudo().search([('name', '=', order_id.name)])
aa.default_code = obj.name
for item in res['bfm_process_order_list']:
product = self.env['product.template'].sudo().product_create(product_id, item, order_id,
obj.name, i)
bom_data = self.env['mrp.bom'].get_bom(product)
logging.info('bom_data:%s' % bom_data)
if bom_data:
bom = self.env['mrp.bom'].bom_create(product, 'normal', False)
bom.bom_create_line_has(bom_data)
else:
if product.materials_type_id.gain_way == '自加工':
# 创建坯料
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
self_machining_id,
item, order_id,
'self_machining',
i)
# 创建坯料的bom
self_machining_bom = self.env['mrp.bom'].bom_create(self_machining_embryo, 'normal', False)
# 创建坯料里bom的组件
self_machining_bom_line = self_machining_bom.bom_create_line(self_machining_embryo)
if self_machining_bom_line == False:
self.cr.rollback()
return UserError('该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配')
# 产品配置bom
product_bom_self_machining = self.env['mrp.bom'].bom_create(product, 'normal', False)
product_bom_self_machining.bom_create_line_has(self_machining_embryo)
elif product.materials_type_id.gain_way == '外协':
# 创建坯料
outsource_embryo = self.env['product.template'].sudo().no_bom_product_create(outsource_id, item,
order_id,
'subcontract', i)
# 创建坯料的bom
outsource_bom = self.env['mrp.bom'].bom_create(outsource_embryo, 'subcontract', True)
# 创建坯料的bom的组件
outsource_bom_line = outsource_bom.with_user(
self.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
if outsource_bom_line == False:
self.cr.rollback()
return UserError('该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配')
# 产品配置bom
product_bom_outsource = self.env['mrp.bom'].bom_create(product, 'normal', False)
product_bom_outsource.bom_create_line_has(outsource_embryo)
elif product.materials_type_id.gain_way == '采购':
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id, item,
order_id,
'purchase', i)
# 产品配置bom
product_bom_purchase = self.env['mrp.bom'].bom_create(product, 'normal', False)
product_bom_purchase.bom_create_line_has(purchase_embryo)
order_id.with_user(self.env.ref("base.user_admin")).sale_order_create_line(product, item)
except Exception as e:
if ret['status'] != 1:
raise UserError(e)
else:
raise UserError("分配工厂失败,请联系管理员")
self.cr.rollback()
return 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,
@@ -200,11 +249,10 @@ class QuickEasyOrder(models.Model):
return ret
# 模型上色
def model_coloring(self):
def model_coloring(self, order):
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'])
order = self.search([('id', '=', self.id)])
logging.info('order: %s' % order.name)
if order:
attachment = order.upload_model_file[0]
@@ -252,11 +300,13 @@ class QuickEasyOrder(models.Model):
vals['accuracy'] = order.machining_precision
vals['number'] = order.quantity
vals['process_code'] = 0
vals['texture_code'] = order.material_model_id.code
vals['texture_code'] = order.material_model_id.materials_no
vals['delivery_days'] = 15
if order.model_file:
attachment = self.env['ir.attachment'].sudo().search(
[('id', '=', order.upload_model_file[0])])
for item in order.upload_model_file:
if item.ids[0]:
logging.info('create-attachment:%s' % int(item.ids[0]))
attachment = self.env['ir.attachment'].sudo().search([('id', '=', int(item.ids[0]))])
vals['attachment_id'] = attachment.id
else:
vals['attachment_id'] = ''

View File

@@ -19,7 +19,7 @@
<field optional="show" name="customer_id" string="客户"/>
<field optional="show" name="material_id"/>
<field optional="show" name="material_model_id"/>
<field optional="show" name="process_id"/>
<field optional="show" name="parameter_ids"/>
<field optional="show" name="quantity"/>
<field optional="show" name="price"/>
<field optional="hide" name="delivery_time"/>
@@ -41,8 +41,8 @@
<field name="customer_id" readonly="1" force_save="1"/>
<field name="material_id"/>
<field name="material_model_id"/>
<field name="process_id"/>
<field name="parameter_ids" widget="many2many_tags"/>
<!-- <field name="process_id"/>-->
<field name="parameter_ids" widget="many2many_tags" string="表面工艺参数"/>
<field name="machining_precision"/>
<field name="quantity"/>
<field name="unit_price"/>

View File

@@ -18,5 +18,6 @@
'web.assets_backend': [
'web_widget_model_viewer/static/src/js/*',
],
}
},
'license': 'LGPL-3',
}