优化产量部分
This commit is contained in:
@@ -301,21 +301,21 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
plan_obj = request.env['sf.production.plan'].sudo()
|
plan_obj = request.env['sf.production.plan'].sudo()
|
||||||
|
production_obj = request.env['mrp.production'].sudo()
|
||||||
line_list = ast.literal_eval(kw['line_list'])
|
line_list = ast.literal_eval(kw['line_list'])
|
||||||
print('line_list: %s' % line_list)
|
print('line_list: %s' % line_list)
|
||||||
for line in line_list:
|
for line in line_list:
|
||||||
plan_data = plan_obj.search([('production_line_id.name', '=', line)])
|
|
||||||
# 工单总量
|
# 工单计划量
|
||||||
plan_data_total_counts = plan_obj.search_count([('production_line_id.name', '=', line)])
|
plan_data_total_counts = production_obj.search_count(
|
||||||
|
[('production_line_id.name', '=', line), ('state', 'not in', ['cancel']),
|
||||||
|
('active', '=', True)])
|
||||||
# 工单完成量
|
# 工单完成量
|
||||||
plan_data_finish_counts = plan_obj.search_count(
|
plan_data_finish_counts = plan_obj.search_count(
|
||||||
[('production_line_id.name', '=', line), ('state', 'in', ['finished'])])
|
[('production_line_id.name', '=', line), ('state', 'in', ['finished'])])
|
||||||
# 工单计划量
|
# # 工单计划量
|
||||||
plan_data_plan_counts = plan_obj.search_count(
|
# plan_data_plan_counts = plan_obj.search_count(
|
||||||
[('production_line_id.name', '=', line), ('state', 'not in', ['finished'])])
|
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])])
|
||||||
# # 工单不良累计
|
|
||||||
# plan_data_fault_counts = plan_obj.search_count(
|
|
||||||
# [('production_line_id.name', '=', line), ('production_id.detection_result_ids.state', 'in', ['返工', '报废'])])
|
|
||||||
|
|
||||||
# 查找符合条件的生产计划记录
|
# 查找符合条件的生产计划记录
|
||||||
plan_data = plan_obj.search([
|
plan_data = plan_obj.search([
|
||||||
@@ -327,8 +327,13 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
result.test_results in ['返工', '报废'] for result in p.production_id.detection_result_ids
|
result.test_results in ['返工', '报废'] for result in p.production_id.detection_result_ids
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# 查找制造订单取消与归档的数量
|
||||||
|
cancel_order_count = production_obj.search_count(
|
||||||
|
[('production_line_id.name', '=', line), ('state', 'in', ['cancel']),
|
||||||
|
('active', '=', False)])
|
||||||
|
|
||||||
# 计算符合条件的记录数量
|
# 计算符合条件的记录数量
|
||||||
plan_data_fault_counts = len(faulty_plans)
|
plan_data_fault_counts = len(faulty_plans) + cancel_order_count
|
||||||
|
|
||||||
# 工单返工数量
|
# 工单返工数量
|
||||||
|
|
||||||
@@ -340,13 +345,13 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
(plan_data_finish_counts / plan_data_total_counts if plan_data_total_counts > 0 else 0), 3)
|
(plan_data_finish_counts / plan_data_total_counts if plan_data_total_counts > 0 else 0), 3)
|
||||||
|
|
||||||
# 工单进度偏差
|
# 工单进度偏差
|
||||||
plan_data_progress_deviation = plan_data_finish_counts - plan_data_plan_counts
|
plan_data_progress_deviation = plan_data_total_counts - plan_data_finish_counts - plan_data_fault_counts
|
||||||
|
|
||||||
if plan_data:
|
if plan_data:
|
||||||
data = {
|
data = {
|
||||||
'plan_data_total_counts': plan_data_total_counts,
|
'plan_data_total_counts': plan_data_total_counts,
|
||||||
'plan_data_finish_counts': plan_data_finish_counts,
|
'plan_data_finish_counts': plan_data_finish_counts,
|
||||||
'plan_data_plan_counts': plan_data_plan_counts,
|
'plan_data_plan_counts': plan_data_total_counts,
|
||||||
'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,
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ class sf_production_plan(models.Model):
|
|||||||
('draft', '待排程'),
|
('draft', '待排程'),
|
||||||
('done', '已排程'),
|
('done', '已排程'),
|
||||||
('processing', '加工中'),
|
('processing', '加工中'),
|
||||||
('finished', '已完成')
|
('finished', '已完成'),
|
||||||
|
('cancel', '已取消')
|
||||||
], string='状态', tracking=True)
|
], string='状态', tracking=True)
|
||||||
|
|
||||||
state_order = fields.Integer(compute='_compute_state_order', store=True)
|
state_order = fields.Integer(compute='_compute_state_order', store=True)
|
||||||
@@ -37,7 +38,7 @@ class sf_production_plan(models.Model):
|
|||||||
_order = 'state_order asc, write_date desc'
|
_order = 'state_order asc, write_date desc'
|
||||||
|
|
||||||
name = fields.Char(string='制造订单')
|
name = fields.Char(string='制造订单')
|
||||||
# active = fields.Boolean(string='已归档', default=True)
|
active = fields.Boolean(string='已归档', default=True)
|
||||||
# selected = fields.Boolean(default=False)
|
# selected = fields.Boolean(default=False)
|
||||||
# order_number = fields.Char(string='订单号')
|
# order_number = fields.Char(string='订单号')
|
||||||
order_deadline = fields.Datetime(string='订单交期')
|
order_deadline = fields.Datetime(string='订单交期')
|
||||||
@@ -385,3 +386,23 @@ class machine_work_schedule(models.Model):
|
|||||||
_description = '机台作业计划'
|
_description = '机台作业计划'
|
||||||
|
|
||||||
name = fields.Char(string='机台名')
|
name = fields.Char(string='机台名')
|
||||||
|
|
||||||
|
|
||||||
|
class MrpProductionInheritForPlan(models.Model):
|
||||||
|
_inherit = 'mrp.production'
|
||||||
|
|
||||||
|
def button_cancel(self):
|
||||||
|
# 调用父类的取消操作
|
||||||
|
res = super(MrpProductionInheritForPlan, self).button_cancel()
|
||||||
|
# 更新 sf.production.plan 模型的 state 为 'cancel'
|
||||||
|
self.env['sf.production.plan'].search([('production_id', '=', self.id)]).write({'state': 'cancel'})
|
||||||
|
return res
|
||||||
|
|
||||||
|
def toggle_active(self):
|
||||||
|
# 调用父类方法切换 active 状态
|
||||||
|
res = super(MrpProductionInheritForPlan, self).toggle_active()
|
||||||
|
self.env['sf.production.plan'].search(
|
||||||
|
[('production_id', '=', self.id), '|', ('active', '=', False), ('active', '=', True)]).write(
|
||||||
|
{'active': self.active})
|
||||||
|
|
||||||
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user