diff --git a/quality_control/models/quality.py b/quality_control/models/quality.py index df4a11b2..95c11451 100644 --- a/quality_control/models/quality.py +++ b/quality_control/models/quality.py @@ -180,8 +180,14 @@ class QualityCheck(models.Model): # 出厂检验报告编号 report_number_id = fields.Many2one('documents.document', string='出厂检验报告编号', readonly=True) + report_number_name = fields.Char('出厂检验报告编号名称', compute='_compute_report_number_name') - old_report_name = fields.Char('旧出厂检验报告编号', default='') + @api.depends('serial_number', 'part_number') + def _compute_report_number_name(self): + for record in self: + str_serial_number = '0' + str(record.serial_number) if record.serial_number < 10 else str(record.serial_number) + str_part_number = record.part_number if record.part_number else '' + record.report_number_name = f'FQC{str_part_number}{str_serial_number}' # 出厂检验报告、关联文档的数据 report_content = fields.Binary(string='出厂检验报告', related='report_number_id.datas') @@ -303,11 +309,9 @@ class QualityCheck(models.Model): if self.serial_number > 99: raise UserError(_('流水号不能大于99')) - str_serial_number = '0' + str(self.serial_number) if self.serial_number < 10 else str(self.serial_number) - str_part_number = self.part_number if self.part_number else '' # 3. 创建文档记录 doc_vals = { - 'name': f'FQC{str_part_number}{str_serial_number}', + 'name': self.report_number_name, 'raw': pdf_content, # 'attachment_id': attachment.id, 'mimetype': 'application/pdf', diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 944eb5a0..0c91846b 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -566,7 +566,8 @@ class Sf_Dashboard_Connect(http.Controller): :return: """ res = {'status': 1, 'message': '成功', 'data': {}} - plan_obj = request.env['sf.production.plan'].sudo() + # plan_obj = request.env['sf.production.plan'].sudo() + plan_obj = request.env['mrp.production'].sudo() line_list = ast.literal_eval(kw['line_list']) begin_time_str = kw['begin_time'].strip('"') end_time_str = kw['end_time'].strip('"') @@ -604,7 +605,7 @@ class Sf_Dashboard_Connect(http.Controller): return date_list for line in line_list: - date_field_name = 'actual_end_time' # 替换为你模型中的实际字段名 + date_field_name = 'date_finished' # 替换为你模型中的实际字段名 order_counts = [] if time_unit == 'hour': @@ -618,7 +619,7 @@ class Sf_Dashboard_Connect(http.Controller): orders = plan_obj.search([ ('production_line_id.name', '=', line), - ('state', 'in', ['finished']), + ('state', 'in', ['done']), (date_field_name, '>=', start_time.strftime('%Y-%m-%d %H:%M:%S')), (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间 ]) @@ -637,18 +638,18 @@ class Sf_Dashboard_Connect(http.Controller): for date in date_list: next_day = date + timedelta(days=1) - orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'in', ['finished']), + orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'in', ['done']), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) ]) rework_orders = plan_obj.search( - [('production_line_id.name', '=', line), ('production_id.state', 'in', ['rework']), + [('production_line_id.name', '=', line), ('state', 'in', ['rework']), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) ]) not_passed_orders = plan_obj.search( - [('production_line_id.name', '=', line), ('production_id.state', 'in', ['scrap', 'cancel']), + [('production_line_id.name', '=', line), ('state', 'in', ['scrap', 'cancel']), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) ]) @@ -1129,8 +1130,9 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND time::date = CURRENT_DATE - AND device_state in ('离线') + AND time >= CURRENT_DATE -- 今日 00:00:00 + AND time < CURRENT_DATE + 1 -- 明日 00:00:00 + AND device_state in ('待机', '警告', '运行中') ORDER BY time ASC LIMIT 1; """, (item,)) @@ -1142,8 +1144,9 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND time::date = CURRENT_DATE - AND device_state in ('离线') + AND time >= CURRENT_DATE -- 今日 00:00:00 + AND time < CURRENT_DATE + 1 -- 明日 00:00:00 + AND device_state in ('待机', '警告', '运行中') ORDER BY time DESC LIMIT 1; """, (item,)) @@ -1161,11 +1164,11 @@ class Sf_Dashboard_Connect(http.Controller): # 获取当月第一条记录(排除device_state等于‘离线’的记录) with conn.cursor() as cur: cur.execute(""" - SELECT * FROM device_datas + SELECT * FROM device_data WHERE device_name = %s AND time >= DATE_TRUNC('MONTH', CURRENT_DATE) AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH' - AND device_state in ('离线') + AND device_state in ('待机', '警告', '运行中') ORDER BY time ASC LIMIT 1; """, (item,)) @@ -1179,7 +1182,7 @@ class Sf_Dashboard_Connect(http.Controller): WHERE device_name = %s AND time >= DATE_TRUNC('MONTH', CURRENT_DATE) AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH' - AND device_state in ('离线') + AND device_state in ('待机', '警告', '运行中') ORDER BY time DESC LIMIT 1; """, (item,)) @@ -1200,7 +1203,7 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND device_state in ('离线') + AND device_state in ('待机', '警告', '运行中') ORDER BY time ASC LIMIT 1; """, (item,)) @@ -1212,7 +1215,7 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND device_state in ('离线') + AND device_state in ('待机', '警告', '运行中') ORDER BY time DESC LIMIT 1; """, (item,)) @@ -1290,7 +1293,7 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND device_state in ('离线') AND process_time IS NOT NULL + AND device_state in ('待机', '警告', '运行中') AND process_time IS NOT NULL ORDER BY time DESC LIMIT 1; """, (item,)) @@ -1299,7 +1302,7 @@ class Sf_Dashboard_Connect(http.Controller): cur.execute(""" SELECT * FROM device_data WHERE device_name = %s - AND device_state in ('离线') AND time >= %s AND process_time IS NOT NULL + AND device_state in ('待机', '警告', '运行中') AND time >= %s AND process_time IS NOT NULL ORDER BY time ASC LIMIT 1; """, (item, time_threshold)) diff --git a/sf_quality/data/insepection_report_template.xml b/sf_quality/data/insepection_report_template.xml index cd7998a3..f605b3e4 100644 --- a/sf_quality/data/insepection_report_template.xml +++ b/sf_quality/data/insepection_report_template.xml @@ -18,7 +18,7 @@