cnc程序上传

This commit is contained in:
gqh
2022-11-11 10:31:37 +08:00
parent 8bc7cd0391
commit e23548a0d3
6 changed files with 138 additions and 33 deletions

View File

@@ -252,6 +252,7 @@ class CNCprocessing(models.Model):
_name = 'cnc.processing' _name = 'cnc.processing'
_description = "CNC加工" _description = "CNC加工"
cnc_id = fields.Many2one('ir.attachment')
FNo = fields.Char(string="序号") FNo = fields.Char(string="序号")
FPGName = fields.Char(string="程序名") FPGName = fields.Char(string="程序名")
FKnifeName = fields.Char(string="刀具名称") FKnifeName = fields.Char(string="刀具名称")

View File

@@ -296,7 +296,6 @@
<search string="托盘"> <search string="托盘">
<field name="name" string="名称" filter_domain="[('name','ilike',self)]"/> <field name="name" string="名称" filter_domain="[('name','ilike',self)]"/>
<field name="code" string="编码" filter_domain="[('code','ilike',self)]"/> <field name="code" string="编码" filter_domain="[('code','ilike',self)]"/>
<!-- <field name="state" string="状态" filter_domain="[('state','ilike',self)]"/>-->
<group string="分组"> <group string="分组">
<filter name="state" string="状态" domain="[]" context="{'group_by': 'state'}"/> <filter name="state" string="状态" domain="[]" context="{'group_by': 'state'}"/>
</group> </group>

View File

@@ -4,13 +4,10 @@ import base64
import logging import logging
import math import math
from io import BytesIO from io import BytesIO
from odoo import api, fields, models, SUPERUSER_ID from odoo import api, fields, models, SUPERUSER_ID
from pystrich.code128 import Code128Encoder from pystrich.code128 import Code128Encoder
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@@ -84,7 +81,6 @@ class MrpWorkOrder(models.Model):
_inherit = 'mrp.workorder' _inherit = 'mrp.workorder'
_description = '工单' _description = '工单'
tray_ids = fields.One2many('sf.tray', 'workorder_id', string='托盘') tray_ids = fields.One2many('sf.tray', 'workorder_id', string='托盘')
# def get_tray_info(self): # def get_tray_info(self):
# @api.onchange('X_axis', 'Y_axis', 'Z_axis') # @api.onchange('X_axis', 'Y_axis', 'Z_axis')
@@ -129,6 +125,7 @@ class MrpWorkOrder(models.Model):
# 扫码绑定托盘方法 # 扫码绑定托盘方法
def gettray(self): def gettray(self):
return "" return ""
# 解除托盘绑定 # 解除托盘绑定
def unbindtray(self): def unbindtray(self):
return "" return ""
@@ -176,37 +173,70 @@ class MrpWorkOrder(models.Model):
cnc_ids = fields.One2many("cnc.processing", 'workorder_id', string="CNC加工") cnc_ids = fields.One2many("cnc.processing", 'workorder_id', string="CNC加工")
# @api.depends('tray_id') tray_code = fields.Char( string="托盘",compute='updateTrayState')
# def updateTrayState(self):
#
# for item in self: @api.depends('tray_code')
# if item.tray_code == False: def updateTrayState(self):
# continue tray = self.env['sf.tray'].search([("code",'=',self.tray_code)])
# trayInfo = self.env['sf.tray'].sudo.search([('code', '=', item.tray_code)]) if tray:
# if trayInfo: tray.workorder_id = self
# trayInfo.update( else:
# { return ""
# 'production_id': item.production_id,
# 'state': "占用",
# }
# )
def recreateManufacturing(self): def recreateManufacturing(self):
"""
重新生成制造订单
"""
values = self.env['mrp.production'].create_production1_values(self.production_id)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(self.production_id.company_id).create(
values)
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions._create_workorder()
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[
0].raw_material_production_id or False
orderpoint = production.orderpoint_id
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
production.message_post(
body=_('This production order has been created from Replenishment Report.'),
message_type='comment',
subtype_xmlid='mail.mt_note')
elif orderpoint:
production.message_post_with_view(
'mail.message_origin_link',
values={'self': production, 'origin': orderpoint},
subtype_id=self.env.ref('mail.mt_note').id)
elif origin_production:
production.message_post_with_view(
'mail.message_origin_link',
values={'self': production, 'origin': origin_production},
subtype_id=self.env.ref('mail.mt_note').id)
# productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(self.company_id).create(self.production_id)
# print(productions) # print(productions)
return "" return ""
def recreateWorkerOrder(self): def recreateWorkerOrder(self):
self.env['stock.move'].sudo().create(self.production_id._get_moves_raw_values()) """
self.env['stock.move'].sudo().create(self.production_id._get_moves_finished_values()) 返工重新生成工单
self.production_id._create_workorder() """
productions = self.production_id
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions.create_workorder1(self.processing_panel)
return "" return ""
cnc_id = fields.Many2many('ir.attachment', 'cnc_attachment', string="cnc程序获取")
def fetchCNC(self): def fetchCNC(self):
return "" return ""
''' '''
制造订单绑定托盘信息 制造订单绑定托盘信息
''' '''
@@ -215,12 +245,83 @@ class MrpWorkOrder(models.Model):
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = 'mrp.production'
_description = "制造订单" _description = "制造订单"
tray_ids = fields.One2many('sf.tray', 'production_id', string="托盘") tray_ids = fields.One2many('sf.tray', 'production_id', string="托盘")
def create_production1_values(self, production):
production_values_str = {'origin': production.origin,
'product_id': production.product_id.id,
'product_description_variants': production.product_description_variants,
'product_qty': production.product_qty,
'product_uom_id': production.product_uom_id.id,
'location_src_id': production.location_src_id.id,
'location_dest_id': production.location_dest_id.id,
'bom_id': production.bom_id.id,
'date_deadline': production.date_deadline,
'date_planned_start': production.date_planned_start,
'date_planned_finished': production.date_planned_finished,
'procurement_group_id': False,
'propagate_cancel': production.propagate_cancel,
'orderpoint_id': production.orderpoint_id.id,
'picking_type_id': production.picking_type_id.id,
'company_id': production.company_id.id,
'move_dest_ids': production.move_dest_ids.ids,
'user_id': production.user_id.id}
return production_values_str
def create_workorder1(self, k):
for production in self:
if not production.bom_id or not production.product_id:
continue
workorders_values = []
product_qty = production.product_uom_id._compute_quantity(production.product_qty,
production.bom_id.product_uom_id)
exploded_boms, dummy = production.bom_id.explode(production.product_id,
product_qty / production.bom_id.product_qty,
picking_type=production.bom_id.picking_type_id)
for bom, bom_data in exploded_boms:
# If the operations of the parent BoM and phantom BoM are the same, don't recreate work orders.
if not (bom.operation_ids and (not bom_data['parent_line'] or bom_data[
'parent_line'].bom_id.operation_ids != bom.operation_ids)):
continue
for operation in bom.operation_ids:
if operation._skip_operation_line(bom_data['product']):
continue
workorders_values += [{
'name': operation.name,
'production_id': production.id,
'workcenter_id': operation.workcenter_id.id,
'product_uom_id': production.product_uom_id.id,
'operation_id': operation.id,
'state': 'pending',
}]
# 根据加工面板的面数及对应的工序模板生成工单
i = 0
production.product_id.model_processing_panel = k
processing_panel_len = len(k)
for k in (production.product_id.model_processing_panel.split(',')):
routingworkcenter = self.env['sf.model.type.routing.sort'].search(
[('model_type_id', '=', production.product_id.model_type_id.id)],
order='sequence asc'
)
i += 1
for route in routingworkcenter:
if route.is_repeat == True:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(k, production, route))
production.workorder_ids = workorders_values
for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected()
class Attachment(models.Model): class Attachment(models.Model):
_inherit = 'ir.attachment' _inherit = 'ir.attachment'
cnc_model = fields.Binary('cnc文件', attachment=False) cnc_model = fields.Binary('cnc文件', attachment=False)
model_name = fields.Char('模型名称') model_name = fields.Char('模型名称')

View File

@@ -1,6 +1,6 @@
<odoo> <odoo>
<data> <data>
<!-- 打印尺寸-->
<record id="sf_tray1" model="report.paperformat"> <record id="sf_tray1" model="report.paperformat">
<field name="name">Dymo Label Sheet</field> <field name="name">Dymo Label Sheet</field>
<field name="default" eval="True"/> <field name="default" eval="True"/>
@@ -16,6 +16,7 @@
<field name="dpi">96</field> <field name="dpi">96</field>
</record> </record>
<!-- 打印动作-->
<record id="label_sf_tray_code" model="ir.actions.report"> <record id="label_sf_tray_code" model="ir.actions.report">
<field name="name">打印条形码</field> <field name="name">打印条形码</field>
<field name="model">sf.tray</field> <field name="model">sf.tray</field>
@@ -27,7 +28,7 @@
<field name="paperformat_id" ref="sf_route_workcenter.sf_tray1"/> <field name="paperformat_id" ref="sf_route_workcenter.sf_tray1"/>
</record> </record>
<!-- 打印模板-->
<template id="sf_tray_template"> <template id="sf_tray_template">
<t t-call="web.html_container"> <t t-call="web.html_container">
<t t-call="web.external_layout"> <t t-call="web.external_layout">

View File

@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<record id="sf_tray_form_inherit" model="ir.ui.view"> <record id="sf_tray_form_inherit" model="ir.ui.view">

View File

@@ -22,6 +22,7 @@
<field name="routing_type" invisible="1"/> <field name="routing_type" invisible="1"/>
<field name="processing_panel" readonly = "1" /> <field name="processing_panel" readonly = "1" />
<field name="tray_code"/>
<div class="col-12 col-lg-6 o_setting_box"> <div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="gettray" string="扫描托盘" <button type="object" class="oe_highlight" name="gettray" string="扫描托盘"
attrs='{"invisible": [("production_id","=",False)]}' attrs='{"invisible": [("production_id","=",False)]}'
@@ -153,11 +154,12 @@
</xpath> </xpath>
<xpath expr="//page[last()]" position="after"> <xpath expr="//page[last()]" position="after">
<page string="CNC加工" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'> <page string="CNC程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
<group>
<field name="cnc_ids" widget="one2many"> <field name="cnc_ids" widget="one2many">
<tree> <tree>
<field name="cnc_id" />
<field name="FNo" /> <field name="FNo" />
<field name="FPGName" /> <field name="FPGName" />
<field name="FKnifeName" /> <field name="FKnifeName" />
@@ -175,7 +177,7 @@
</field> </field>
</group>
</page> </page>
</xpath> </xpath>