出厂检验报告上传模板后-没有自动新增有数值的列
This commit is contained in:
@@ -24,6 +24,7 @@ class ImportComplexModelWizard(models.TransientModel):
|
|||||||
file_data = fields.Binary("数据文件")
|
file_data = fields.Binary("数据文件")
|
||||||
model_name = fields.Char(string='Model Name')
|
model_name = fields.Char(string='Model Name')
|
||||||
field_basis = fields.Char(string='Field Basis')
|
field_basis = fields.Char(string='Field Basis')
|
||||||
|
check_id = fields.Many2one(string='质检单', comodel_name='quality.check')
|
||||||
|
|
||||||
def get_model_column_name_labels(self, model):
|
def get_model_column_name_labels(self, model):
|
||||||
fields_info = model.fields_get()
|
fields_info = model.fields_get()
|
||||||
@@ -97,6 +98,9 @@ class ImportComplexModelWizard(models.TransientModel):
|
|||||||
if not self.file_data:
|
if not self.file_data:
|
||||||
raise UserError(_('请先上传Excel文件'))
|
raise UserError(_('请先上传Excel文件'))
|
||||||
|
|
||||||
|
if self.check_id.measure_line_ids:
|
||||||
|
self.sudo().check_id.measure_line_ids.unlink()
|
||||||
|
|
||||||
# 解码文件数据
|
# 解码文件数据
|
||||||
file_content = base64.b64decode(self.file_data)
|
file_content = base64.b64decode(self.file_data)
|
||||||
|
|
||||||
@@ -156,6 +160,7 @@ class ImportComplexModelWizard(models.TransientModel):
|
|||||||
valid_data_imported = False
|
valid_data_imported = False
|
||||||
|
|
||||||
# 从第二行开始读取数据(跳过表头)
|
# 从第二行开始读取数据(跳过表头)
|
||||||
|
max_columns = 1
|
||||||
for row_index in range(1, sheet.nrows):
|
for row_index in range(1, sheet.nrows):
|
||||||
row = sheet.row_values(row_index)
|
row = sheet.row_values(row_index)
|
||||||
|
|
||||||
@@ -182,9 +187,16 @@ class ImportComplexModelWizard(models.TransientModel):
|
|||||||
'remark': row[10] if len(row) > 10 and row[10] else '', # 备注列
|
'remark': row[10] if len(row) > 10 and row[10] else '', # 备注列
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i in range(1, 6):
|
||||||
|
if measure_line_vals.get(f'measure_value{i}'):
|
||||||
|
if i > max_columns:
|
||||||
|
max_columns = i
|
||||||
|
|
||||||
self.env['quality.check.measure.line'].create(measure_line_vals)
|
self.env['quality.check.measure.line'].create(measure_line_vals)
|
||||||
valid_data_imported = True
|
valid_data_imported = True
|
||||||
|
|
||||||
|
quality_check.column_nums = max_columns
|
||||||
|
|
||||||
# 检查是否有有效数据被导入
|
# 检查是否有有效数据被导入
|
||||||
if not valid_data_imported:
|
if not valid_data_imported:
|
||||||
raise UserError(_('表格中没有有效数据行可导入,请检查表格内容'))
|
raise UserError(_('表格中没有有效数据行可导入,请检查表格内容'))
|
||||||
|
|||||||
Reference in New Issue
Block a user