sf计划排程计算生产线是否配置生产线,计算排程时间是否在工作时间内,计算生产线是否有可排程的资源,

This commit is contained in:
hujiaying
2024-09-06 17:48:27 +08:00
parent d123ca5173
commit 4560bbc0ed
3 changed files with 68 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import datetime
from datetime import time
from collections import defaultdict
from odoo import fields, models, api
from odoo.addons.resource.models.resource import Intervals
@@ -152,7 +153,7 @@ class ResWorkcenter(models.Model):
def _compute_effective_working_hours_day(self):
for record in self:
attendance_ids = [p for p in record.resource_calendar_id.attendance_ids if
p.dayofweek == self.get_current_day_of_week()]
p.dayofweek == self.get_current_day_of_week(datetime.datetime.now())]
if attendance_ids:
for attendance_id in attendance_ids:
if attendance_id.hour_from and attendance_id.hour_to:
@@ -160,9 +161,9 @@ class ResWorkcenter(models.Model):
else:
record.effective_working_hours_day = 0
def get_current_day_of_week(self):
day_num = datetime.datetime.now().weekday()
# 获取传入时间是星期几
def get_current_day_of_week(self, datetime):
day_num = datetime.weekday()
return str(day_num)
# 计算生产线小时产能
@@ -172,6 +173,44 @@ class ResWorkcenter(models.Model):
record.production_line_hour_capacity = round(
record.single_machine_capacity * record.available_machine_number, 2)
# 判断计划开始时间是否在配置的工作中心的工作日历内
def deal_with_workcenter_calendar(self, start_date):
for record in self:
attendance_ids = [p for p in record.resource_calendar_id.attendance_ids if
p.dayofweek == record.get_current_day_of_week(start_date) and self.is_between_times(
p.hour_from, p.hour_to, start_date)]
return False if not attendance_ids else True
# 判断传入时间是否在配置的工作中心的工作日历内
def is_between_times(self, hour_from, hour_to, start_date):
integer_part, decimal_part = self.get_integer_and_decimal_parts(hour_from)
start_time = time(integer_part, decimal_part)
integer_part, decimal_part = self.get_integer_and_decimal_parts(hour_to)
end_time = time(integer_part, decimal_part)
return start_time <= start_date.time() <= end_time
# 获取整数部分和小数部分
def get_integer_and_decimal_parts(self, value):
integer_part = int(value)
decimal_part = value - integer_part
return int(integer_part), int(decimal_part)
## 处理生产线的是否有可排程的资源
def deal_production_lines_available(self, date_planned_start):
for record in self:
# 自动生产线工单
date_planned_end = date_planned_start + datetime.datetime.timedelta(hours=1)
workorder_ids = record.env['mrp.workorder'].sudo().search(
[('workcenter_id', '=', record.id), ('date_planned_start', '>=', datetime),
('date_planned_start', '<=', date_planned_end)])
if not workorder_ids:
return True
sum_qty = sum([p.qty_produced for p in workorder_ids])
if sum_qty >= record.default_capacity:
return False
return True
class ResWorkcenterProductivity(models.Model):
_inherit = 'mrp.workcenter.productivity'