调整模型上传的流程

This commit is contained in:
胡尧
2025-02-20 13:36:05 +08:00
parent 8095a8a972
commit 05dac9fb0c
8 changed files with 66 additions and 40 deletions

View File

@@ -16,13 +16,16 @@
<field name='categ_id' class="custom_required" attrs="{'readonly': [('id', '!=', False)]}"/>
<field name='is_bfm' invisible="1"/>
<field name='categ_type' invisible="1"/>
<field name='glb_url' invisible="1"/>
<field name='part_name' attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>
<field name='part_number' attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>
<field name='manual_quotation' attrs="{'invisible':[('upload_model_file', '=', [])]}"/>
<field name='manual_quotation' attrs="{'invisible':[('glb_url', '=', False)]}"/>
<field name="is_customer_provided" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
<field name="upload_model_file"
widget="many2many_binary"
attrs="{'invisible': ['|', '|',('categ_type', '!=', '成品'),('categ_type', '=', False),('is_bfm','=', True)]}"/>
<field name="model_name" invisible="1"/>
<field name="model_url"
widget="binary_download"
filename_field="model_name"
attrs="{'invisible': ['|', '|',('categ_type', '!=', '成品'),('categ_type', '=', False),('model_url', '=', False)]}"/>
<field name="model_file" widget="Viewer3D" string="模型" readonly="1" force_save="1"
attrs="{'invisible': ['|','|', ('categ_type', '!=', '成品'),('categ_type', '=', False),('model_file', '=', False)]}"/>
<field name='cutting_tool_type' invisible="1"/>
@@ -68,6 +71,7 @@
</field>
<xpath expr="//field[@name='uom_id']" position="before">
<field name="is_manual_processing" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
<field name="auto_machining" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
</xpath>
<xpath expr="//label[@for='volume']" position="before">
<label for="length" string="尺寸"

View File

@@ -682,14 +682,16 @@ class MrpProduction(models.Model):
'model_order_no': cnc.product_id.default_code,
'user': cnc.env.user.name,
'programme_way': programme_way,
'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
cnc.product_id.model_file).decode('utf-8'),
# 'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
# cnc.product_id.model_file).decode('utf-8'),
'glb_url': cnc.product_id.glb_url,
'part_name': cnc.product_id.part_name,
'part_number': cnc.product_id.part_number,
'machining_drawings': base64.b64encode(cnc.product_id.machining_drawings).decode(
'utf-8') if cnc.product_id.machining_drawings else '',
'machining_drawings_name': cnc.product_id.machining_drawings_name,
'machining_drawings_mimetype': cnc.product_id.machining_drawings_mimetype,
'model_id': cnc.product_id.model_id,
}
# 打印出除了 model_file 之外的所有键值对
for key, value in res.items():

View File

@@ -29,6 +29,7 @@ class ResProductMo(models.Model):
model_width = fields.Float('模型宽(mm)', digits=(16, 3))
model_height = fields.Float('模型高(mm)', digits=(16, 3))
model_volume = fields.Float('模型体积(m³)')
model_area = fields.Float('模型表面积(m²)')
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='加工精度')
model_processing_panel = fields.Char('模型加工面板')
model_remark = fields.Char('模型备注说明')
@@ -171,6 +172,7 @@ class ResProductMo(models.Model):
'压紧方式', domain=[('type', '=', '压紧方式')])
name = fields.Char('产品名称', compute='_compute_tool_name', store=True, required=False)
@api.constrains('seller_ids')
def _check_seller_ids(self):
@@ -780,6 +782,13 @@ class ResProductMo(models.Model):
part_number = fields.Char(string='零件图号', readonly=True)
machining_drawings_name = fields.Char(string='零件图号名称', readonly=True)
machining_drawings_mimetype = fields.Char(string='零件图号类型', readonly=True)
model_url = fields.Char('模型文件地址')
glb_url = fields.Char('glb文件地址')
area = fields.Float('表面积(m²)')
auto_machining = fields.Boolean('自动化加工(模型识别)', default=False)
model_id = fields.Char('模型id')
@api.constrains('tool_length')
def _check_tool_length_size(self):
if self.tool_length > 1000000:
@@ -850,7 +859,7 @@ class ResProductMo(models.Model):
copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy()
copy_product_id.product_tmpl_id.active = True
model_type = self.env['sf.model.type'].search([], limit=1)
attachment = self.attachment_create(item['model_name'], item['model_data'])
# attachment = self.attachment_create(item['model_name'], item['model_data'])
# 获取坯料冗余配置
if not item.get('embryo_redundancy'):
embryo_redundancy_id = model_type.embryo_tolerance_id
@@ -863,9 +872,8 @@ class ResProductMo(models.Model):
'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),
'model_volume': self.format_float((item['model_long'] + embryo_redundancy_id.long) * (
item['model_width'] + embryo_redundancy_id.width) * (
item['model_height'] + embryo_redundancy_id.height)),
'model_volume': self.format_float(item['blank_volume']),
'model_area': self.format_float(item['blank_area']),
'product_model_type_id': model_type.id,
'model_processing_panel': item['processing_panel_detail'],
'model_machining_precision': item['model_machining_precision'],
@@ -873,10 +881,14 @@ class ResProductMo(models.Model):
'length': item['model_long'],
'width': item['model_width'],
'height': item['model_height'],
'volume': item['model_long'] * item['model_width'] * item['model_height'],
'model_file': '' if not item['model_file'] else base64.b64decode(item['model_file']),
'model_name': attachment.name if attachment else None,
'upload_model_file': [(6, 0, [attachment.id])] if attachment else None,
'volume': item['model_volume'],
'area': item['model_area'],
# 'model_file': '' if not item['model_file'] else base64.b64decode(item['model_file']),
'model_url': item['model_url'],
'glb_url': item['glb_url'],
'model_name': item['model_name'],
'auto_machining': item['auto_machining'],
# 'upload_model_file': [(6, 0, [attachment.id])] if attachment else None,
'list_price': item['price'],
'materials_id': self.env['sf.production.materials'].search(
[('materials_no', '=', item['texture_code'])]).id,
@@ -896,6 +908,7 @@ class ResProductMo(models.Model):
'part_name': item.get('part_name') or '',
'machining_drawings_name': item.get('machining_drawings_name') or '',
'machining_drawings_mimetype': item.get('machining_drawings_mimetype') or '',
'model_id': item['model_id'],
}
tax_id = self.env['account.tax'].sudo().search(
[('type_tax_use', '=', 'sale'), ('amount', '=', item.get('tax')), ('price_include', '=', 'True')])
@@ -978,15 +991,14 @@ class ResProductMo(models.Model):
vals = {
'name': '%s-%s-%s [%s %s-%s * %s * %s]' % ('R',
order_id.name, i, materials_id.name, materials_type_id.name,
item['model_long'] + embryo_redundancy_id.long,
item['model_width'] + embryo_redundancy_id.width,
item['model_height'] + embryo_redundancy_id.height),
'length': item['model_long'] + embryo_redundancy_id.long,
'width': item['model_width'] + embryo_redundancy_id.width,
'height': item['model_height'] + embryo_redundancy_id.height,
'volume': (item['model_long'] + embryo_redundancy_id.long) * (
item['model_width'] + embryo_redundancy_id.width) * (
item['model_height'] + embryo_redundancy_id.height),
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)),
'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),
'volume': self.format_float(item['blank_volume']),
'area': self.format_float(item['blank_area']),
'embryo_model_type_id': model_type.id,
'list_price': item['price'],
'materials_id': materials_id.id,
@@ -1078,6 +1090,9 @@ class ResProductMo(models.Model):
image_data = fileObj.read()
base64_data = base64.b64encode(image_data)
return base64_data
# 增加产品表面积
class ResProductFixture(models.Model):

View File

@@ -51,13 +51,15 @@ class SaleOrder(models.Model):
order_id = self
product = line.product_id
# 拼接方法需要的item结构
# 拼接方法需要的item结构,成品的模型数据信息就是坯料的数据信息
item = {
'texture_code': product.materials_id.materials_no,
'texture_type_code': product.materials_type_id.materials_no,
'model_long': product.length,
'model_width': product.width,
'model_height': product.height,
'blank_volume': product.model_volume,
'blank_area': product.model_area,
'price': product.list_price,
'embryo_redundancy_id': line.embryo_redundancy_id,
}

View File

@@ -18,10 +18,6 @@
<xpath expr="//page/field[@name='order_line']/tree/field[@name='remark']" position="before">
<field name="supply_method" attrs="{'invisible': [('state', '=', 'draft')], 'required': [('state', '=', 'supply method')]}" />
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='model_glb_file']" position="before">
<field name="part_number" optional="show"/>
</xpath>
<xpath expr="//header/button[@name='action_cancel']" position="attributes">
<attribute name="attrs">{'invisible': [('state', '!=', 'draft')]}</attribute>
</xpath>

View File

@@ -138,11 +138,14 @@ class ReSaleOrder(models.Model):
product.materials_id.name),
'price_unit': product.list_price,
'product_uom_qty': item['number'],
'model_glb_file': base64.b64decode(item['model_file']) if item['model_file'] else None,
# 'model_glb_file': base64.b64decode(item['model_file']) if item['model_file'] else None,
'model_url': item['model_url'],
'glb_url': item['glb_url'],
'remark': item.get('remark'),
'embryo_redundancy_id': item.get('embryo_redundancy_id'),
'is_incoming_material': True if item.get('embryo_redundancy_id') else False,
'manual_quotation': item.get('manual_quotation')
'manual_quotation': item.get('manual_quotation'),
'model_id': item['model_id'],
}
return self.env['sale.order.line'].with_context(skip_procurement=True).create(vals)
@@ -261,6 +264,9 @@ class ResaleOrderLine(models.Model):
is_incoming_material = fields.Boolean('客供料', compute='_compute_is_incoming_material', store=True)
embryo_redundancy_id = fields.Many2one('sf.embryo.redundancy', '坯料冗余')
manual_quotation = fields.Boolean('人工编程', default=False)
model_url = fields.Char('模型文件地址')
glb_url = fields.Char('glb文件地址')
model_id = fields.Char('模型id')
@api.depends('embryo_redundancy_id')
def _compute_is_incoming_material(self):

View File

@@ -101,9 +101,9 @@
<!-- <field name="schedule_status" readonly="1"/> -->
</field>
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="before">
<field name="model_glb_file" widget="Viewer3D" optional="show"
string="模型文件" attrs="{'readonly': [('state', 'in', ['draft'])]}"/>
<field name="part_name" optional="hide"/>
<field name="glb_url" widget="Viewer3D" optional="show"
string="模型文件" readonly="1"/>
<field name="part_name" optional="show"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
<field name="remark"/>

View File

@@ -27,7 +27,10 @@ export class StepViewer extends Component {
formatUrl() {
var url = '';
if (this.props.value) {
if (this.props.value.slice(-1) == 'b' && !isNaN(this.props.value.split(' ')[0])) {
if (this.props.value.startsWith('http')) {
// 从url读取文件内容
url = this.props.value;
} else if (this.props.value.slice(-1) == 'b' && !isNaN(this.props.value.split(' ')[0])) {
var url_props = {
base_url: session['web.base.url'],
model: this.props.record.resModel,
@@ -37,21 +40,19 @@ export class StepViewer extends Component {
url = url_props['base_url'].replace('http://', 'https://') + '/web/content/' + url_props['model'] + '/' + url_props['id'] + '/' + url_props['field'] + '?download=true';
// url = 'http://localhost:8069'+'/web/content/'+url_props['model']+'/'+url_props['id']+'/'+url_props['field']+'?download=true'
// console.log('url111111', url)
return url;
} else {
url = "data:model/gltf-binary;base64," + this.props.value;
// console.log('url2', url)
return url;
// localStorage.setItem('url',url)
// let new_url = localStorage.getItem(('url'))
// var oViewer = document.getElementsByTagName('model-viewer')[0];
// return new_url
// url = "web_widget_model_viewer/static/src/images/not_model.png";
}
} else {
// var oImg = document.getElementsByClassName('test')[0]
// console.log(oImg)
}
}
return url;
}
}