增加合并下发向导,增加cnc模型的缺省tree视图

This commit is contained in:
mgw
2023-02-23 08:52:56 +08:00
parent d81cf77bbe
commit 28659bfc95
13 changed files with 260 additions and 9 deletions

View File

@@ -1 +1,2 @@
from . import models
from . import models
from . import wizard

View File

@@ -16,13 +16,20 @@
'data': [
# 定义权限组放在最上面
# 权限组
'security/ir.model.access.csv',
'wizard/up_select.xml',
'views/cnc.xml',
'views/compensation.xml',
'views/ftp_button.xml',
'views/SfWorkOrderBarcodes.xml',
'views/WorkCenterBarcodes.xml',
'views/Stock_picking_Barcodes.xml',
'views/machine_monitor.xml',
'views/machine_info_present.xml',
'views/delivery_record.xml',
],
'assets': {

View File

@@ -23,7 +23,6 @@ _logger = logging.getLogger(__name__)
class FtpButton(models.Model):
_inherit = 'sf.cnc.processing'
button_state = fields.Boolean(string='是否已经下发')
user_permissions = fields.Boolean(string='权限', related='workorder_id.user_permissions')
state = fields.Selection(string='状态', related='workorder_id.state')
@@ -301,12 +300,13 @@ class WorkCenterBarcode(models.Model):
# 存在本地的文件下发到机床
_logger.info("=====================11================")
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
item.button_state = True
# _logger.info("=====================22================")
except Exception as e:
_logger.info("=====================================", e)
raise UserError('NC下发执行超时, 请检查下发状态')
# 下发都执行完毕后按钮标志位变为true
self.button_up_all_state = True
# # 下发都执行完毕后按钮标志位变为true
# self.cnc_ids.button_state = True
def get__state(self):
pay_time = str(datetime.now())
@@ -338,3 +338,16 @@ class WorkCenterBarcode(models.Model):
}
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
def action_up_select(self):
return {
'name': '选择要下发的程序文件',
'view_mode': 'tree,form',
# 'res_model': self._name,
'res_model': 'sf_tray_form_inherit',
'target': 'main', # 打开方式
# 'domain': [('project_num', '=', self.project_num), ('state', '=', 'done')], # 域
'type': 'ir.actions.act_window', # 返回的类型
}

View File

@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ftp_client,ftp.client,model_ftp_client,base.group_user,1,1,1,1
access_up_select_wizard,up.select.wizard,model_up_select_wizard,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_ftp_client access_up_select_wizard ftp.client up.select.wizard model_ftp_client model_up_select_wizard base.group_user 1 1 1 1
3

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sf_cnc_tree_view" model="ir.ui.view">
<field name="name">sf.cnc.tree</field>
<field name="model">sf.cnc.processing</field>
<field name="arch" type="xml">
<tree>
<field name="sequence_number"/>
<field name="program_name"/>
<field name="cnc_id" string="文件"/>
<field name="cutting_tool_name"/>
<field name="cutting_tool_no"/>
<field name="processing_type"/>
<field name="margin_x_y"/>
<field name="margin_z"/>
<field name="depth_of_processing_z"/>
<field name="cutting_tool_extension_length"/>
<field name="cutting_tool_handle_type"/>
<field name="estimated_processing_time"/>
<field name="remark"/>
</tree>
</field>
</record>
</odoo>

View File

@@ -19,11 +19,13 @@
class="btn-primary" attrs='{"invisible": ["|",
("state","!=","progress"),("user_permissions","=",False)]}'/>
<span>&#32;</span>
<field name="button_up_all_state" attrs='{"invisible": ["|",
("state","!=","progress"),("user_permissions","=",False)]}'/>
<!-- <field name="button_up_all_state" attrs='{"invisible": ["|",-->
<!-- ("state","!=","progress"),("user_permissions","=",False)]}'/>-->
<button string="一键下发" name="up_all" type="object" style="text-align: right;" confirm="是否确认一键下发"
class="btn-primary" attrs='{"invisible": ["|",
("state","!=","progress"),("user_permissions","=",False)]}'/>
<span>&#32;</span>
<button string="合并下发" id="action_up_select" name="%(sf_machine_connect.action_up_select)d" type="action" class="btn-primary" context="{'default_workorder_id': id}"/>
</div>
</div>
</group>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_delivery_record_form_inherit_sf" model="ir.ui.view">
<field name="name">delivery.record.form.inherit.sf</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
<field name="arch" type="xml">
<xpath expr="//page[last()-3]" position="before">
<!-- <page string="下发记录" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>-->
<page string="下发记录">
<group string="机床信息">
<field name="machine_tool_name"/>
<field name="machine_tool_type_id"/>
<field name="machine_tool_machine_ip"/>
</group>
<group string="运行信息">
<field name="machine_tool_timestamp"/>
<field name="machine_tool_status"/>
<field name="machine_tool_run_status"/>
<field name="machine_tool_time_on"/>
<field name="machine_tool_time_on_now"/>
<field name="machine_tool_tool_num"/>
<field name="machine_tool_program"/>
<field name="machine_tool_cut_status"/>
<field name="machine_tool_compensation_value_x"/>
<field name="machine_tool_compensation_value_y"/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>

View File

@@ -26,5 +26,18 @@
</xpath>
</field>
</record>
<!-- <record id="app_view_quotation_tree" model="ir.ui.view">-->
<!-- <field name="name">app.sale.order.form</field>-->
<!-- <field name="model">mrp.workorder</field>-->
<!-- <field name="inherit_id" ref="sf_manufacturing.view_mrp_production_workorder_tray_form_inherit_sf"/>-->
<!-- <field name="arch" type="xml">-->
<!-- <xpath expr="//page//field[@name='cnc_ids']//tree" position="attributes">-->
<!-- <attribute name="bg_colors">-->
<!--&lt;!&ndash; Gold:state in ('sale');LightGreen:state in ('done')&ndash;&gt;-->
<!-- LightGreen:button_state is ('False')-->
<!-- </attribute>-->
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
</odoo>

View File

@@ -0,0 +1 @@
from . import action_up

View File

@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
import base64
import logging
import os
import json
import hashlib
import time
import requests
from datetime import datetime
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.addons.sf_machine_connect.models import py2opcua, ftp_operate
_logger = logging.getLogger(__name__)
class UpSelectWizard(models.TransientModel):
_name = 'up.select.wizard'
workorder_id = fields.Many2one('mrp.workorder', string='工单', readonly=True)
workcenter_id = fields.Many2one('mrp.workcenter', string='工作中心', related='workorder_id.workcenter_id', readonly=True)
program_ids = fields.Many2many('sf.cnc.processing', string='程序列表')
def confirm_up(self):
pass
# cnc_id1 = fields.Many2one('ir.attachment', compute='_compute_cnc_id')
# sequence_number1 = fields.Char('序号', compute='_compute_cnc_id', default='0')
# program_name1 = fields.Char('程序名', compute='_compute_cnc_id')
# cutting_tool_name1 = fields.Char('刀具名称', compute='_compute_cnc_id')
# cutting_tool_no1 = fields.Char('刀号', compute='_compute_cnc_id')
# processing_type1 = fields.Char('加工类型', compute='_compute_cnc_id')
# margin_x_y1 = fields.Char('余量_X/Y', compute='_compute_cnc_id')
# margin_z1 = fields.Char('余量_Z', compute='_compute_cnc_id')
# depth_of_processing_z1 = fields.Char('加工深度(Z)', compute='_compute_cnc_id')
# cutting_tool_extension_length1 = fields.Char('刀具伸出长度', compute='_compute_cnc_id')
# cutting_tool_handle_type1 = fields.Char('刀柄型号', compute='_compute_cnc_id')
# estimated_processing_time1 = fields.Char('预计加工时间', compute='_compute_cnc_id')
# remark1 = fields.Text('备注', compute='_compute_cnc_id')
# cnc_id = fields.Many2one('sf.cnc.processing', '工单')
# num = fields.Integer('索引', default=0)
# cnc_id1 = fields.Many2one('ir.attachment')
# sequence_number1 = fields.Char('序号', compute='_compute_cnc_id', default='1')
# program_name1 = fields.Char('程序名')
# cutting_tool_name1 = fields.Char('刀具名称')
# cutting_tool_no1 = fields.Char('刀号')
# processing_type1 = fields.Char('加工类型')
# margin_x_y1 = fields.Char('余量_X/Y')
# margin_z1 = fields.Char('余量_Z')
# depth_of_processing_z1 = fields.Char('加工深度(Z)')
# cutting_tool_extension_length1 = fields.Char('刀具伸出长度')
# cutting_tool_handle_type1 = fields.Char('刀柄型号')
# estimated_processing_time1 = fields.Char('预计加工时间')
# remark1 = fields.Text('备注')
# cnc_id = fields.Many2one('sf.cnc.processing', '工单')
# num = fields.Integer('索引', default=0)
# print(11111111111111111111111111111111111111111111111)
# # @api.depends('program_ids')
# def _compute_cnc_id(self):
# print(222222222222222222222222222222222222222222)
# workorder_id = self.env.context.get('default_workorder_id')
# workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id)])
# # self.workcenter_id = workorder.workcent_id
# print(workorder_id)
#
# lines = []
# print(lines)
# for item in workorder.cnc_ids:
# # lines.append((4,item.id,0))
# lines.append((4, item.id, 0))
# print(lines)
#
# # print(self.cnc_id1, self.sequence_number1, self.program_name1, self.processing_type1,
# # self.cutting_tool_handle_type1
# # , self.cutting_tool_extension_length1, self.margin_z1, self.margin_z1, self.depth_of_processing_z1,
# # self.cutting_tool_no1, self.cutting_tool_name1, self.estimated_processing_time1, self.remark1)
# # else:
# # self.write({
# #
# # # 'cnc_id1': item.cnc_id or '',
# # # 'sequence_number1': item.sequence_number or '',
# # # 'program_name1': item.program_name or '',
# # # 'cutting_tool_name1': item.cutting_tool_name or '',
# # # 'cutting_tool_no1': item.cutting_tool_no or '',
# # # 'processing_type1': item.processing_type or '',
# # # 'margin_x_y1': item.margin_x_y or '',
# # # 'margin_z1': item.margin_z or '',
# # # 'depth_of_processing_z1': item.depth_of_processing_z or '',
# # # 'cutting_tool_extension_length1': item.cutting_tool_extension_length or '',
# # # 'cutting_tool_handle_type1': item.cutting_tool_handle_type or '',
# # # 'estimated_processing_time1': item.estimated_processing_time or '',
# # # 'remark1': item.remark or '',
# # 'id': item.sequence_number,
# # 'cnc_id1': item.cnc_id,
# # 'sequence_number1': item.sequence_number,
# # 'program_name1': item.program_name,
# # 'cutting_tool_name1': item.cutting_tool_name,
# # 'cutting_tool_no1': item.cutting_tool_no,
# # 'processing_type1': item.processing_type,
# # 'margin_x_y1': item.margin_x_y,
# # 'margin_z1': item.margin_z,
# # 'depth_of_processing_z1': item.depth_of_processing_z,
# # 'cutting_tool_extension_length1': item.cutting_tool_extension_length,
# # 'cutting_tool_handle_type1': item.cutting_tool_handle_type,
# # 'estimated_processing_time1': item.estimated_processing_time,
# # 'remark1': item.remark,
# # })
# # print(self.cnc_id1, self.sequence_number1, self.program_name1, self.processing_type1,
# # self.cutting_tool_handle_type1
# # , self.cutting_tool_extension_length1, self.margin_z1, self.margin_z1,
# # self.depth_of_processing_z1,
# # self.cutting_tool_no1, self.cutting_tool_name1, self.estimated_processing_time1, self.remark1)
#
# self.update({'program_ids': lines})

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="action_up_select_form" model="ir.ui.view">
<field name="name">CNC工单</field>
<field name="model">up.select.wizard</field>
<field name="arch" type="xml">
<form>
<group>
<field name="workcenter_id"/>
<field name="workorder_id"/>
</group>
<group>
<field name="program_ids" widget='many2many_tags' domain="[('workorder_id', '=', workorder_id)]"/>
<!-- <field name="program_ids" domain="[('workorder_id', '=', workorder_id)]"/>-->
</group>
<footer>
<button string="合并下发" name="confirm_up" type="object" class="btn-primary" confirm="是否确认合并下发"/>
<button string="取消" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_up_select" model="ir.actions.act_window">
<field name="name">选择要下发的NC程序</field>
<field name="type">ir.actions.act_window</field>
<!-- <field name="res_model">up.select.wizard</field>-->
<field name="res_model">up.select.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="action_up_select_form"/>
<field name="target">new</field>
</record>
</odoo>

View File

@@ -431,6 +431,7 @@ class ResMrpWorkOrder(models.Model):
class CNCprocessing(models.Model):
_name = 'sf.cnc.processing'
_description = "CNC加工"
_rec_name = 'program_name'
cnc_id = fields.Many2one('ir.attachment')
sequence_number = fields.Char('序号')
@@ -446,6 +447,8 @@ class CNCprocessing(models.Model):
estimated_processing_time = fields.Char('预计加工时间')
remark = fields.Text('备注')
workorder_id = fields.Many2one('mrp.workorder', string="工单")
button_state = fields.Boolean(string='是否已经下发')
# mrs下发编程单创建CNC加工
def cnc_processing_create(self, cnc_workorder, ret):

View File

@@ -336,11 +336,11 @@
<xpath expr="//page[1]" position="before">
<page string="CNC程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
<field name="cnc_ids" widget="one2many" string="工作程序">
<tree>
<tree decoration-success="button_state" decoration-bf="button_state">
<field name="sequence_number"/>
<field name="program_name"/>
<field name="cnc_id" string="文件"/>
<field name="cutting_tool_name"/>
<field name="cutting_tool_name"/>
<field name="cutting_tool_no"/>
<field name="processing_type"/>
<field name="margin_x_y"/>
@@ -350,6 +350,7 @@
<field name="cutting_tool_handle_type"/>
<field name="estimated_processing_time"/>
<field name="remark"/>
<field name="button_state" invisible="1"/>
</tree>
</field>
<group>