增加交付准时率
This commit is contained in:
@@ -6,7 +6,7 @@ import base64
|
|||||||
import logging
|
import logging
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from odoo import http
|
from odoo import http, fields
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
# 数据库连接配置
|
# 数据库连接配置
|
||||||
@@ -347,6 +347,32 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
# 工单进度偏差
|
# 工单进度偏差
|
||||||
plan_data_progress_deviation = plan_data_total_counts - plan_data_finish_counts - plan_data_fault_counts
|
plan_data_progress_deviation = plan_data_total_counts - plan_data_finish_counts - plan_data_fault_counts
|
||||||
|
|
||||||
|
# 交付准时率
|
||||||
|
plan_data_finish_orders = plan_obj.search(
|
||||||
|
[('production_line_id.name', '=', line), ('state', 'in', ['finished'])])
|
||||||
|
|
||||||
|
delay_num = 0
|
||||||
|
for plan in plan_data_finish_orders:
|
||||||
|
sale_obj = request.env['sale.order'].sudo().search([('name', '=', plan.origin)])
|
||||||
|
if sale_obj:
|
||||||
|
if sale_obj.deadline_of_delivery and plan.actual_end_time:
|
||||||
|
# 将 deadline_of_delivery 转换为字符串
|
||||||
|
date_as_string = sale_obj.deadline_of_delivery.strftime('%Y-%m-%d')
|
||||||
|
# 然后使用 strptime 将字符串转换为 datetime 对象
|
||||||
|
date_as_datetime = datetime.strptime(date_as_string, '%Y-%m-%d')
|
||||||
|
|
||||||
|
# 将 actual_end_time 转换为 datetime 对象
|
||||||
|
datetime_value = fields.Datetime.from_string(plan.actual_end_time)
|
||||||
|
|
||||||
|
# 给 datetime_value 加1天
|
||||||
|
new_datetime_value = datetime_value + timedelta(days=1)
|
||||||
|
|
||||||
|
# 比较 new_datetime_value 和 date_as_datetime 的大小
|
||||||
|
if new_datetime_value.date() > date_as_datetime.date():
|
||||||
|
delay_num += 1
|
||||||
|
delay_rate = round((delay_num / plan_data_finish_counts if plan_data_finish_counts > 0 else 0), 3)
|
||||||
|
on_time_rate = 1 - delay_rate
|
||||||
|
|
||||||
if plan_data:
|
if plan_data:
|
||||||
data = {
|
data = {
|
||||||
'plan_data_total_counts': plan_data_total_counts,
|
'plan_data_total_counts': plan_data_total_counts,
|
||||||
@@ -355,7 +381,8 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
'plan_data_fault_counts': plan_data_fault_counts,
|
'plan_data_fault_counts': plan_data_fault_counts,
|
||||||
'finishe_rate': finishe_rate,
|
'finishe_rate': finishe_rate,
|
||||||
'plan_data_progress_deviation': plan_data_progress_deviation,
|
'plan_data_progress_deviation': plan_data_progress_deviation,
|
||||||
'plan_data_rework_counts': plan_data_rework_counts
|
'plan_data_rework_counts': plan_data_rework_counts,
|
||||||
|
'on_time_rate': on_time_rate
|
||||||
}
|
}
|
||||||
res['data'][line] = data
|
res['data'][line] = data
|
||||||
|
|
||||||
@@ -514,10 +541,15 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
for line in line_list:
|
for line in line_list:
|
||||||
# 未完成订单
|
# 未完成订单
|
||||||
not_done_orders = plan_obj.search(
|
not_done_orders = plan_obj.search(
|
||||||
[('production_line_id.name', '=', line), ('state', 'not in', ['finished'])])
|
[('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
|
||||||
|
('production_id.state', 'not in', ['cancel']), ('active', '=', True)
|
||||||
|
])
|
||||||
print(not_done_orders)
|
print(not_done_orders)
|
||||||
# 完成订单
|
# 完成订单
|
||||||
finish_orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'in', ['finished'])])
|
finish_orders = plan_obj.search([
|
||||||
|
('production_line_id.name', '=', line), ('state', 'in', ['finished']),
|
||||||
|
('production_id.state', 'not in', ['cancel']), ('active', '=', True)
|
||||||
|
])
|
||||||
print(finish_orders)
|
print(finish_orders)
|
||||||
|
|
||||||
# 获取所有未完成订单的ID列表
|
# 获取所有未完成订单的ID列表
|
||||||
|
|||||||
Reference in New Issue
Block a user