diff --git a/sf_maintenance/models/sf_equipment_maintenance_standards.py b/sf_maintenance/models/sf_equipment_maintenance_standards.py index 7c8740f5..55fea8b0 100644 --- a/sf_maintenance/models/sf_equipment_maintenance_standards.py +++ b/sf_maintenance/models/sf_equipment_maintenance_standards.py @@ -15,13 +15,31 @@ class SfEquipmentSaintenanceStandards(models.Model): num = "%04d" % 1 else: - m = int(partner.code) + 1 + m = int(partner.code[-4:]) + 1 num = "%04d" % m return num - code = fields.Char(string='编码', default=get_no) + code = fields.Char(string='编码') remark = fields.Char('备注') maintenance_type = fields.Selection([('保养', '保养'), ("检修", "检修")], string='类型', default='保养') name = fields.Char(string='名称') + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if not vals['code']: + if vals['maintenance_type']: + if vals['maintenance_type'] == '保养': + vals['code'] = 'BY' + self.get_no() + else: + vals['code'] = 'JX' + self.get_no() + if not vals['name']: + if vals['maintenance_equipment_category_id']: + ma_name = self.env['maintenance.equipment.category'].sudo().search( + [('id', '=', vals['maintenance_equipment_category_id'])]).name + vals['name'] = ma_name + '-' + vals['maintenance_type'] + '标准-' + vals[ + 'code'] + return super().create(vals_list) + created_user_id = fields.Many2one('res.users', string='创建人', default=lambda self: self.env.user) maintenance_equipment_category_id = fields.Many2one('maintenance.equipment.category', string='设备类别') maintenance_equipment_ids = fields.Many2many( diff --git a/sf_maintenance/views/equipment_maintenance_standards_views.xml b/sf_maintenance/views/equipment_maintenance_standards_views.xml index 1b30b68f..3737a31c 100644 --- a/sf_maintenance/views/equipment_maintenance_standards_views.xml +++ b/sf_maintenance/views/equipment_maintenance_standards_views.xml @@ -11,7 +11,7 @@ - + diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index 37b5fd79..febab313 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -18,9 +18,9 @@ 'views/mrp_production_addional_change.xml', # 'views/mrp_maintenance_views.xml', 'views/mrp_routing_workcenter_view.xml', + 'views/production_line_view.xml', 'views/mrp_workcenter_views.xml', 'views/mrp_workorder_view.xml', - 'views/production_line_view.xml', 'views/tool_other_features_view.xml', 'views/model_type_view.xml', # 'views/kanban_change.xml' diff --git a/sf_manufacturing/models/__init__.py b/sf_manufacturing/models/__init__.py index c560211b..25b91f15 100644 --- a/sf_manufacturing/models/__init__.py +++ b/sf_manufacturing/models/__init__.py @@ -2,8 +2,8 @@ from . import model_type from . import product_template from . import mrp_production from . import mrp_workorder -from . import mrp_workcenter from . import mrp_maintenance +from . import mrp_workcenter from . import mrp_routing_workcenter from . import stock from . import res_user diff --git a/sf_manufacturing/models/mrp_maintenance.py b/sf_manufacturing/models/mrp_maintenance.py index afca09a2..f0b09e8d 100644 --- a/sf_manufacturing/models/mrp_maintenance.py +++ b/sf_manufacturing/models/mrp_maintenance.py @@ -6,8 +6,8 @@ from dateutil.relativedelta import relativedelta class MaintenanceEquipment(models.Model): _inherit = "maintenance.equipment" - _check_company_auto = True + production_line_id = fields.Many2one('sf.production.line', string='生产线') expected_mtbf = fields.Integer(string='Expected MTBF', help='Expected Mean Time Between Failure') mtbf = fields.Integer(compute='_compute_maintenance_request', string='MTBF', help='Mean Time Between Failure, computed based on done corrective maintenances.') @@ -16,8 +16,6 @@ class MaintenanceEquipment(models.Model): string='Estimated time before next failure (in days)', help='Computed as Latest Failure Date + MTBF') latest_failure_date = fields.Date(compute='_compute_maintenance_request', string='Latest Failure Date') - workcenter_id = fields.Many2one( - 'mrp.workcenter', string='Work Center', check_company=True) @api.depends('effective_date', 'maintenance_ids.stage_id', 'maintenance_ids.close_date', 'maintenance_ids.request_date') @@ -64,3 +62,8 @@ class MaintenanceRequest(models.Model): 'mrp.workorder', string='Work Order', check_company=True) production_company_id = fields.Many2one(string='Production Company', related='production_id.company_id') company_id = fields.Many2one(domain="[('id', '=?', production_company_id)]") + +class SfMaintenanceLogs(models.Model): + _inherit = 'sf.maintenance.logs' + + production_line_id = fields.Many2one('sf.production.line', string='生产线', related='maintenance_equipment_id.production_line_id', store=True) diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index c42e9cec..54d5e9a0 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -9,13 +9,10 @@ class ResWorkcenter(models.Model): # 生产线显示 production_line_show = fields.Char(string='生产线名称') - machine_tool_id = fields.Many2one('sf.machine_tool', string='机床') - production_line_id = fields.Many2one('sf.production.line', string='生产线') equipment_id = fields.Many2one( 'maintenance.equipment', string="设备", - check_company=True) - - + ) + production_line_id = fields.Many2one('sf.production.line', string='生产线', related='equipment_id.production_line_id', store=True) is_process_outsourcing = fields.Boolean('工艺外协') users_ids = fields.Many2many("res.users", 'users_workcenter') @@ -25,13 +22,13 @@ class ResWorkcenter(models.Model): equipment_status = fields.Selection( [("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")], - string="设备状态", compute='_compute_equipment_id') + string="设备状态", related='equipment_id.state') - @api.depends('equipment_id') - def _compute_equipment_id(self): - for record in self: - if record: - record.equipment_status = record.equipment_id.state + # @api.depends('equipment_id') + # def _compute_equipment_id(self): + # for record in self: + # if record: + # record.equipment_status = record.equipment_id.state equipment_image = fields.Binary('设备图片', related='equipment_id.machine_tool_picture') @@ -40,23 +37,23 @@ class ResWorkcenter(models.Model): outsourcing_workcenter = self.env['mrp.workcenter'].search([('is_process_outsourcing', '=', True)]) return outsourcing_workcenter.id - @api.onchange('machine_tool_id') - def update_machine_tool_is_binding(self): - machine_tool = self.env["sf.machine_tool"].search([('is_binding', '=', True)]) - if machine_tool: - for item in machine_tool: - workcenter_machine_tool = self.env["mrp.workcenter"].search([('machine_tool_id', '=', item.id)]) - if workcenter_machine_tool: - if self.machine_tool_id.id: - if workcenter_machine_tool.id != self.machine_tool_id.id: - self.machine_tool_id.is_binding = True - else: - self.machine_tool_id.is_binding = True - else: - self.machine_tool_id.is_binding = True - item.is_binding = False - else: - self.machine_tool_id.is_binding = True + # @api.onchange('machine_tool_id') + # def update_machine_tool_is_binding(self): + # machine_tool = self.env["sf.machine_tool"].search([('is_binding', '=', True)]) + # if machine_tool: + # for item in machine_tool: + # workcenter_machine_tool = self.env["mrp.workcenter"].search([('machine_tool_id', '=', item.id)]) + # if workcenter_machine_tool: + # if self.machine_tool_id.id: + # if workcenter_machine_tool.id != self.machine_tool_id.id: + # self.machine_tool_id.is_binding = True + # else: + # self.machine_tool_id.is_binding = True + # else: + # self.machine_tool_id.is_binding = True + # item.is_binding = False + # else: + # self.machine_tool_id.is_binding = True def action_work_order(self): if not self.env.context.get('desktop_list_view', False): diff --git a/sf_manufacturing/models/production_line_base.py b/sf_manufacturing/models/production_line_base.py index a8c41cd3..2cb704f0 100644 --- a/sf_manufacturing/models/production_line_base.py +++ b/sf_manufacturing/models/production_line_base.py @@ -22,6 +22,7 @@ class ProductionLine(models.Model): return num mrp_workcenter_ids = fields.One2many('mrp.workcenter', 'production_line_id', '工作中心') + mrp_manufacturing_ids = fields.One2many('maintenance.equipment', 'production_line_id', '设备') name = fields.Char('生产线', size=20, required=True) code = fields.Char('编码', default=_get_code, readonly=True) remark = fields.Char('备注') diff --git a/sf_manufacturing/views/production_line_view.xml b/sf_manufacturing/views/production_line_view.xml index f12f6d98..47e03488 100644 --- a/sf_manufacturing/views/production_line_view.xml +++ b/sf_manufacturing/views/production_line_view.xml @@ -82,4 +82,27 @@ name="生产线" sequence="20" action="sf_production_line_act"/> + + + + sf_equipment.form + maintenance.equipment + + + + + + + + + + sf.maintenance.logs.tree + sf.maintenance.logs + + + + + + + \ No newline at end of file