From 5f218e69d4793d9915c5b5c8db111a120631a5a7 Mon Sep 17 00:00:00 2001 From: hujiaying Date: Thu, 5 Sep 2024 17:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=8E=92=E7=A8=8B=E8=80=83?= =?UTF-8?q?=E8=99=91CNC=E7=94=9F=E4=BA=A7=E7=BA=BF=E6=97=A5=E4=BA=A7?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E4=BC=98=E5=8C=96=E9=9C=80=E6=B1=82,?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=AF=E7=94=A8=E6=9C=BA=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=8C=E5=8D=95=E5=8F=B0=E5=B0=8F=E6=97=B6=E4=BA=A7?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=97=A5=E6=9C=89=E6=95=88=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E8=AE=A1=E7=AE=97=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workcenter.py | 45 +++++++- .../views/mrp_workcenter_views.xml | 101 +++++++++++------- 2 files changed, 103 insertions(+), 43 deletions(-) diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 03597980..ecb29ad7 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -1,6 +1,6 @@ import datetime from collections import defaultdict -from odoo import fields, models +from odoo import fields, models, api from odoo.addons.resource.models.resource import Intervals @@ -41,14 +41,16 @@ class ResWorkcenter(models.Model): oee_target = fields.Float( string='OEE Target', help="Overall Effective Efficiency Target in percentage", default=90, tracking=True) - oee = fields.Float(compute='_compute_oee', help='Overall Equipment Effectiveness, based on the last month', store=True) + oee = fields.Float(compute='_compute_oee', help='Overall Equipment Effectiveness, based on the last month', + store=True) time_start = fields.Float('Setup Time', tracking=True) time_stop = fields.Float('Cleanup Time', tracking=True) costs_hour = fields.Float(string='Cost per hour', help='Hourly processing cost.', default=0.0, tracking=True) equipment_status = fields.Selection( - [("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"), ("空闲", "空闲"), ("封存(报废)", "封存(报废)")], + [("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"), ("空闲", "空闲"), + ("封存(报废)", "封存(报废)")], string="设备状态", related='equipment_id.state') # @api.depends('equipment_id') @@ -127,6 +129,43 @@ class ResWorkcenter(models.Model): # AGV是否可配送 is_agv_scheduling = fields.Boolean(string="AGV所属区域", tracking=True) + # 生产线优化 + available_machine_number = fields.Integer(string="可用机台数量") + single_machine_capacity = fields.Float(string="单台小时产能") + production_line_hour_capacity = fields.Float(string="生产线小时产能", readonly=True, + _compute='_compute_production_line_hour_capacity') + effective_working_hours_day = fields.Float(string="日有效工作时长", default=0, readonly=True, + _compute='_compute_effective_working_hours_day') + default_capacity = fields.Float( + '生产线日产能', default=2.0, _compute='_compute_production_line_day_capacity', readonly=True) + + # 计算生产线日产能 + @api.depends('production_line_hour_capacity', 'effective_working_hours_day') + def _compute_production_line_day_capacity(self): + for record in self: + record.default_capacity = round( + record.production_line_hour_capacity * record.effective_working_hours_day, 2) + + # 计算日有效工作时长 + @api.depends('attendance_ids', 'attendance_ids.hour_to', 'attendance_ids.hour_from') + def _compute_effective_working_hours_day(self): + for record in self: + attendance_ids = record.resource_calendar_id.attendance_ids.filter( + lambda r: r.dayofweek == datetime.now().weekday()) + if attendance_ids: + for attendance_id in attendance_ids: + if attendance_id.hour_from and attendance_id.hour_to: + record.effective_working_hours_day += attendance_id.hour_to - attendance_id.hour_from + else: + record.effective_working_hours_day = 0 + + # 计算生产线小时产能 + @api.depends('single_machine_capacity', 'available_machine_number') + def _compute_production_line_hour_capacity(self): + for record in self: + record.production_line_hour_capacity = round( + record.single_machine_capacity * record.available_machine_number, 2) + class ResWorkcenterProductivity(models.Model): _inherit = 'mrp.workcenter.productivity' diff --git a/sf_manufacturing/views/mrp_workcenter_views.xml b/sf_manufacturing/views/mrp_workcenter_views.xml index d0b4bee6..aad35d04 100644 --- a/sf_manufacturing/views/mrp_workcenter_views.xml +++ b/sf_manufacturing/views/mrp_workcenter_views.xml @@ -6,9 +6,9 @@ mrp.production - - - + + +