Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/commercially_launched

This commit is contained in:
mgw
2025-03-25 10:35:00 +08:00
3 changed files with 34 additions and 27 deletions

View File

@@ -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',

View File

@@ -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 != '离线'
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 != '离线'
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,))
@@ -1163,23 +1166,23 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute("""
SELECT * FROM device_data
WHERE device_name = %s
AND EXTRACT(YEAR FROM time) = EXTRACT(YEAR FROM CURRENT_DATE)
AND EXTRACT(MONTH FROM time) = EXTRACT(MONTH FROM CURRENT_DATE)
AND device_state != '离线'
AND time >= DATE_TRUNC('MONTH', CURRENT_DATE)
AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH'
AND device_state in ('待机', '警告', '运行中')
ORDER BY time ASC
LIMIT 1;
""", (item,))
first_month = fetch_result_as_dict(cur)
# print("当月第一条记录(非离线):", first_month)
# print("当月第一条记录:", first_month)
# 获取当月最新一条记录排除device_state等于离线的记录
# 获取当月最新一条记录
with conn.cursor() as cur:
cur.execute("""
SELECT * FROM device_data
WHERE device_name = %s
AND EXTRACT(YEAR FROM time) = EXTRACT(YEAR FROM CURRENT_DATE)
AND EXTRACT(MONTH FROM time) = EXTRACT(MONTH FROM CURRENT_DATE)
AND device_state != '离线'
AND time >= DATE_TRUNC('MONTH', CURRENT_DATE)
AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH'
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 != '离线'
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 != '离线'
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 != '离线' 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 != '离线' 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))

View File

@@ -18,7 +18,7 @@
<div style="position: absolute; top: 0; right: 0; text-align: right;">
<img t-att-src="'/report/barcode/QR/%s' % o.get_report_url()" style="width:100px;height:100px"/>
<div style="font-size: 14px; margin-top: 5px;">
报告编号:<span t-if="o.report_number_id" t-field="o.report_number_id"/><span t-else="">ceshi</span>
报告编号:<span t-if="o.report_number_id" t-field="o.report_number_name"/><span t-else="">ceshi</span>
</div>
<div style="font-size: 12px; margin-top: 5px;">
扫描二维码查看PDF报告