239 lines
8.9 KiB
Python
239 lines
8.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
|
|
from odoo import fields, models, api
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MachineBrandTags(models.Model):
|
|
_name = 'mrs.machine.brand.tags'
|
|
_description = '标签'
|
|
brand_id = fields.Many2one('mrs.machine.brand', '品牌')
|
|
name = fields.Char('名称', size=50)
|
|
color = fields.Integer('颜色', default=0)
|
|
active = fields.Boolean('有效', default=True)
|
|
|
|
|
|
class MachineControlSystem(models.Model):
|
|
_name = 'mrs.machine_tool.type.control_system'
|
|
_description = '控制系统'
|
|
code = fields.Char('编码')
|
|
name = fields.Char('名称', size=10)
|
|
# type_id = fields.Many2one('mrs.machine_tool.type')
|
|
brand_id = fields.Many2one('mrs.machine.brand', '品牌')
|
|
active = fields.Boolean('有效', default=True)
|
|
|
|
|
|
# 品牌标签
|
|
class MachineBrand(models.Model):
|
|
_name = 'mrs.machine.brand'
|
|
_description = '品牌'
|
|
|
|
name = fields.Char('名称')
|
|
tag_ids = fields.Many2many('mrs.machine.brand.tags', 'rel_machine_brand_tags', string='类别')
|
|
image_brand = fields.Image("品牌图片")
|
|
active = fields.Boolean('有效', default=True)
|
|
code = fields.Char('编码')
|
|
|
|
|
|
# 机床
|
|
class MachineTool(models.Model):
|
|
_name = 'mrs.machine_tool'
|
|
_description = '机床'
|
|
|
|
code = fields.Char('编码')
|
|
name = fields.Char('名称')
|
|
knife_type = fields.Selection(
|
|
[("BT40", "BT40"), ("BT30", "BT30")],
|
|
default="", string="刀把类型")
|
|
number_of_knife_library = fields.Integer('刀库数量')
|
|
rotate_speed = fields.Integer('转速')
|
|
number_of_axles = fields.Selection(
|
|
[("三轴", "三轴"), ("四轴", "四轴"), ("五轴", "五轴")],
|
|
default="", string="轴数")
|
|
# 加工进程
|
|
x_axis = fields.Integer('X轴')
|
|
y_axis = fields.Integer('Y轴')
|
|
z_axis = fields.Integer('Z轴')
|
|
b_axis = fields.Integer('B轴')
|
|
c_axis = fields.Integer('C轴')
|
|
remark = fields.Text('备注')
|
|
precision = fields.Float('加工精度')
|
|
control_system_id = fields.Many2one('mrs.machine_tool.type.control_system',
|
|
string="控制系统")
|
|
# 多个机床型号对应一个机床
|
|
type_id = fields.Many2one('mrs.machine_tool.type', '型号',
|
|
compute='_compute_type_id')
|
|
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
|
state = fields.Selection(
|
|
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
|
default="", string="状态")
|
|
|
|
# 一个机床对应一個加工工厂,一个加工工厂对应多个机床
|
|
factory_id = fields.Many2one('res.partner', string='所属工厂',
|
|
domain="[('is_factory', '=', True)]")
|
|
# 一个机床对应一个供应商,一个供应商对应多个机床
|
|
supplier_id = fields.Many2one('res.partner', string='制造商',
|
|
domain="[('is_vendor', '=', True)]")
|
|
registration_date = fields.Date('注册日期')
|
|
|
|
active = fields.Boolean('有效', default=True)
|
|
|
|
# @api.depends('type_id')
|
|
# def _compute_type_id(self):
|
|
# to_reset = self.filtered(lambda e: e.type_id != e.type_id.id)
|
|
# to_reset.type_id = False
|
|
|
|
# 编码规则:加工工厂编码-品牌编码-注册年月-00001
|
|
# def get_machine_tool_code(self):
|
|
# partner = self.env['res.partner'].sudo().search(
|
|
# [('is_factory', '=', True)],
|
|
# limit=1,
|
|
# order="id desc")
|
|
# brand = self.env['mrs.machine.brand'].sudo().search(
|
|
# [('tag_ids', '=', '机床')],
|
|
# limit=1,
|
|
# order="id desc")
|
|
# if not brand:
|
|
# num = item.brand_id.code + "%04d" % 1
|
|
# item.code = num
|
|
# else:
|
|
# print('--------')
|
|
# print(type)
|
|
# m = int(type.code[-4:]) + 1
|
|
# num = item.brand_id.code + "%04d" % m
|
|
# item.code = num
|
|
|
|
# 选择机床型号时,该型号的基本信息带出并赋给机床对应的信息里
|
|
|
|
# @api.onchange('type_id')
|
|
# def get_type_info(self):
|
|
# for item in self:
|
|
# item.knife_type = item.type_id.knife_type
|
|
# item.number_of_knife_library = item.type_id.number_of_knife_library
|
|
# item.number_of_axles = item.type_id.number_of_axles
|
|
# item.rotate_speed = item.type_id.rotate_speed
|
|
# item.precision = item.type_id.precision
|
|
# item.control_system_id = item.type_id.control_system_id
|
|
# item.x_axis = item.type_id.x_axis
|
|
# item.y_axis = item.type_id.y_axis
|
|
# item.z_axis = item.type_id.z_axis
|
|
# item.b_axis = item.type_id.b_axis
|
|
# item.c_axis = item.type_id.c_axis
|
|
|
|
|
|
class MachineToolType(models.Model):
|
|
_name = 'mrs.machine_tool.type'
|
|
_description = '机床型号'
|
|
# _order = 'priority desc, code, name, id'
|
|
|
|
name = fields.Char('名称')
|
|
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
|
knife_type = fields.Selection(
|
|
[("BT40", "BT40"), ("BT30", "BT30")],
|
|
default="", string="刀把类型")
|
|
number_of_knife_library = fields.Integer('刀库数量')
|
|
rotate_speed = fields.Integer('转速')
|
|
# 多个型号对应一个机床
|
|
machine_tool_id = fields.Many2one('mrs.machine_tool', '机床')
|
|
number_of_axles = fields.Selection(
|
|
[("三轴", "三轴"), ("四轴", "四轴"), ("五轴", "五轴")],
|
|
default="", string="轴数")
|
|
# 加工进程
|
|
x_axis = fields.Integer('X轴')
|
|
y_axis = fields.Integer('Y轴')
|
|
z_axis = fields.Integer('Z轴')
|
|
b_axis = fields.Integer('B轴')
|
|
c_axis = fields.Integer('C轴')
|
|
remark = fields.Text('备注')
|
|
precision = fields.Float('加工精度')
|
|
control_system_id = fields.Many2one('mrs.machine_tool.type.control_system',
|
|
string="控制系统")
|
|
active = fields.Boolean('有效', default=True)
|
|
code = fields.Char('编码')
|
|
|
|
# @api.onchange('brand_id')
|
|
# def get_machine_tool_type_code(self):
|
|
# for item in self:
|
|
# if not item.brand_id:
|
|
# return False
|
|
# type = self.env['mrs.machine_tool.type'].sudo().search(
|
|
# [('brand_id', '=', item.brand_id.id)],
|
|
# limit=1,
|
|
# order="id desc"
|
|
# )
|
|
# print(item.brand_id.id)
|
|
# if not type:
|
|
# num = item.brand_id.code + "%04d" % 1
|
|
# item.code = num
|
|
# print(item.code)
|
|
# else:
|
|
# print('----------')
|
|
# m = int(type.code[-4:]) + 1
|
|
# num = item.brand_id.code + "%04d" % m
|
|
# item.code = num
|
|
# print(item.code)
|
|
|
|
|
|
# 刀具
|
|
class CuttingTool(models.Model):
|
|
_name = 'mrs.cutting_tool.category'
|
|
_description = '刀具类别'
|
|
|
|
# def get_cutting_tool_category_code(self):
|
|
# code = self.env['mrs.cutting_tool.category'].sudo().search(
|
|
# [('code', '!=', False)], limit=1,
|
|
# order="id desc")
|
|
# if not code:
|
|
# num = "%03d" % 1
|
|
# else:
|
|
# m = int(code.code) + 1
|
|
# num = "%03d" % m
|
|
# return num
|
|
|
|
code = fields.Char('编码')
|
|
name = fields.Char('名称')
|
|
# type_ids = fields.One2many('mrs.cutting_tool.type', 'category_id', string='刀具型号')
|
|
remark = fields.Text('备注')
|
|
active = fields.Boolean('有效', default=True)
|
|
|
|
|
|
class CuttingToolType(models.Model):
|
|
_name = 'mrs.cutting_tool.type'
|
|
_description = '刀具型号'
|
|
|
|
code = fields.Char('编码')
|
|
name = fields.Char('名称')
|
|
diameter = fields.Integer('直径')
|
|
long_blade = fields.Integer('避空长/刃长')
|
|
cone_angle_pitch = fields.Integer('锥角/节距')
|
|
shank_diameter = fields.Integer('柄径')
|
|
taper_shank_length = fields.Integer('锥柄长')
|
|
tool_length = fields.Integer('刀具总长')
|
|
blade_number = fields.Integer('刃数')
|
|
category_id = fields.Many2one('mrs.cutting_tool.category', string='刀具类别')
|
|
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
|
remark = fields.Text('备注')
|
|
active = fields.Boolean('有效', default=True)
|
|
|
|
# @api.onchange('brand_id', 'category_id')
|
|
# def get_cutting_tool_type_code(self):
|
|
# for item in self:
|
|
# if not item.brand_id:
|
|
# return False
|
|
# if not item.category_id:
|
|
# return False
|
|
# type = self.env['mrs.cutting_tool.type'].sudo().search(
|
|
# [('brand_id', '=', item.brand_id.id), ('brand_id', '=', item.category_id.id)],
|
|
# limit=1,
|
|
# order="id desc"
|
|
# )
|
|
# if not type:
|
|
# num = item.brand_id.code + item.category_id.code + "%03d" % 1
|
|
# item.code = num
|
|
# else:
|
|
# m = int(type.code[-4:]) + 1
|
|
# num = item.brand_id.code + item.category_id.code + "%03d" % m
|
|
# item.code = num
|