diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv
index 175e4589..e5c4093c 100644
--- a/sf_base/security/ir.model.access.csv
+++ b/sf_base/security/ir.model.access.csv
@@ -31,3 +31,6 @@ access_sf_functional_fixture,sf_functional_fixture,model_sf_functional_fixture,b
+
+
+
diff --git a/sf_maintenance/__manifest__.py b/sf_maintenance/__manifest__.py
index 529c62fc..6e644ebc 100644
--- a/sf_maintenance/__manifest__.py
+++ b/sf_maintenance/__manifest__.py
@@ -12,6 +12,7 @@
'data': [
'security/group_security.xml',
'security/ir.model.access.csv',
+ 'views/production_line_base.py',
'views/maintenance_views.xml',
'views/maintenance_logs_views.xml',
'views/equipment_maintenance_standards_views.xml',
diff --git a/sf_maintenance/models/__init__.py b/sf_maintenance/models/__init__.py
index 1e93b68d..98f9d12c 100644
--- a/sf_maintenance/models/__init__.py
+++ b/sf_maintenance/models/__init__.py
@@ -2,4 +2,5 @@
from . import sf_maintenance
from . import sf_maintenance_logs
from . import sf_equipment_maintenance_standards
-from . import sf_maintenance_requests
\ No newline at end of file
+from . import sf_maintenance_requests
+from . import production_line_base
diff --git a/sf_maintenance/models/production_line_base.py b/sf_maintenance/models/production_line_base.py
new file mode 100644
index 00000000..f9a30d36
--- /dev/null
+++ b/sf_maintenance/models/production_line_base.py
@@ -0,0 +1,30 @@
+from odoo import models,fields
+
+
+class ProductionLine(models.Model):
+ _name = 'sf.production.line'
+ _description = '生产线'
+
+ def _get_code(self):
+ """
+ 自动生成编码
+ :return:
+ """
+ fixture_material = self.env['sf.production.line'].sudo().search(
+ [('code', '!=', '')],
+ limit=1,
+ order="id desc")
+ if not fixture_material:
+ num = "%03d" % 1
+ else:
+ m = int(fixture_material.code) + 1
+ num = "%03d" % m
+ return num
+
+ name = fields.Char('生产线')
+ code = fields.Char('编码', default=_get_code, readonly=True)
+ remark = fields.Char('备注')
+
+
+
+
diff --git a/sf_maintenance/security/ir.model.access.csv b/sf_maintenance/security/ir.model.access.csv
index 05ee33a2..809ed5b6 100644
--- a/sf_maintenance/security/ir.model.access.csv
+++ b/sf_maintenance/security/ir.model.access.csv
@@ -4,4 +4,6 @@ access_sf_maintenance_logs,sf_maintenance_logs,model_sf_maintenance_logs,base.gr
access_maintenance_equipment,maintenance_equipment,model_maintenance_equipment,base.group_user,1,1,1,1
access_maintenance_standards,maintenance_standards,model_maintenance_standards,base.group_user,1,1,1,1
+access_sf_production_line,sf.production.line,model_sf_production_line,base.group_user,1,1,1,1
+
diff --git a/sf_maintenance/views/production_line_view.xml b/sf_maintenance/views/production_line_view.xml
new file mode 100644
index 00000000..0772d116
--- /dev/null
+++ b/sf_maintenance/views/production_line_view.xml
@@ -0,0 +1,81 @@
+
+
+
+ 生产线
+ sf.production.line
+
+
+
+
+
+
+
+
+
+
+ 生产线
+ sf.production.line
+
+
+
+
+
+
+ 生产线
+ sf.production.line
+
+
+
+
+
+
+
+
+ 生产线看板
+ sf.production.line
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 生产线
+ sf.production.line
+ kanban,tree,form
+
+
+
+
\ No newline at end of file
diff --git a/sf_plan_management/__manifest__.py b/sf_plan_management/__manifest__.py
index 9a8af0cd..44be0987 100644
--- a/sf_plan_management/__manifest__.py
+++ b/sf_plan_management/__manifest__.py
@@ -10,11 +10,12 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
- 'depends': [],
+ 'depends': ['sf_maintenance'],
'data': [
'security/ir.model.access.csv',
+ # 'security/ir.model.access.csv',
'views/paln_base_view.xml',
- 'views/menu_view.xml'
+ 'views/menu_view.xml',
],
'demo': [
],
diff --git a/sf_plan_management/models/base.py b/sf_plan_management/models/base.py
index 76b1c0fc..1a8d1e27 100644
--- a/sf_plan_management/models/base.py
+++ b/sf_plan_management/models/base.py
@@ -1,42 +1,55 @@
-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')
+from odoo import models, fields, api
+from odoo.exceptions import UserError
class ProcedureEquipmentResourceSetting(models.Model):
_name = 'sf.procedure.equipment.resource.setting'
- _description = '工序设备资源设置'
+ _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='品牌')
- model = fields.Char(string='型号')
- production_capacity = fields.Char(string='产能')
- working_calendar = fields.Many2one('sf.work.log.setting', string='工作日历')
- working_shift = fields.Char(string='班次')
- create_time = fields.Datetime(string='新增时间', default=lambda self: fields.Datetime.now())
- stale_dated_time = fields.Datetime(string='过期时间')
- status = fields.Selection([('0', '正常'), ('1', '故障停机'), ('2', '计划停机')], string='设备状态', default='0')
+ production_line_id = fields.Many2one('sf.production.line', string='生产线', required=True)
+ work_center_name_id = fields.Many2one('mrp.workcenter', string='工作中心名称')
+ equipment_code = fields.Char(string='机台号(原设备编码)', readonly=True, compute='_onchange_equipment_name_id')
+ equipment_name_id = fields.Many2one('maintenance.equipment',
+ string='设备名称',
+ readonly=True,
+ compute='_onchange_work_center_name_id')
+ brand = fields.Char(string='品牌', readonly=True, compute='_onchange_equipment_name_id')
+ model = fields.Char(string='型号', readonly=True, compute='_onchange_equipment_name_id')
+ # todo 传入工序数据
+ working_procedure = fields.Char(string='工序', readonly=True)
+ production_capacity = fields.Float(string='产能', required=True, digits=(4, 1))
+ working_calendar_id = fields.Many2one('sf.work.log.setting', string='工作日历')
+ working_shift = fields.Char(string='班次', readonly=True, compute='_onchange_working_calendar_id')
+ create_time = fields.Datetime(string='新增时间', default=lambda self: fields.Datetime.now(), readonly=True)
+ status = fields.Selection([('正常', '正常'), ('1', '故障停机'), ('2', '计划停机')],
+ string='设备状态',
+ readonly=True,
+ compute='_onchange_equipment_name_id')
participate_in_scheduling = fields.Boolean(string='参与排程', default=True)
-
-
+ @api.onchange('production_capacity')
+ def _onchange_production_capacity(self):
+ for record in self:
+ if record.production_capacity < 0:
+ raise UserError("输入的产能值不正确,请重新输入!")
+
+ @api.depends('work_center_name_id')
+ def _onchange_work_center_name_id(self):
+ for record in self:
+ record.equipment_name_id = record.work_center_name_id.equipment_ids
+
+ @api.onchange('equipment_name_id')
+ def _onchange_equipment_name_id(self):
+ for record in self:
+ record.equipment_code = record.equipment_name_id.code,
+ record.brand = record.equipment_name_id.brand_id.name,
+ record.model = record.equipment_name_id.type_id.name,
+ record.status = record.equipment_name_id.state
+
+ @api.depends('working_calendar_id')
+ def _onchange_working_calendar_id(self):
+ for record in self:
+ record.working_shift = record.working_calendar_id.working_shift
diff --git a/sf_plan_management/models/calendar_base.py b/sf_plan_management/models/calendar_base.py
index dc22b92f..0bc1ba56 100644
--- a/sf_plan_management/models/calendar_base.py
+++ b/sf_plan_management/models/calendar_base.py
@@ -2,49 +2,123 @@ 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='日结束时间')
- duration = fields.Char(string='时长')
- day_off = fields.Char(string='休息日')
+ def _get_code(self):
+ """
+ 自动生成编码
+ :return:
+ """
+ fixture_material = self.env['sf.work.log.setting'].sudo().search(
+ [('code', '!=', '')],
+ limit=1,
+ order="id desc")
+ if not fixture_material:
+ num = "%03d" % 1
+ else:
+ m = int(fixture_material.code) + 1
+ num = "%03d" % m
+ return num
+
+ code = fields.Char(string='序号', default=_get_code, readonly=True)
+ name = fields.Char(string='工作日历名称', required=True)
+
+ start_time = fields.Char(string='日开始时间', readonly=True, compute='_compute_start_time')
+ start_time_H = fields.Selection(time_H_selection(), '时', required=True)
+ start_time_M = fields.Selection(time_M_or_S_selection(), '分', required=True)
+ end_time = fields.Char(string='日结束时间', readonly=True, compute='_compute_end_time')
+ end_time_H = fields.Selection(time_H_selection(), '时', required=True)
+ end_time_M = fields.Selection(time_M_or_S_selection(), '分', required=True)
+
+ duration = fields.Char(string='时长', readonly=True, compute='_compute_duration')
+ day_off = fields.Char(string='休息日', required=True)
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_char = fields.Char(string='班次', readonly=True, compute='_compute_working_shift_time')
+ 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(), '班次开始时间:时',
+ attr={'required': [('user_defined_working_shift_status', '=', 'True')]})
+ working_shift_start_time_M = fields.Selection(time_M_or_S_selection(), '分',
+ attr={'required': [('user_defined_working_shift_status', '=', 'True')]})
+ working_shift_end_time_H = fields.Selection(time_H_selection(), '班次结束时间:时',
+ attr={'required': [('user_defined_working_shift_status', '=', 'True')]})
+ working_shift_end_time_M = fields.Selection(time_M_or_S_selection(), '分',
+ attr={'required': [('user_defined_working_shift_status', '=', 'True')]})
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.depends('start_time_H', 'start_time_M')
+ def _compute_start_time(self):
+ """
+ 设置输入日开始时间
+ :return:
+ """
+ for record in self:
+ record.start_time = f"{record.start_time_H}:{record.start_time_M}:00"
+
+ @api.depends('end_time_H', 'end_time_M')
+ def _compute_end_time(self):
+ """
+ 设置输入日结束时间
+ :return:
+ """
+ for record in self:
+ record.end_time = f"{record.end_time_H}:{record.end_time_M}:00"
+
@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.depends(
+ 'working_shift_start_time_H', 'working_shift_start_time_M',
+ 'working_shift_end_time_H', 'working_shift_end_time_M')
+ def _compute_working_shift_time(self):
+ start_time = f"{self.working_shift_start_time_H}:{self.working_shift_start_time_M}:00"
+ end_time = f"{self.working_shift_end_time_H}:{self.working_shift_end_time_M}:00"
+ self.working_shift_char = f"自定义班次{start_time}-{end_time}"
- @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$')
+ @api.depends('start_time_H', 'start_time_M', 'end_time_H', 'end_time_M')
+ def _compute_duration(self):
+ """
+ 根据日开始时间和日结束时间计算每日工作时长
+ :return:
+ """
for record in self:
- if record.end_time and not pattern.match(record.end_time):
- raise models.ValidationError('输入的日结束时间不正确,请重新输入!')
-
-
+ st_h = float(record.start_time_H)
+ st_m = float(record.start_time_M)
+ end_h = float(record.end_time_H)
+ end_m = float(record.end_time_M)
+ # 日开始时间小于日结束时间
+ if st_h < end_h:
+ record.duration = str(round(end_h-st_h+(end_m-st_m)/60, 2))
+ else:
+ record.duration = str(round(end_h-st_h+(end_m-st_m)/60+24, 2))
diff --git a/sf_plan_management/security/ir.model.access.csv b/sf_plan_management/security/ir.model.access.csv
index 1103d658..98cf2ae7 100644
--- a/sf_plan_management/security/ir.model.access.csv
+++ b/sf_plan_management/security/ir.model.access.csv
@@ -1,7 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sf_work_log_setting,sf.work.log.setting,model_sf_work_log_setting,base.group_user,1,1,1,1
-access_sf_production_line,sf.production.line,model_sf_production_line,base.group_user,1,1,1,1
-access_sf_working_procedure,sf.working.procedure,model_sf_working_procedure,base.group_user,1,1,1,1
access_sf_procedure_equipment_resource_setting,sf.procedure.equipment.resource.setting,model_sf_procedure_equipment_resource_setting,base.group_user,1,1,1,1
diff --git a/sf_plan_management/views/menu_view.xml b/sf_plan_management/views/menu_view.xml
index 1641947c..2bf4569d 100644
--- a/sf_plan_management/views/menu_view.xml
+++ b/sf_plan_management/views/menu_view.xml
@@ -20,7 +20,7 @@
/>