更新sf
This commit is contained in:
@@ -10,13 +10,13 @@
|
||||
""",
|
||||
'category': 'YZ',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['account', 'base'],
|
||||
'depends': ['account', 'base', 'mrp'],
|
||||
'data': [
|
||||
'security/group_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/mrs_base_view.xml',
|
||||
'views/mrs_common_view.xml',
|
||||
'views/menu_view.xml'
|
||||
"views/menu_view.xml"
|
||||
|
||||
],
|
||||
'demo': [
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
import json
|
||||
from odoo import fields, models, api
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.http import request
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -39,8 +45,8 @@ class MachineBrand(models.Model):
|
||||
class MachineTool(models.Model):
|
||||
_name = 'mrs.machine_tool'
|
||||
_description = '机床'
|
||||
|
||||
code = fields.Char('编码')
|
||||
MTcode = fields.Char("编码")
|
||||
code = fields.Char('行业编码')
|
||||
name = fields.Char('名称')
|
||||
knife_type = fields.Selection(
|
||||
[("BT40", "BT40"), ("BT30", "BT30")],
|
||||
@@ -61,12 +67,11 @@ class MachineTool(models.Model):
|
||||
control_system_id = fields.Many2one('mrs.machine.control_system',
|
||||
string="控制系统")
|
||||
# 多个机床型号对应一个机床
|
||||
type_id = fields.Many2one('mrs.machine_tool.type', '型号',
|
||||
compute='_compute_type_id')
|
||||
type_id = fields.Many2one('mrs.machine_tool.type', '型号')
|
||||
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
||||
state = fields.Selection(
|
||||
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
||||
default="", string="状态")
|
||||
default='正常', string="状态")
|
||||
|
||||
# 一个机床对应一個加工工厂,一个加工工厂对应多个机床
|
||||
factory_id = fields.Many2one('res.partner', string='所属工厂',
|
||||
@@ -78,7 +83,108 @@ class MachineTool(models.Model):
|
||||
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
@api.constrains('rotate_speed')
|
||||
def _check_rotate_speed(self):
|
||||
if self.rotate_speed <= 0:
|
||||
raise ValidationError("转速不能为0")
|
||||
|
||||
@api.constrains('precision')
|
||||
def _check_precision(self):
|
||||
if self.precision <= 0.00:
|
||||
raise ValidationError("加工精度不能为0")
|
||||
|
||||
@api.constrains('number_of_knife_library')
|
||||
def _check_number_of_knife_library(self):
|
||||
if self.number_of_knife_library <= 0:
|
||||
raise ValidationError("刀库数量不能为0")
|
||||
|
||||
@api.constrains('x_axis')
|
||||
def _check_x_axis(self):
|
||||
if self.x_axis <= 0:
|
||||
raise ValidationError("加工行程里x轴不能为0")
|
||||
|
||||
@api.constrains('y_axis')
|
||||
def _check_y_axis(self):
|
||||
if self.y_axis <= 0:
|
||||
raise ValidationError("加工行程里y轴不能为0")
|
||||
|
||||
@api.constrains('z_axis')
|
||||
def _check_z_axis(self):
|
||||
if self.z_axis <= 0:
|
||||
raise ValidationError("加工行程里z轴不能为0")
|
||||
|
||||
@api.constrains('b_axis')
|
||||
def _check_b_axis(self):
|
||||
if self.number_of_axles == '四轴':
|
||||
print(self.number_of_axles)
|
||||
if self.b_axis <= 0:
|
||||
raise ValidationError("加工行程里b轴不能为0")
|
||||
|
||||
@api.constrains('c_axis')
|
||||
def _check_c_axis(self):
|
||||
if self.number_of_axles == '五轴':
|
||||
if self.c_axis <= 0:
|
||||
raise ValidationError("加工行程里c轴不能为0")
|
||||
|
||||
@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
|
||||
|
||||
# 注册同步机床
|
||||
def enroll_machine_tool(self):
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
mrs_secret_key = sf_sync_config['mrs_secret_key']
|
||||
headers = Common.get_headers(self, token, mrs_secret_key)
|
||||
strurl = sf_sync_config['mrs_url'] + self.crea_url
|
||||
objs_all = request.env['mrs.machine_tool'].sudo().search([])
|
||||
machine_tool_list = []
|
||||
if objs_all:
|
||||
for item in objs_all:
|
||||
val = {
|
||||
'factory_token': token,
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'code': item.code,
|
||||
'precision': item.precision,
|
||||
'knife_type': item.knife_type,
|
||||
'number_of_knife_library': item.number_of_knife_library,
|
||||
'rotate_speed': item.rotate_speed,
|
||||
'number_of_axles': item.number_of_axles,
|
||||
'control_system_id': self.env['mrs.machine.control_system'].search(
|
||||
[('id', '=', item.control_system_id.id)]).code,
|
||||
'type_id': self.env['mrs.machine_tool.type'].search([('id', '=', item.type_id.id)]).code,
|
||||
'brand_id': self.env['mrs.machine.brand'].search([('id', '=', item.brand_id.id)]).code,
|
||||
'supplier_id': item.supplier_id.id,
|
||||
'x_axis': item.x_axis,
|
||||
'y_axis': item.y_axis,
|
||||
'z_axis': item.z_axis,
|
||||
'b_axis': item.b_axis,
|
||||
'c_axis': item.c_axis,
|
||||
'state': item.state,
|
||||
'active': item.active,
|
||||
|
||||
}
|
||||
machine_tool_list.append(val)
|
||||
# kw = machine_tool_list
|
||||
kw = json.dumps(machine_tool_list, ensure_ascii=False)
|
||||
r = requests.post(strurl, json={}, data={'kw': kw}, headers=headers)
|
||||
print(r)
|
||||
if r == 200:
|
||||
raise ValidationError("机床注册成功")
|
||||
else:
|
||||
raise ValidationError("没有注册机床信息")
|
||||
|
||||
|
||||
class MachineToolType(models.Model):
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
groups="base.group_system"/>-->
|
||||
<menuitem
|
||||
id="menu_mrs_machine_tool"
|
||||
parent="menu_mrs_base"
|
||||
parent="mrp.menu_mrp_configuration"
|
||||
name="机床"
|
||||
sequence="0"
|
||||
sequence="1"
|
||||
action="action_mrs_machine_tool"
|
||||
/>
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
<group>
|
||||
<field name="brand_id" required="1"
|
||||
domain="[('tag_ids', '=', '机床')]"
|
||||
options="{'no_create': True}" />
|
||||
options="{'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="参数">
|
||||
@@ -121,25 +121,27 @@
|
||||
<div class="o_address_format"
|
||||
attrs="{'invisible': [('number_of_axles', '=', False)]}">
|
||||
<label for="x_axis" string="x"/>
|
||||
<field name="x_axis" class="o_address_city" required="1" options="{'format': false}" />
|
||||
<field name="x_axis" class="o_address_city" required="1" options="{'format': false}"/>
|
||||
<label for="y_axis" string="y"/>
|
||||
<field name="y_axis" class="o_address_zip" required="1" options="{'format': false}" />
|
||||
<field name="y_axis" class="o_address_zip" required="1" options="{'format': false}"/>
|
||||
<label for="z_axis" string="z"/>
|
||||
<field name="z_axis" class="o_address_zip" required="1" options="{'format': false}" />
|
||||
<field name="z_axis" class="o_address_zip" required="1" options="{'format': false}"/>
|
||||
<label for="b_axis" string="b"
|
||||
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"/>
|
||||
<field name="b_axis" class="o_address_city" required="1"
|
||||
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}" options="{'format': false}" />
|
||||
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"
|
||||
options="{'format': false}"/>
|
||||
<label for="c_axis" string="c"
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"/>
|
||||
<field name="c_axis" class="o_address_zip" required="1"
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}" options="{'format': false}" />
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"
|
||||
options="{'format': false}"/>
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<field name="rotate_speed" string="转速(min)" required="1" options="{'format': false}"/>
|
||||
<field name="precision" required="1" string="加工精度(mm)"/>
|
||||
<field name="control_system_id" required="1" options="{'no_create': True}" />
|
||||
<field name="control_system_id" required="1" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="其它">
|
||||
@@ -275,24 +277,24 @@
|
||||
<field name="name" required="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<!-- <group string="参数">-->
|
||||
<!-- <field name="type_ids" string="刀具型号">-->
|
||||
<!-- <tree editable="bottom">-->
|
||||
<!-- <field name="category_id" invisible="True"/>-->
|
||||
<!-- <field name="code" string="编码" required="True"/>-->
|
||||
<!-- <field name="name" string="名称" required="True"/>-->
|
||||
<!-- <field name="diameter" string="直径" required="True"/>-->
|
||||
<!-- <field name="long_blade" string="避空长/刃长" required="True"/>-->
|
||||
<!-- <field name="cone_angle_pitch" string="锥角/节距" required="True"/>-->
|
||||
<!-- <field name="shank_diameter" string="柄径" required="True"/>-->
|
||||
<!-- <field name="taper_shank_length" string="锥柄" required="True"/>-->
|
||||
<!-- <field name="tool_length" string="刀具总长" required="True"/>-->
|
||||
<!-- <field name="blade_number" string="刃数" required="True"/>-->
|
||||
<!-- <field name="remark" string="备注"/>-->
|
||||
<!-- <field name="active" string="有效"/>-->
|
||||
<!-- </tree>-->
|
||||
<!-- </field>-->
|
||||
<!-- </group>-->
|
||||
<!-- <group string="参数">-->
|
||||
<!-- <field name="type_ids" string="刀具型号">-->
|
||||
<!-- <tree editable="bottom">-->
|
||||
<!-- <field name="category_id" invisible="True"/>-->
|
||||
<!-- <field name="code" string="编码" required="True"/>-->
|
||||
<!-- <field name="name" string="名称" required="True"/>-->
|
||||
<!-- <field name="diameter" string="直径" required="True"/>-->
|
||||
<!-- <field name="long_blade" string="避空长/刃长" required="True"/>-->
|
||||
<!-- <field name="cone_angle_pitch" string="锥角/节距" required="True"/>-->
|
||||
<!-- <field name="shank_diameter" string="柄径" required="True"/>-->
|
||||
<!-- <field name="taper_shank_length" string="锥柄" required="True"/>-->
|
||||
<!-- <field name="tool_length" string="刀具总长" required="True"/>-->
|
||||
<!-- <field name="blade_number" string="刃数" required="True"/>-->
|
||||
<!-- <field name="remark" string="备注"/>-->
|
||||
<!-- <field name="active" string="有效"/>-->
|
||||
<!-- </tree>-->
|
||||
<!-- </field>-->
|
||||
<!-- </group>-->
|
||||
<group string="其它">
|
||||
<field name="remark"/>
|
||||
</group>
|
||||
@@ -314,16 +316,21 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
#------------------机床注册------------------
|
||||
#------------------机床注册------------------
|
||||
|
||||
<record model="ir.ui.view" id="search_mrs_machine_tool_view">
|
||||
<field name="name">search.mrs.machine_tool</field>
|
||||
<field name="model">mrs.machine_tool</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="机床">
|
||||
<field name="name" string="模糊搜索"
|
||||
filter_domain="['|',('name', 'ilike', self),('remark', 'ilike', self)]"/>
|
||||
<field name="name" string="名称" filter_domain="[('name', 'ilike', self)]"/>
|
||||
<field name="type_id" string="型号" filter_domain="[('type_id', 'ilike', self)]"/>
|
||||
<searchpanel>
|
||||
<field name="brand_id" icon="fa-building" enable_counters="1"/>
|
||||
<!-- <field name="type_id" icon="fa-users" enable_counters="1"/>-->
|
||||
</searchpanel>
|
||||
</search>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -335,55 +342,71 @@
|
||||
<field name="code"/>
|
||||
<field name="name"/>
|
||||
<field name="brand_id"/>
|
||||
<field name="remark"/>
|
||||
<field name="type_id"/>
|
||||
<field name="factory_id"/>
|
||||
<field name="registration_date"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="form_mrs_machine_tool">
|
||||
<record model="ir.ui.view" id="mrs_machine_tool_form">
|
||||
<field name="name">form.mrs.machine_tool</field>
|
||||
<field name="model">mrs.machine_tool</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="机床">
|
||||
<header>
|
||||
<button type="object" class="oe_highlight" name ='enroll_machine_tool' string="机床注册" />
|
||||
</header>
|
||||
<group string="基本信息">
|
||||
<group>
|
||||
<field name="code" force_save="1" readonly="1"/>
|
||||
<field name="name" required="1"/>
|
||||
<field name="MTcode" string="编码" />
|
||||
|
||||
<field name="brand_id"
|
||||
required="1"
|
||||
domain="[('tag_ids', '=', '机床')]"
|
||||
options="{'no_create': True}"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="brand_id" required="1"
|
||||
domain="[('tag_ids', '=', '机床')]"/>
|
||||
<field name="name" required="1"/>
|
||||
<field name="type_id" required="1" options="{'no_create': True}" domain="[('brand_id', '=', brand_id)]" attrs="{'invisible': [('brand_id','=',False)]}"/>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<field name="code" readonly="1" string="行业编码" force_save="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="参数">
|
||||
<group>
|
||||
<field name="knife_type" required="1"/>
|
||||
<field name="number_of_knife_library" required="1" options="{'format': false}"/>
|
||||
<field name="number_of_axles" required="1" widget="radio" options="{'horizontal': true}"/>
|
||||
<field name="number_of_axles" widget="radio" options="{'horizontal': true}"/>
|
||||
<label for="x_axis" string="加工行程(mm)"
|
||||
attrs="{'invisible': [('number_of_axles', '=', False)]}"/>
|
||||
<div class="o_address_format"
|
||||
attrs="{'invisible': [('number_of_axles', '=', False)]}">
|
||||
<label for="x_axis" string="x"/>
|
||||
<field name="x_axis" class="o_address_city" required="1"/>
|
||||
<field name="x_axis" class="o_address_city" required="1" options="{'format': false}"/>
|
||||
<label for="y_axis" string="y"/>
|
||||
<field name="y_axis" class="o_address_zip" required="1"/>
|
||||
<field name="y_axis" class="o_address_zip" required="1" options="{'format': false}"/>
|
||||
<label for="z_axis" string="z"/>
|
||||
<field name="z_axis" class="o_address_zip" required="1"/>
|
||||
<field name="z_axis" class="o_address_zip" required="1" options="{'format': false}"/>
|
||||
<label for="b_axis" string="b"
|
||||
attrs="{'invisible': [('number_of_axles', '=', '3轴')]}"/>
|
||||
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"/>
|
||||
<field name="b_axis" class="o_address_city" required="1"
|
||||
attrs="{'invisible': [('number_of_axles', '=', '3轴')]}"/>
|
||||
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"
|
||||
options="{'format': false}"/>
|
||||
<label for="c_axis" string="c"
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['3轴','4轴'])]}"/>
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"/>
|
||||
<field name="c_axis" class="o_address_zip" required="1"
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['3轴','4轴'])]}"/>
|
||||
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"
|
||||
options="{'format': false}"/>
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<field name="rotate_speed" string="转速(min)" required="1" options="{'format': false}"/>
|
||||
<field name="precision" required="1" string="加工精度(mm)" />
|
||||
<field name="control_system_id" required="1" />
|
||||
<field name="rotate_speed" required="1" string="转速(min)" options="{'format': false}"/>
|
||||
<field name="precision" required="1" string="加工精度(mm)"/>
|
||||
<field name="control_system_id" required="1" options="{'no_create': True}"/>
|
||||
<field name="state" widget="selection"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="其它">
|
||||
@@ -394,20 +417,21 @@
|
||||
</record>
|
||||
|
||||
<record id="action_mrs_machine_tool" model="ir.actions.act_window">
|
||||
<field name="name">机床注册</field>
|
||||
<field name="name">机床</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">mrs.machine_tool</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<!-- <field name="search_view_id" ref="view_okr_filter"/>-->
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
[机床注册]
|
||||
[机床] 还没有哦!点左上角的[创建]按钮,沙发归你了!
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
#------------------控制系统------------------
|
||||
#------------------控制系统------------------
|
||||
|
||||
<record model="ir.ui.view" id="search_mrs_machine_control_system_view">
|
||||
<field name="name">search.mrs.machine.control_system</field>
|
||||
|
||||
@@ -80,16 +80,16 @@
|
||||
<field name="doall" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.cron" id="sf_cron8">
|
||||
<field name="name">同步注册机床</field>
|
||||
<field name="model_id" ref="model_mrs_machine_tool"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.enroll_machine_tool()</field>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="doall" eval="False"/>
|
||||
</record>
|
||||
<!-- <record model="ir.cron" id="sf_cron8">-->
|
||||
<!-- <field name="name">同步注册机床</field>-->
|
||||
<!-- <field name="model_id" ref="model_mrs_machine_tool"/>-->
|
||||
<!-- <field name="state">code</field>-->
|
||||
<!-- <field name="code">model.enroll_machine_tool()</field>-->
|
||||
<!-- <field name="interval_number">1</field>-->
|
||||
<!-- <field name="interval_type">days</field>-->
|
||||
<!-- <field name="numbercall">-1</field>-->
|
||||
<!-- <field name="doall" eval="False"/>-->
|
||||
<!-- </record>-->
|
||||
|
||||
<record model="ir.cron" id="sf_cron9">
|
||||
<field name="name">同步资源库机床型号</field>
|
||||
|
||||
@@ -517,49 +517,7 @@ class MachineTool(models.Model):
|
||||
url = '/api/machine_tool/list'
|
||||
crea_url = '/api/machine_tool/create'
|
||||
|
||||
# 注册同步机床
|
||||
def enroll_machine_tool(self):
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
mrs_secret_key = sf_sync_config['mrs_secret_key']
|
||||
headers = Common.get_headers(self, token, mrs_secret_key)
|
||||
strurl = sf_sync_config['mrs_url'] + self.crea_url
|
||||
objs_all = request.env['mrs.machine_tool'].sudo().search([])
|
||||
machine_tool_list = []
|
||||
if objs_all:
|
||||
for item in objs_all:
|
||||
val = {
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'code': item.code,
|
||||
'precision': item.precision,
|
||||
'knife_type': item.knife_type,
|
||||
'registration_date': str(item.registration_date),
|
||||
'number_of_knife_library': item.number_of_knife_library,
|
||||
'rotate_speed': item.rotate_speed,
|
||||
'number_of_axles': item.number_of_axles,
|
||||
# 'control_system_id': item.control_system_id.id,
|
||||
# 'type_id': item.type_id.id,
|
||||
# 'brand_id': item.brand_id.id,
|
||||
'factory_id': item.factory_id.id,
|
||||
'supplier_id': item.supplier_id.id,
|
||||
'x_axis': item.x_axis,
|
||||
'y_axis': item.y_axis,
|
||||
'z_axis': item.z_axis,
|
||||
'b_axis': item.b_axis,
|
||||
'c_axis': item.c_axis,
|
||||
'state': item.state,
|
||||
'active': item.active
|
||||
}
|
||||
machine_tool_list.append(val)
|
||||
# kw = machine_tool_list
|
||||
kw = json.dumps(machine_tool_list, ensure_ascii=False)
|
||||
print(type(kw))
|
||||
|
||||
r = requests.post(strurl, json={}, data={'kw': kw}, headers=headers)
|
||||
|
||||
else:
|
||||
raise ValidationError("没有机床信息")
|
||||
|
||||
# 定时同步机床
|
||||
def sync_machine_tool(self):
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<button type="object" class="oe_highlight" name="sf_all_sync" string="同步资源库所有基础数据" />
|
||||
<button type="object" class="oe_highlight" name="sf_all_sync" string="同步资源库所有基础数据"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user