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_plan_management/__manifest__.py b/sf_plan_management/__manifest__.py index 5f82e7b4..44be0987 100644 --- a/sf_plan_management/__manifest__.py +++ b/sf_plan_management/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': [], + 'depends': ['sf_maintenance'], 'data': [ 'security/ir.model.access.csv', # 'security/ir.model.access.csv', diff --git a/sf_plan_management/models/base.py b/sf_plan_management/models/base.py index 0bda7291..1a8d1e27 100644 --- a/sf_plan_management/models/base.py +++ b/sf_plan_management/models/base.py @@ -1,43 +1,55 @@ -from odoo import models, fields +from odoo import models, fields, api +from odoo.exceptions import UserError class ProcedureEquipmentResourceSetting(models.Model): _name = 'sf.procedure.equipment.resource.setting' _description = '产线设备资源设置' - def _get_code(self): - """ - 自动生成编码 - :return: - """ - fixture_material = self.env['sf.procedure.equipment.resource.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='序号', readonly=True, default=_get_code) - work_center_name = fields.Char(string='工作中心名称') - equipment_code = fields.Char(string='机台号') - # todo 绑定设备 - # equipment_name = fields.Many2one('', string='设备名称') - brand = fields.Char(string='品牌') - model = fields.Char(string='型号') - working_procedure = fields.Char(string='工序') - production_capacity = fields.Char(string='产能', required=True) + 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='班次') - create_time = fields.Datetime(string='新增时间', default=lambda self: fields.Datetime.now()) - status = fields.Selection([('0', '正常'), ('1', '故障停机'), ('2', '计划停机')], string='设备状态', default='0') + 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/views/paln_base_view.xml b/sf_plan_management/views/paln_base_view.xml index b029a6e0..645aa45d 100644 --- a/sf_plan_management/views/paln_base_view.xml +++ b/sf_plan_management/views/paln_base_view.xml @@ -106,18 +106,19 @@ sf.procedure.equipment.resource.setting - - + - + + + @@ -128,32 +129,40 @@
- + - - - - + - + - - - + - - - - + + - - - - + ` + + + + + + + + + + + + + + + + + +
@@ -165,8 +174,20 @@ sf.procedure.equipment.resource.setting + + + + + + + + + + + + - +