diff --git a/mrp_workorder/views/mrp_workorder_views.xml b/mrp_workorder/views/mrp_workorder_views.xml index 19abe1bf..efabc78b 100644 --- a/mrp_workorder/views/mrp_workorder_views.xml +++ b/mrp_workorder/views/mrp_workorder_views.xml @@ -156,30 +156,30 @@ if env.user.has_group('mrp.group_mrp_workorder_dependencies'): - - Work Orders - ir.actions.act_window - mrp.workorder - kanban,tree,form - - fullscreen - [('state', 'not in', ['done', 'cancel'])] - {'search_default_workcenter_id': active_id} - -

- No work orders to do! -

- Work orders are operations to do as part of a manufacturing order. - Operations are defined in the bill of materials or added in the manufacturing order directly. -

- Use the table work center control panel to register operations in the shop floor directly. - The tablet provides worksheets for your workers and allow them to scrap products, track time, - launch a maintenance request, perform quality tests, etc. -

-
-
+ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sf_base/models/assemble.py b/sf_base/models/assemble.py index 902bedc6..c8568f99 100644 --- a/sf_base/models/assemble.py +++ b/sf_base/models/assemble.py @@ -5,50 +5,40 @@ class Assemble(models.Model): _name = 'sf.assemble' _description = "组合装夹" - functional_fixture_code = fields.Char(string="功能夹具编码", size=25, required=True) - functional_fixture_name = fields.Char(string="功能夹具名称", size=25, required=True) - functional_fixture_type = fields.Char(string="功能夹具类型", required=True) - chuck_name = fields.Char(string="卡盘名称", required=True) - chuck_brand_id = fields.Many2one('sf.machine.brand', string="卡盘品牌", required=True) - chuck_type_id = fields.Char(string="卡盘类型", required=True) - chuck_model_id = fields.Char(string="卡盘型号", required=True) - tray_name = fields.Char(string="托盘名称", required=True) - tray_brand_id = fields.Many2one('sf.machine.brand', string="托盘品牌", required=True) - tray_type_id = fields.Char(string="托盘类型", required=True) - tray_model_id = fields.Char(string="托盘型号", required=True) - real_code = fields.Char(string="真实坯料编码", size=25, required=True) - real_name = fields.Char(string="真实坯料名称", size=25, required=True) - total_wight = fields.Float(string="总重量", required=True) + functional_fixture_code = fields.Char(string="功能夹具编码", readonly=True) + name = fields.Char(string="功能夹具名称", readonly=True) + functional_fixture_type_id = fields.Many2one('sf.functional.fixture.type', string="功能夹具类型", readonly=True) + chuck_name = fields.Char(string="卡盘名称") + chuck_brand_id = fields.Many2one('sf.machine.brand', string="卡盘品牌") + chuck_type_id = fields.Char(string="卡盘类型") + chuck_model_id = fields.Char(string="卡盘型号") + tray_name = fields.Char(string="托盘名称") + tray_brand_id = fields.Many2one('sf.machine.brand', string="托盘品牌") + tray_type_id = fields.Char(string="托盘类型") + tray_model_id = fields.Char(string="托盘型号") + real_code = fields.Char(string="真实坯料编码") + real_name = fields.Char(string="真实坯料名称") + real_width = fields.Float(string="真实宽度") + real_length = fields.Float(string="真实长度") + real_height = fields.Float(string="真实高度") + real_diameter = fields.Float(string="真实直径") + total_wight = fields.Float(string="总重量") maximum_carrying_weight = fields.Char(string="最大承载重量[kg]") maximum_clamping_force = fields.Char(string="最大夹持力[n]") - production_line = fields.Char(string="生产线", required=True) + production_line = fields.Char(string="生产线") # 以下为智能工厂工单带过来的机床信息 - machine_tool = fields.Many2one('sf.machine_tool', string="机床名称", required=True) - machine_tool_startime = fields.Date(string="机床开始加工时间", required=True) + machine_tool = fields.Many2one('sf.machine_tool', string="机床名称") + machine_tool_startime = fields.Date(string="机床开始加工时间") # 以下为智能工厂工单带过来的信息 - apply_staff = fields.Char(string="申请人", required=True) - machine_tool_code = fields.Char(string="机床编码", required=True) - apply_time = fields.Date(string="申请时间", required=True) - apply_reason = fields.Char(string="申请原因", required=True) + apply_staff = fields.Char(string="申请人") + machine_tool_code = fields.Char(string="机床编码") + apply_time = fields.Date(string="申请时间") + apply_reason = fields.Char(string="申请原因") # 以下为装夹的信息 - preset_staff = fields.Char(string="预调名称", required=True) - preset_time = fields.Date(string="预调时间", required=True) - material_taker = fields.Char(string="领料人", required=True) - material_removal_time = fields.Date(string="领料出库时间", required=True) - remark = fields.Char(string="备注", required=True) - - - - - - - - - - - - - - - - + preset_staff = fields.Char(string="预调名称") + preset_time = fields.Date(string="预调时间") + material_taker = fields.Char(string="领料人") + material_removal_time = fields.Date(string="领料出库时间") + remark = fields.Char(string="备注") + # 以下为出库的信息 + stock_removal_code = fields.Char(string="出库人") diff --git a/sf_base/views/assemble_view.xml b/sf_base/views/assemble_view.xml index 20da39b2..ccad42f9 100644 --- a/sf_base/views/assemble_view.xml +++ b/sf_base/views/assemble_view.xml @@ -10,8 +10,8 @@ - + @@ -24,8 +24,8 @@ - - + + @@ -65,87 +65,57 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sf_base/wizard/stock_removal_wizard_view.xml b/sf_base/wizard/stock_removal_wizard_view.xml index d669cdca..fbb7708b 100644 --- a/sf_base/wizard/stock_removal_wizard_view.xml +++ b/sf_base/wizard/stock_removal_wizard_view.xml @@ -4,22 +4,24 @@ sf.stock.removal.wizard.form.view sf.stock.removal.wizard -
- + + - - - + + + + + + + + + - - - - - -
-
+ +
diff --git a/sf_base/wizard/workpiece_clamping_wizard_view.xml b/sf_base/wizard/workpiece_clamping_wizard_view.xml index 30cb1591..6418f5c9 100644 --- a/sf_base/wizard/workpiece_clamping_wizard_view.xml +++ b/sf_base/wizard/workpiece_clamping_wizard_view.xml @@ -5,70 +5,74 @@ sf.workpiece.clamping.wizard
- - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - -
-
+ +
diff --git a/sf_bf_connect/models/process_status.py b/sf_bf_connect/models/process_status.py index 0a18096b..b5a1cc19 100644 --- a/sf_bf_connect/models/process_status.py +++ b/sf_bf_connect/models/process_status.py @@ -33,8 +33,8 @@ class StatusChange(models.Model): 'process_start_time': process_start_time, }, } - url1 = config['bfm_url'] + '/api/get/state/get_order' - requests.post(url1, json=json1, data=None) + # url1 = config['bfm_url'] + '/api/get/state/get_order' + # requests.post(url1, json=json1, data=None) logging.info('接口已经执行=============') return res @@ -57,8 +57,8 @@ class StatusChange(models.Model): 'state': '待派单', }, } - url1 = config['bfm_url'] + '/api/get/state/cancel_order' - requests.post(url1, json=json1, data=None) + # url1 = config['bfm_url'] + '/api/get/state/cancel_order' + # requests.post(url1, json=json1, data=None) return res diff --git a/sf_maintenance/models/sf_equipment_maintenance_standards.py b/sf_maintenance/models/sf_equipment_maintenance_standards.py index 35f25911..2544adb4 100644 --- a/sf_maintenance/models/sf_equipment_maintenance_standards.py +++ b/sf_maintenance/models/sf_equipment_maintenance_standards.py @@ -24,8 +24,7 @@ class SfEquipmentSaintenanceStandards(models.Model): 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('maintenance.equipment', 'sf_maintenance_equipment_ids', string='设备') - maintenance_projects = fields.Char('维保项目') - maintenance_standards = fields.Char('维保标准') + maintenance_standards_ids = fields.One2many('maintenance.standards', 'equipment_maintenance_standards_id', string='维保项目') eq_maintenance_ids = fields.One2many('maintenance.equipment', 'eq_maintenance_id', string='保养设备') overhaul_ids = fields.One2many('maintenance.equipment', 'overhaul_id', string='检修设备') @@ -37,7 +36,14 @@ class SfEquipmentSaintenanceStandards(models.Model): if record.maintenance_type == '检修': record.write({'overhaul_ids': [(6, 0, record.maintenance_equipment_ids.ids)]}) - +class SfSaintenanceStandards(models.Model): + _name = 'maintenance.standards' + _description = '维保项目' + + name = fields.Char('维保项目') + maintenance_standards = fields.Char('维保标准') + equipment_maintenance_standards_id = fields.Many2one('equipment.maintenance.standards', string='设备维保标准') + maintenance_request_id = fields.Many2one('maintenance.request', string='设备维保计划') diff --git a/sf_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index 6c2f1dcd..bc7c841b 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -4,10 +4,12 @@ import base64 from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.exceptions import UserError import logging +from datetime import date, datetime, timedelta import requests import json from odoo.addons.sf_base.commons.common import Common + class SfMaintenanceEquipmentCategory(models.Model): _inherit = 'maintenance.equipment.category' _description = '设备类别' @@ -20,6 +22,7 @@ class SfMaintenanceEquipment(models.Model): _description = '设备' crea_url = "/api/machine_tool/create" + def get_no(self): partner = self.env['maintenance.equipment'].sudo().search( [('MTcode', '!=', '')], @@ -33,19 +36,23 @@ class SfMaintenanceEquipment(models.Model): num = "%04d" % m return num - equipment_maintenance_standards_ids = fields.Many2many('equipment.maintenance.standards', 'sf_maintenance_equipment_ids', string='设备维保标准') - eq_maintenance_id =fields.Many2one('equipment.maintenance.standards', string='设备保养标准', domain="[('maintenance_type','=','保养')]") + equipment_maintenance_standards_ids = fields.Many2many('equipment.maintenance.standards', + 'sf_maintenance_equipment_ids', string='设备维保标准') + eq_maintenance_id = fields.Many2one('equipment.maintenance.standards', string='设备保养标准', + domain="[('maintenance_type','=','保养')]") overhaul_date = fields.Date(string='下次预防检修') overhaul_period = fields.Integer(string='预防检修频次') overhaul_duration = fields.Float(string='检修时长') - overhaul_id = fields.Many2one('equipment.maintenance.standards', string='设备检修标准', domain="[('maintenance_type','=','检修')]") + overhaul_id = fields.Many2one('equipment.maintenance.standards', string='设备检修标准', + domain="[('maintenance_type','=','检修')]") @api.onchange('eq_maintenance_id', 'overhaul_id') def _compute_equipment_maintenance_standards_ids(self): for record in self: if record.eq_maintenance_id and record.overhaul_id: - record.equipment_maintenance_standards_ids = [(6, 0, [record.eq_maintenance_id.id, record.overhaul_id.id])] + record.equipment_maintenance_standards_ids = [ + (6, 0, [record.eq_maintenance_id.id, record.overhaul_id.id])] break if record.eq_maintenance_id: record.equipment_maintenance_standards_ids = [(6, 0, [record.eq_maintenance_id.id])] @@ -56,12 +63,10 @@ class SfMaintenanceEquipment(models.Model): else: record.equipment_maintenance_standards_ids = False - - MTcode = fields.Char("编码", default=get_no) created_user = fields.Many2one('res.users', string='创建人', default=lambda self: self.env.user) equipment_type = fields.Selection([('机床', '机床')], related='category_id.equipment_type') - code = fields.Char('行业编码') + code = fields.Char('机台号') name = fields.Char('名称') knife_type = fields.Selection( [("BT40", "BT40"), ("BT30", "BT30")], @@ -139,7 +144,16 @@ class SfMaintenanceEquipment(models.Model): control_system_id = fields.Many2one('sf.machine.control_system', string="控制系统") active = fields.Boolean('有效', default=True) - code = fields.Char('编码') + + def name_get(self): + result = [] + for parameter in self: + if parameter.code: + name = parameter.name + '-' + parameter.code + else: + name = parameter.name + result.append((parameter.id, name)) + return result @api.constrains('rotate_speed') def _check_rotate_speed(self): @@ -279,7 +293,6 @@ class SfMaintenanceEquipment(models.Model): 'tool_diameter_max': item.tool_diameter_max, 'machine_tool_category': item.machine_tool_category.code, - } machine_tool_list.append(val) # kw = machine_tool_list @@ -293,4 +306,168 @@ class SfMaintenanceEquipment(models.Model): else: raise UserError("没有注册机床信息") + # 修改原生方法,生成维保日期 + @api.depends('effective_date', 'period', 'maintenance_ids.request_date', 'maintenance_ids.close_date', + 'overhaul_period') + def _compute_next_maintenance(self): + date_now = fields.Date.context_today(self) + equipments = self.filtered(lambda x: x.period > 0) + if equipments: + for equipment in equipments: + next_maintenance_todo = self.env['maintenance.request'].search([ + ('equipment_id', '=', equipment.id), + ('sf_maintenance_type', '=', '保养'), + ('stage_id.done', '!=', True), + ('close_date', '=', False)], order="request_date asc", limit=1) + last_maintenance_done = self.env['maintenance.request'].search([ + ('equipment_id', '=', equipment.id), + ('sf_maintenance_type', '=', '保养'), + ('stage_id.done', '=', True), + ('close_date', '!=', False)], order="close_date desc", limit=1) + if next_maintenance_todo and last_maintenance_done: + next_date = next_maintenance_todo.request_date + date_gap = next_maintenance_todo.request_date - last_maintenance_done.close_date + # If the gap between the last_maintenance_done and the next_maintenance_todo one is bigger than 2 times the period and next request is in the future + # We use 2 times the period to avoid creation too closed request from a manually one created + if date_gap > timedelta(0) and date_gap > timedelta( + days=equipment.period) * 2 and next_maintenance_todo.request_date > date_now: + # If the new date still in the past, we set it for today + if last_maintenance_done.close_date + timedelta(days=equipment.period) < date_now: + next_date = date_now + else: + next_date = last_maintenance_done.close_date + timedelta(days=equipment.period) + elif next_maintenance_todo: + next_date = next_maintenance_todo.request_date + date_gap = next_maintenance_todo.request_date - date_now + # If next maintenance to do is in the future, and in more than 2 times the period, we insert an new request + # We use 2 times the period to avoid creation too closed request from a manually one created + if date_gap > timedelta(0) and date_gap > timedelta(days=equipment.period) * 2: + next_date = date_now + timedelta(days=equipment.period) + elif last_maintenance_done: + next_date = last_maintenance_done.close_date + timedelta(days=equipment.period) + # If when we add the period to the last maintenance done and we still in past, we plan it for today + if next_date < date_now: + next_date = date_now + else: + next_date = equipment.effective_date + timedelta(days=equipment.period) + equipment.next_action_date = next_date + else: + self.next_action_date = False + overhaul_equipments = self.filtered(lambda x: x.overhaul_period > 0) + if overhaul_equipments: + for equipment in overhaul_equipments: + next_maintenance_todo = self.env['maintenance.request'].search([ + ('equipment_id', '=', equipment.id), + ('sf_maintenance_type', '=', '检修'), + ('stage_id.done', '!=', True), + ('close_date', '=', False)], order="request_date asc", limit=1) + last_maintenance_done = self.env['maintenance.request'].search([ + ('equipment_id', '=', equipment.id), + ('sf_maintenance_type', '=', '检修'), + ('stage_id.done', '=', True), + ('close_date', '!=', False)], order="close_date desc", limit=1) + if next_maintenance_todo and last_maintenance_done: + next_date = next_maintenance_todo.request_date + date_gap = next_maintenance_todo.request_date - last_maintenance_done.close_date + # If the gap between the last_maintenance_done and the next_maintenance_todo one is bigger than 2 times the period and next request is in the future + # We use 2 times the period to avoid creation too closed request from a manually one created + if date_gap > timedelta(0) and date_gap > timedelta( + days=equipment.overhaul_period) * 2 and next_maintenance_todo.request_date > date_now: + # If the new date still in the past, we set it for today + if last_maintenance_done.close_date + timedelta(days=equipment.overhaul_period) < date_now: + next_date = date_now + else: + next_date = last_maintenance_done.close_date + timedelta(days=equipment.overhaul_period) + elif next_maintenance_todo: + next_date = next_maintenance_todo.request_date + date_gap = next_maintenance_todo.request_date - date_now + # If next maintenance to do is in the future, and in more than 2 times the period, we insert an new request + # We use 2 times the period to avoid creation too closed request from a manually one created + if date_gap > timedelta(0) and date_gap > timedelta(days=equipment.overhaul_period) * 2: + next_date = date_now + timedelta(days=equipment.overhaul_period) + elif last_maintenance_done: + next_date = last_maintenance_done.close_date + timedelta(days=equipment.overhaul_period) + # If when we add the period to the last maintenance done and we still in past, we plan it for today + if next_date < date_now: + next_date = date_now + else: + next_date = equipment.effective_date + timedelta(days=equipment.overhaul_period) + equipment.overhaul_date = next_date + else: + self.overhaul_date = False + # 拼接维保请求字符串 + def _prepare_maintenance_request_vals(self, date): + self.ensure_one() + return { + 'name': _('Preventive Maintenance - %s', self.name), + 'request_date': date, + 'schedule_date': date, + 'category_id': self.category_id.id, + 'equipment_id': self.id, + 'maintenance_type': 'preventive', + 'owner_user_id': self.owner_user_id.id, + 'user_id': self.technician_user_id.id, + 'maintenance_team_id': self.maintenance_team_id.id, + 'duration': self.maintenance_duration, + 'company_id': self.company_id.id or self.env.company.id, + 'equipment_maintenance_id': self.eq_maintenance_id.id, + 'sf_maintenance_type': '保养' + + } + + # 拼接维保请求字符串 + + def _prepare_maintenance_request_vals1(self, date): + self.ensure_one() + return { + 'name': _('Preventive Maintenance - %s', self.name), + 'request_date': date, + 'schedule_date': date, + 'category_id': self.category_id.id, + 'equipment_id': self.id, + 'maintenance_type': 'preventive', + 'owner_user_id': self.owner_user_id.id, + 'user_id': self.technician_user_id.id, + 'maintenance_team_id': self.maintenance_team_id.id, + 'duration': self.overhaul_duration, + 'company_id': self.company_id.id or self.env.company.id, + 'equipment_maintenance_id': self.overhaul_id.id, + 'sf_maintenance_type': '检修' + } + + # 创建维保请求 + def _create_new_request(self, date): + self.ensure_one() + vals = self._prepare_maintenance_request_vals(date) + maintenance_requests = self.env['maintenance.request'].create(vals) + return maintenance_requests + + def _create_new_request1(self, date): + self.ensure_one() + vals = self._prepare_maintenance_request_vals1(date) + maintenance_requests = self.env['maintenance.request'].create(vals) + return maintenance_requests + + # 生成维保请求定时器 + @api.model + def _cron_generate_requests(self): + """ + Generates maintenance request on the next_action_date or today if none exists + """ + for equipment in self.search([('period', '>', 0)]): + next_requests = self.env['maintenance.request'].search([('stage_id.done', '=', False), + ('equipment_id', '=', equipment.id), + ('maintenance_type', '=', 'preventive'), + ('request_date', '=', equipment.next_action_date), + ('sf_maintenance_type', '=', '保养')]) + if not next_requests: + equipment._create_new_request(equipment.next_action_date) + for equipment in self.search([('overhaul_period', '>', 0)]): + next_requests = self.env['maintenance.request'].search([('stage_id.done', '=', False), + ('equipment_id', '=', equipment.id), + ('maintenance_type', '=', 'preventive'), + ('request_date', '=', equipment.overhaul_date), + ('sf_maintenance_type', '=', '检修')]) + if not next_requests: + equipment._create_new_request1(equipment.overhaul_date) diff --git a/sf_maintenance/models/sf_maintenance_requests.py b/sf_maintenance/models/sf_maintenance_requests.py index 3508abcc..1de354fe 100644 --- a/sf_maintenance/models/sf_maintenance_requests.py +++ b/sf_maintenance/models/sf_maintenance_requests.py @@ -26,8 +26,8 @@ class SfMaintenanceEquipmentCategory(models.Model): record.equipment_maintenance_id = False - maintenance_projects = fields.Char(string='维保项目', related='equipment_maintenance_id.maintenance_projects') - maintenance_standards = fields.Char(string='维保标准', related='equipment_maintenance_id.maintenance_standards') + + maintenance_standards = fields.One2many('maintenance.standards','maintenance_request_id', string='维保标准', related='equipment_maintenance_id.maintenance_standards_ids') @api.constrains('equipment_maintenance_id') def _check_equipment_maintenance_id(self): @@ -35,6 +35,12 @@ class SfMaintenanceEquipmentCategory(models.Model): if not record.equipment_maintenance_id: raise UserError(_("设备维保标准不能为空,请选择后再保存")) + def confirm_maintenance(self): + self.write({'stage_id': 2}) + + def confirm_maintenance_done(self): + self.write({'stage_id': 3}) + diff --git a/sf_maintenance/security/ir.model.access.csv b/sf_maintenance/security/ir.model.access.csv index 06e231b9..05ee33a2 100644 --- a/sf_maintenance/security/ir.model.access.csv +++ b/sf_maintenance/security/ir.model.access.csv @@ -2,5 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_equipment_maintenance_standards,equipment_maintenance_standards,model_equipment_maintenance_standards,base.group_user,1,1,1,1 access_sf_maintenance_logs,sf_maintenance_logs,model_sf_maintenance_logs,base.group_user,1,1,1,1 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 diff --git a/sf_maintenance/views/equipment_maintenance_standards_views.xml b/sf_maintenance/views/equipment_maintenance_standards_views.xml index f4b90fa6..7263a135 100644 --- a/sf_maintenance/views/equipment_maintenance_standards_views.xml +++ b/sf_maintenance/views/equipment_maintenance_standards_views.xml @@ -2,31 +2,42 @@ - - equipment.maintenance.standards.form - equipment.maintenance.standards - -
- - - - - - - - - - - - + + equipment.maintenance.standards.form + equipment.maintenance.standards + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + +
+ +
+
+ + equipment.maintenance.standards.tree equipment.maintenance.standards @@ -36,9 +47,7 @@ - - - + @@ -50,7 +59,7 @@ equipment.maintenance.standards - + @@ -58,14 +67,11 @@ - - - 设备维保标准 ir.actions.act_window @@ -79,12 +85,12 @@ - +
\ No newline at end of file diff --git a/sf_maintenance/views/maintenance_request_views.xml b/sf_maintenance/views/maintenance_request_views.xml index d711702d..cd5498c1 100644 --- a/sf_maintenance/views/maintenance_request_views.xml +++ b/sf_maintenance/views/maintenance_request_views.xml @@ -7,6 +7,10 @@ maintenance.request + +