Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/新增工艺退回调整

# Conflicts:
#	sf_manufacturing/models/mrp_production.py
#	sf_manufacturing/views/mrp_production_addional_change.xml
This commit is contained in:
jinling.yang
2024-11-15 18:08:31 +08:00
25 changed files with 473 additions and 107 deletions

View File

@@ -144,6 +144,88 @@ class ResMrpWorkOrder(models.Model):
tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True)
def _compute_default_construction_period_status(self):
need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected','done']
try:
if self.state not in need_list:
return False
if not self.date_planned_finished:
return False
hours = self.get_hours_diff()
if hours >= 12:
return '正常'
elif hours > 0 and hours < 12 and self.state!='done':
return '预警'
elif hours > 0 and hours < 12 and self.state=='done':
return '正常'
else:
return '已逾期'
except Exception as e:
logging.error("Error processing production ID {}: {}".format(self.id, e))
raise e
@api.depends('state', 'date_planned_finished')
def _compute_construction_period_status(self):
for worker in self:
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())
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=['pending', 'waiting', 'ready', 'progress', 'to be detected']
# 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):
# 获取当前日期和时间
current_datetime = fields.Datetime.now()
# 将 date_field 转换为 datetime 对象
if self.date_planned_finished:
date_obj = fields.Datetime.from_string(self.date_planned_finished)
# 将 date 对象转换为 datetime 对象,设置时间为 00:00:00
# date_obj = datetime.datetime.combine(date_obj, datetime.time.min)
# 计算两个日期之间的差值
delta = date_obj - current_datetime
# 返回差值的小时数
return int(delta.total_seconds() / 3600)
else:
return 0.0
@api.depends('name', 'production_id.name')
def _compute_surface_technics_picking_ids(self):
for workorder in self: