交期状态

This commit is contained in:
liaodanlong
2024-11-13 14:46:58 +08:00
parent e38407c0a5
commit 9a9bfd198b
4 changed files with 111 additions and 15 deletions

View File

@@ -149,8 +149,8 @@ class ResMrpWorkOrder(models.Model):
def _compute_default_construction_period_status(self):
need_list = [
'progress',
'to be detected']
'progress',
'to be detected']
try:
if self.state not in need_list:
return False
@@ -170,12 +170,45 @@ class ResMrpWorkOrder(models.Model):
@api.depends('state', 'date_planned_finished')
def _compute_construction_period_status(self):
for worker in self:
worker.construction_period_status = worker._compute_default_construction_period_status()
construction_period_status = worker._compute_default_construction_period_status()
if construction_period_status and worker.construction_period_status!=construction_period_status:
worker.construction_period_status = construction_period_status
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='工期状态',
store=True,
compute='_compute_construction_period_status',
default=lambda self: self._compute_default_construction_period_status())
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')],
string='工期状态',
store=True,
compute='_compute_construction_period_status',
default=lambda
self: self._compute_default_construction_period_status())
def get_page_all_records(self, model_name, func, domain, page_size=100):
# 获取模型对象
model = self.env[model_name].sudo()
# 初始化分页参数
page_number = 1
while True:
# 计算偏移量
offset = (page_number - 1) * page_size
# 获取当前页的数据
records = model.search(domain, limit=page_size, offset=offset)
# 如果没有更多记录,退出循环
if not records:
break
# 将当前页的数据添加到结果列表
func(records)
# 增加页码
page_number += 1
def run_compute_construction_period_status(self,records):
records._compute_construction_period_status()
def _corn_update_construction_period_status(self):
need_list = [
'progress',
'to be detected']
self.get_page_all_records('mrp.workorder',self.run_compute_construction_period_status,[('state', 'in', need_list)],100)
def get_hours_diff(self):
# 获取当前日期和时间