diff --git a/jikimo_test_generate_product_name/__init__.py b/jikimo_test_generate_product_name/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/jikimo_test_generate_product_name/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/jikimo_test_generate_product_name/__manifest__.py b/jikimo_test_generate_product_name/__manifest__.py new file mode 100644 index 00000000..b7fd24a2 --- /dev/null +++ b/jikimo_test_generate_product_name/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Jikimo_test_generate_product_name', + 'version': '', + 'summary': """ Jikimo_test_generate_product_name Summary """, + 'author': '', + 'website': '', + 'category': '', + 'depends': ['sf_manufacturing'], + 'data': [ + + ], + + 'application': True, + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/jikimo_test_generate_product_name/models/__init__.py b/jikimo_test_generate_product_name/models/__init__.py new file mode 100644 index 00000000..2757b3ab --- /dev/null +++ b/jikimo_test_generate_product_name/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import product_template diff --git a/jikimo_test_generate_product_name/models/product_template.py b/jikimo_test_generate_product_name/models/product_template.py new file mode 100644 index 00000000..3aa48be6 --- /dev/null +++ b/jikimo_test_generate_product_name/models/product_template.py @@ -0,0 +1,21 @@ +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + def generate_product_name(self, order_id, item, i): + """生成成品名称""" + # 3D文件名(去掉后缀,截取前40个字符)+“-”+模型ID + product_name = '%s-%s' % ('.'.join(item['model_name'].split('.')[:-1])[:40], item['model_id']) + return product_name + + def generate_embryo_name(self, order_id, item, materials_id, materials_type_id, embryo_redundancy_id, i): + """生成坯料名称""" + embryo_name = '%s-%s-%s [%s %s-%s * %s * %s]' % ('R', + order_id.name, i, materials_id.name, materials_type_id.name, + self.format_float(item['model_long'] + embryo_redundancy_id.long), + self.format_float(item['model_width'] + embryo_redundancy_id.width), + self.format_float(item['model_height'] + embryo_redundancy_id.height)) + return embryo_name + \ No newline at end of file diff --git a/sf_bf_connect/models/http.py b/sf_bf_connect/models/http.py index e70d5e79..b106384a 100644 --- a/sf_bf_connect/models/http.py +++ b/sf_bf_connect/models/http.py @@ -2,7 +2,7 @@ import logging from datetime import datetime, timedelta import hashlib -from odoo import models +from odoo import models, SUPERUSER_ID from odoo.http import request __author__ = 'jinling.yang' @@ -48,5 +48,7 @@ class Http(models.AbstractModel): _logger.info('sf_secret_key:%s' % factory_secret.sf_secret_key) if check_sf_str != datas['HTTP_CHECKSTR']: raise AuthenticationError('数据校验不通过') + # 设置管理员用户 + request.update_env(user=SUPERUSER_ID) else: raise AuthenticationError('请求参数中无token') diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 19bce23f..242e0ff4 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -890,8 +890,9 @@ class ResProductMo(models.Model): embryo_redundancy_id = item.get('embryo_redundancy') if not embryo_redundancy_id: raise UserError('请先配置模型类型内的坯料冗余') + product_name = self.generate_product_name(order_id, item, i) vals = { - 'name': '%s-%s-%s' % ('P', order_id.name, i), + 'name': product_name, 'model_long': self.format_float(item['model_long'] + embryo_redundancy_id.long), 'model_width': self.format_float(item['model_width'] + embryo_redundancy_id.width), 'model_height': self.format_float(item['model_height'] + embryo_redundancy_id.height), @@ -1012,12 +1013,9 @@ class ResProductMo(models.Model): if not embryo_redundancy_id: raise UserError('请先配置模型类型内的坯料冗余') logging.info('no_bom_copy_product_supplier-vals:%s' % supplier) + embryo_name = self.generate_embryo_name(order_id, item, materials_id, materials_type_id, embryo_redundancy_id, i) vals = { - 'name': '%s-%s-%s [%s %s-%s * %s * %s]' % ('R', - order_id.name, i, materials_id.name, materials_type_id.name, - self.format_float(item['model_long'] + embryo_redundancy_id.long), - self.format_float(item['model_width'] + embryo_redundancy_id.width), - self.format_float(item['model_height'] + embryo_redundancy_id.height)), + 'name': embryo_name, 'length': self.format_float(item['model_long'] + embryo_redundancy_id.long), 'width': self.format_float(item['model_width'] + embryo_redundancy_id.width), 'height': self.format_float(item['model_height'] + embryo_redundancy_id.height), @@ -1119,7 +1117,19 @@ class ResProductMo(models.Model): # 增加产品表面积 + def generate_product_name(self, order_id, item, i): + """生成成品名称""" + product_name = '%s-%s-%s' % ('P', order_id.name, i), + return product_name + def generate_embryo_name(self, order_id, item, materials_id, materials_type_id, embryo_redundancy_id, i): + """生成坯料名称""" + embryo_name = '%s-%s-%s [%s %s-%s * %s * %s]' % ('R', + order_id.name, i, materials_id.name, materials_type_id.name, + self.format_float(item['model_long'] + embryo_redundancy_id.long), + self.format_float(item['model_width'] + embryo_redundancy_id.width), + self.format_float(item['model_height'] + embryo_redundancy_id.height)) + return embryo_name class ResProductFixture(models.Model): _inherit = 'product.template'