在sf_base下新增生产线模型,优化了计划管理-工作日历设置的手动输入时间和手动输入班次的格式
This commit is contained in:
@@ -1,28 +1,10 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ProductionLine(models.Model):
|
||||
_name = 'sf.production.line'
|
||||
_description = '生产线'
|
||||
|
||||
name = fields.Char(string='生产线名称')
|
||||
|
||||
|
||||
class WorkingProcedure(models.Model):
|
||||
_name = 'sf.working.procedure'
|
||||
_description = '工序'
|
||||
|
||||
name = fields.Char(string='工序名称')
|
||||
content = fields.Char(string='主要加工内容')
|
||||
|
||||
WorkingProcedure_to_ProductionLine_id = fields.Many2one('sf.production.line')
|
||||
|
||||
|
||||
class ProcedureEquipmentResourceSetting(models.Model):
|
||||
_name = 'sf.procedure.equipment.resource.setting'
|
||||
_description = '工序设备资源设置'
|
||||
|
||||
equipment_to_working_procedure_id = fields.Many2one('sf.working.procedure', string='工序')
|
||||
name = fields.Char(string='设备名称')
|
||||
machine_tool_name = fields.Char(string='机台号')
|
||||
brand = fields.Char(string='品牌')
|
||||
|
||||
@@ -2,49 +2,99 @@ from odoo import models, fields, api
|
||||
import re
|
||||
|
||||
|
||||
def time_H_selection():
|
||||
return [('00', '00'), ('01', '01'), ('02', '02'), ('03', '03'), ('04', '04'), ('05', '05'),
|
||||
('06', '06'), ('07', '07'), ('08', '08'), ('09', '09'), ('10', '10'), ('11', '11'),
|
||||
('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'),
|
||||
('18', '18'), ('19', '19'), ('20', '20'), ('21', '21'), ('22', '22'), ('23', '23')]
|
||||
|
||||
|
||||
def time_M_or_S_selection():
|
||||
return [('00', '00'), ('05', '05'), ('10', '10'), ('15', '15'), ('20', '20'), ('25', '25'),
|
||||
('30', '30'), ('35', '35'), ('40', '40'), ('45', '45'), ('50', '50'), ('55', '55')]
|
||||
|
||||
|
||||
class WorkLogSetting(models.Model):
|
||||
_name = 'sf.work.log.setting'
|
||||
_description = '工作日历设置'
|
||||
|
||||
name = fields.Char(string='工作日历名称')
|
||||
# start_time = fields.Char(string='日开始时间')
|
||||
start_time = fields.Datetime(string='日开始时间')
|
||||
end_time = fields.Char(string='日结束时间')
|
||||
|
||||
start_time = fields.Char(string='日开始时间', default="00:00:00")
|
||||
start_time_H = fields.Selection(time_H_selection(), '时', default='00')
|
||||
start_time_M = fields.Selection(time_M_or_S_selection(), '分', default='00')
|
||||
start_time_S = fields.Selection(time_M_or_S_selection(), '秒', default='00')
|
||||
end_time = fields.Char(string='日结束时间', default="00:00:00")
|
||||
end_time_H = fields.Selection(time_H_selection(), '时', default='00')
|
||||
end_time_M = fields.Selection(time_M_or_S_selection(), '分', default='00')
|
||||
end_time_S = fields.Selection(time_M_or_S_selection(), '秒', default='00')
|
||||
|
||||
duration = fields.Char(string='时长')
|
||||
day_off = fields.Char(string='休息日')
|
||||
|
||||
user_defined_working_shift_status = fields.Boolean(string='自定义班次', default=False)
|
||||
working_shift = fields.Char(string='班次')
|
||||
working_shift_char = fields.Char(string='班次')
|
||||
working_shift_select = fields.Selection([('0', '早班00:00-08:00'),
|
||||
('1', '白班08:00-16:00'),
|
||||
('2', '晚班16:00-24:00'),
|
||||
('3', '长白班08:00-20:00'),
|
||||
('4', '长晚班20:00-08:00')], string='班次')
|
||||
working_shift_select = fields.Selection([('早班00:00-08:00', '早班00:00-08:00'),
|
||||
('白班08:00-16:00', '白班08:00-16:00'),
|
||||
('晚班16:00-24:00', '晚班16:00-24:00'),
|
||||
('长白班08:00-20:00', '长白班08:00-20:00'),
|
||||
('长晚班20:00-08:00', '长晚班20:00-08:00')], string='班次')
|
||||
working_shift_start_time_H = fields.Selection(time_H_selection(), '班次开始时间:时', default='00')
|
||||
working_shift_start_time_M = fields.Selection(time_M_or_S_selection(), '分', default='00')
|
||||
working_shift_start_time_S = fields.Selection(time_M_or_S_selection(), '秒', default='00')
|
||||
working_shift_end_time_H = fields.Selection(time_H_selection(), '班次结束时间:时', default='00')
|
||||
working_shift_end_time_M = fields.Selection(time_M_or_S_selection(), '分', default='00')
|
||||
working_shift_end_time_S = fields.Selection(time_M_or_S_selection(), '秒', default='00')
|
||||
|
||||
status = fields.Boolean(string='状态', default=True)
|
||||
update_person = fields.Char(string='更新人', default=lambda self: self.env.user.name)
|
||||
update_time = fields.Datetime(string='更新时间', default=lambda self: fields.Datetime.now())
|
||||
|
||||
@api.onchange('start_time_H', 'start_time_M', 'start_time_S')
|
||||
def _onchange_start_time(self):
|
||||
"""
|
||||
设置输入日开始时间
|
||||
:return:
|
||||
"""
|
||||
self.start_time = f"{self.start_time_H}:{self.start_time_M}:{self.start_time_S}"
|
||||
|
||||
@api.onchange('end_time_H', 'end_time_M', 'end_time_S')
|
||||
def _onchange_end_time(self):
|
||||
"""
|
||||
设置输入日结束时间
|
||||
:return:
|
||||
"""
|
||||
self.end_time = f"{self.end_time_H}:{self.end_time_M}:{self.end_time_S}"
|
||||
|
||||
@api.onchange('working_shift_char', 'working_shift_select')
|
||||
def _onchange_working_shift(self):
|
||||
"""
|
||||
对班次是否手动输入是进行不同的展示
|
||||
:return:
|
||||
"""
|
||||
for record in self:
|
||||
if record.working_shift_select:
|
||||
record.working_shift = record.working_shift_select
|
||||
else:
|
||||
record.working_shift = record.working_shift_char
|
||||
|
||||
# @api.onchange('start_time')
|
||||
# def _onchange_start_time(self):
|
||||
# pattern = re.compile(r'^(([0-9]|1[0-9]|2[0-3]):[0-5][0-9])|24:00$')
|
||||
# if self.start_time and not pattern.match(self.start_time):
|
||||
# raise models.ValidationError('输入的日开始时间不正确,请重新输入!')
|
||||
|
||||
@api.onchange('end_time')
|
||||
def _onchange_end_time(self):
|
||||
pattern = re.compile(r'^(([0-9]|1[0-9]|2[0-3]):[0-5][0-9])|24:00$')
|
||||
for record in self:
|
||||
if record.end_time and not pattern.match(record.end_time):
|
||||
raise models.ValidationError('输入的日结束时间不正确,请重新输入!')
|
||||
@api.onchange('working_shift_start_time_H',
|
||||
'working_shift_start_time_M',
|
||||
'working_shift_start_time_S',
|
||||
'working_shift_end_time_H',
|
||||
'working_shift_end_time_M',
|
||||
'working_shift_end_time_S')
|
||||
def _onchange_working_shift_time(self):
|
||||
start_time = f"{self.working_shift_start_time_H}:{self.working_shift_start_time_M}:{self.working_shift_start_time_S}"
|
||||
end_time = f"{self.working_shift_end_time_H}:{self.working_shift_end_time_M}:{self.working_shift_end_time_S}"
|
||||
self.working_shift_char = f"自定义班次{start_time}-{end_time}"
|
||||
|
||||
@api.onchange('start_time', 'end_time')
|
||||
def _onchange_duration(self):
|
||||
"""
|
||||
根据日开始时间和日结束时间计算每日工作时长
|
||||
:return:
|
||||
"""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user