Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/改造原生库存模块
This commit is contained in:
@@ -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='设备维保计划')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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,8 +63,6 @@ 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')
|
||||
@@ -279,7 +284,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 +297,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)
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
@@ -2,31 +2,42 @@
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_equipment_maintenance_standards_form" model="ir.ui.view">
|
||||
<field name="name">equipment.maintenance.standards.form</field>
|
||||
<field name="model">equipment.maintenance.standards</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="设备维保标准">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="code" readonly="1" force_save="1"/>
|
||||
<field name="maintenance_type" required="1"/>
|
||||
<field name="name" required="1"/>
|
||||
<field name="created_user_id"/>
|
||||
<field name="maintenance_equipment_category_id" required="1"/>
|
||||
<field name="maintenance_equipment_ids" widget="many2many_tags"/>
|
||||
<field name="maintenance_projects" required="1"/>
|
||||
<field name="maintenance_standards" required="1"/>
|
||||
<field name="eq_maintenance_ids"/>
|
||||
<field name="overhaul_ids" />
|
||||
<record id="view_equipment_maintenance_standards_form" model="ir.ui.view">
|
||||
<field name="name">equipment.maintenance.standards.form</field>
|
||||
<field name="model">equipment.maintenance.standards</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="设备维保标准">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="code" readonly="1" force_save="1"/>
|
||||
<field name="maintenance_type" required="1"/>
|
||||
<field name="name" required="1"/>
|
||||
<field name="eq_maintenance_ids" invisible='1'/>
|
||||
<field name="overhaul_ids" invisible='1'/>
|
||||
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_equipment_maintenance_standards_tree" model="ir.ui.view">
|
||||
</group>
|
||||
<group>
|
||||
<field name="created_user_id"/>
|
||||
<field name="maintenance_equipment_category_id" required="1"/>
|
||||
<field name="maintenance_equipment_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="维保项目">
|
||||
<field name="maintenance_standards_ids" widget="ony2many">
|
||||
<tree editable="top" create="true" string="维保项目">
|
||||
<field name="name"/>
|
||||
<field name="maintenance_standards"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_equipment_maintenance_standards_tree" model="ir.ui.view">
|
||||
<field name="name">equipment.maintenance.standards.tree</field>
|
||||
<field name="model">equipment.maintenance.standards</field>
|
||||
<field name="arch" type="xml">
|
||||
@@ -36,9 +47,7 @@
|
||||
<field name="name" required="1"/>
|
||||
<field name="maintenance_equipment_category_id" required="1"/>
|
||||
<field name="maintenance_equipment_ids"/>
|
||||
<field name="maintenance_projects" required="1"/>
|
||||
<field name="maintenance_standards" required="1"/>
|
||||
<field name="created_user_id"/>
|
||||
<field name="created_user_id"/>
|
||||
<field name="create_date" string="创建时间"/>
|
||||
|
||||
</tree>
|
||||
@@ -50,7 +59,7 @@
|
||||
<field name="model">equipment.maintenance.standards</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<searchpanel>
|
||||
<searchpanel>
|
||||
<field name="maintenance_type" icon="fa-building" enable_counters="1"/>
|
||||
</searchpanel>
|
||||
<field name="code" string="编码"/>
|
||||
@@ -58,14 +67,11 @@
|
||||
<field name="name" string="日常机床保养"/>
|
||||
<field name="created_user_id" string="创建人"/>
|
||||
<field name="maintenance_equipment_category_id" string="设备类别"/>
|
||||
<field name="maintenance_projects" string="维保项目"/>
|
||||
<field name="maintenance_standards" string="维保标准"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record id="action_equipment_maintenance_standards" model="ir.actions.act_window">
|
||||
<field name="name">设备维保标准</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
@@ -79,12 +85,12 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="menu_equipment_maintenance_standards"
|
||||
name="设备维保标准"
|
||||
parent="maintenance.menu_maintenance_configuration"
|
||||
action="action_equipment_maintenance_standards"
|
||||
sequence="4"/>
|
||||
<menuitem
|
||||
id="menu_equipment_maintenance_standards"
|
||||
name="设备维保标准"
|
||||
parent="maintenance.menu_maintenance_configuration"
|
||||
action="action_equipment_maintenance_standards"
|
||||
sequence="4"/>
|
||||
|
||||
|
||||
</odoo>
|
||||
@@ -7,6 +7,10 @@
|
||||
<field name="model">maintenance.request</field>
|
||||
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='archive_equipment_request']" position="before">
|
||||
<button name="confirm_maintenance" string="确认维保计划" type="object" class="btn-primary" attrs="{'invisible': [('stage_id', '!=', 1)]}" />
|
||||
<button name="confirm_maintenance_done" string="标记已完成" type="object" class="btn-primary" attrs="{'invisible': [('stage_id', '!=', 2)]}" />
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='maintenance_type']" position="replace">
|
||||
<field name="sf_maintenance_type" widget="radio"/>
|
||||
<field name="equipment_maintenance_id"/>
|
||||
@@ -17,8 +21,12 @@
|
||||
<notebook>
|
||||
<page string="维保标准" attrs="{'invisible': [('equipment_maintenance_id', '=', False)]}">
|
||||
<group>
|
||||
<field name="maintenance_projects"/>
|
||||
<field name="maintenance_standards"/>
|
||||
<field name="maintenance_standards" widget="ony2many">
|
||||
<tree create="False" string="维保项目">
|
||||
<field name="name"/>
|
||||
<field name="maintenance_standards"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
</page>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
'security/group_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'report/tray_report.xml',
|
||||
'views/mrp_maintenance_views.xml',
|
||||
# 'views/mrp_maintenance_views.xml',
|
||||
'views/mrp_routing_workcenter_view.xml',
|
||||
'views/mrp_workcenter_views.xml',
|
||||
'views/mrp_workorder_view.xml',
|
||||
|
||||
@@ -787,6 +787,10 @@ class MachineToolType(models.Model):
|
||||
result = json.loads(r['result'])
|
||||
if result['status'] == 1:
|
||||
for item in result['machine_tool_type_all_list']:
|
||||
if item.get('machine_tool_picture'):
|
||||
image = base64.b64decode(item['machine_tool_picture'])
|
||||
else:
|
||||
image = ''
|
||||
brand = self.env['sf.machine_tool.type'].search(
|
||||
[("code", '=', item['code'])])
|
||||
if not brand:
|
||||
@@ -811,7 +815,7 @@ class MachineToolType(models.Model):
|
||||
[('code', '=', item['control_system_id'])]).id,
|
||||
"active": item['active'],
|
||||
'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id,
|
||||
'machine_tool_picture': base64.b64decode(item['machine_tool_picture']),
|
||||
'machine_tool_picture':image,
|
||||
"heightened_way": item['heightened_way'],
|
||||
"workpiece_load": item['workpiece_load'],
|
||||
"lead_screw": item['lead_screw'],
|
||||
|
||||
1
sf_plan_management/__init__.py
Normal file
1
sf_plan_management/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
34
sf_plan_management/__manifest__.py
Normal file
34
sf_plan_management/__manifest__.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 计划管理',
|
||||
'version': '1.0',
|
||||
'summary': '智能工厂计划管理',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
在本模块,定义了计划管理的清单和原型
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': [],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/paln_base_view.xml',
|
||||
'views/menu_view.xml'
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
'assets': {
|
||||
|
||||
'web.assets_qweb': [
|
||||
],
|
||||
'web.assets_backend':[
|
||||
]
|
||||
|
||||
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
2
sf_plan_management/models/__init__.py
Normal file
2
sf_plan_management/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import calendar_base
|
||||
from . import base
|
||||
43
sf_plan_management/models/base.py
Normal file
43
sf_plan_management/models/base.py
Normal file
@@ -0,0 +1,43 @@
|
||||
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='品牌')
|
||||
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')
|
||||
participate_in_scheduling = fields.Boolean(string='参与排程', default=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
50
sf_plan_management/models/calendar_base.py
Normal file
50
sf_plan_management/models/calendar_base.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from odoo import models, fields, api
|
||||
import re
|
||||
|
||||
|
||||
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='休息日')
|
||||
|
||||
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='班次')
|
||||
|
||||
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('working_shift_char', 'working_shift_select')
|
||||
def _onchange_working_shift(self):
|
||||
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('输入的日结束时间不正确,请重新输入!')
|
||||
|
||||
|
||||
11
sf_plan_management/security/ir.model.access.csv
Normal file
11
sf_plan_management/security/ir.model.access.csv
Normal file
@@ -0,0 +1,11 @@
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
28
sf_plan_management/views/menu_view.xml
Normal file
28
sf_plan_management/views/menu_view.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<menuitem id="menu_sf_plan_manage"
|
||||
name="计划管理"
|
||||
parent="mrp.menu_mrp_root"
|
||||
sequence="22"
|
||||
/>
|
||||
|
||||
<menuitem id="menu_sf_basic_setting"
|
||||
name="基础设置"
|
||||
parent="menu_sf_plan_manage"
|
||||
sequence="0"
|
||||
/>
|
||||
|
||||
<menuitem id="menu_sf_work_log_setting"
|
||||
name="工作日历设置"
|
||||
parent="menu_sf_basic_setting"
|
||||
action="sf_work_log_setting_act"
|
||||
sequence="0"
|
||||
/>
|
||||
|
||||
<menuitem id="menu_sf_procedure_equipment_resource_setting"
|
||||
name="工序设备资源设置"
|
||||
parent="menu_sf_basic_setting"
|
||||
action="sf_procedure_equipment_resource_setting_act"
|
||||
sequence="10"
|
||||
/>
|
||||
</odoo>
|
||||
103
sf_plan_management/views/paln_base_view.xml
Normal file
103
sf_plan_management/views/paln_base_view.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<!--========================================工作日历设置========================================-->
|
||||
<record id="sf_work_log_setting_tree" model="ir.ui.view">
|
||||
<field name="name">工作日历设置</field>
|
||||
<field name="model">sf.work.log.setting</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="start_time"/>
|
||||
<field name="end_time"/>
|
||||
<field name="duration"/>
|
||||
<field name="day_off"/>
|
||||
<field name="working_shift"/>
|
||||
<field name="status"/>
|
||||
<field name="update_person"/>
|
||||
<field name="update_time"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sf_work_log_setting_form" model="ir.ui.view">
|
||||
<field name="name">工作日历设置</field>
|
||||
<field name="model">sf.work.log.setting</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet string-="工作日历设置">
|
||||
<group string="基础信息">
|
||||
<field name="name"/>
|
||||
</group>
|
||||
<group string="选择班次">
|
||||
<group>
|
||||
<field name="user_defined_working_shift_status"/>
|
||||
<field name="working_shift" invisible="True"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="working_shift_char" attrs="{'invisible': [('user_defined_working_shift_status', '=', False)]}"/>
|
||||
<field name="working_shift_select" attrs="{'invisible': [('user_defined_working_shift_status', '!=', False)]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="工作时间">
|
||||
<group>
|
||||
<!-- <field name="start_time" widget="char" placeholder="请输入的时间为:00:00-24:00"/>-->
|
||||
<field name="start_time" options="{'no_date': True, 'format': 'HH:mm:ss'}"/>
|
||||
<field name="duration"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="end_time" widget="char" placeholder="请输入的时间为:00:00-24:00"/>
|
||||
<field name="day_off"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="日历状态">
|
||||
<field name="status"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sf_work_log_setting_act" model="ir.actions.act_window">
|
||||
<field name="name">工作日历设置</field>
|
||||
<field name="res_model">sf.work.log.setting</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!--========================================工序设备资源设置========================================-->
|
||||
<record id="sf_procedure_equipment_resource_setting_tree" model="ir.ui.view">
|
||||
<field name="name">工序设备资源设置</field>
|
||||
<field name="model">sf.procedure.equipment.resource.setting</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="machine_tool_name"/>
|
||||
<field name="brand"/>
|
||||
<field name="model"/>
|
||||
<field name="production_capacity"/>
|
||||
<field name="working_calendar"/>
|
||||
<field name="working_shift"/>
|
||||
<field name="create_time"/>
|
||||
<field name="stale_dated_time"/>
|
||||
<field name="status"/>
|
||||
<field name="participate_in_scheduling"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- <record id="sf_procedure_equipment_resource_setting_form" model="ir.ui.view">-->
|
||||
<!-- <field name="name">工序设备资源设置</field>-->
|
||||
<!-- <field name="model">sf.procedure.equipment.resource.setting</field>-->
|
||||
<!-- <field name="arch" type="xml">-->
|
||||
<!-- <form>-->
|
||||
|
||||
<!-- </form>-->
|
||||
<!-- </field>-->
|
||||
<!-- </record>-->
|
||||
|
||||
<record id="sf_procedure_equipment_resource_setting_act" model="ir.actions.act_window">
|
||||
<field name="name">工序设备资源设置</field>
|
||||
<field name="res_model">sf.procedure.equipment.resource.setting</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user