cnc程序上传
This commit is contained in:
@@ -252,6 +252,7 @@ class CNCprocessing(models.Model):
|
||||
_name = 'cnc.processing'
|
||||
_description = "CNC加工"
|
||||
|
||||
cnc_id = fields.Many2one('ir.attachment')
|
||||
FNo = fields.Char(string="序号")
|
||||
FPGName = fields.Char(string="程序名")
|
||||
FKnifeName = fields.Char(string="刀具名称")
|
||||
|
||||
@@ -296,7 +296,6 @@
|
||||
<search string="托盘">
|
||||
<field name="name" string="名称" filter_domain="[('name','ilike',self)]"/>
|
||||
<field name="code" string="编码" filter_domain="[('code','ilike',self)]"/>
|
||||
<!-- <field name="state" string="状态" filter_domain="[('state','ilike',self)]"/>-->
|
||||
<group string="分组">
|
||||
<filter name="state" string="状态" domain="[]" context="{'group_by': 'state'}"/>
|
||||
</group>
|
||||
|
||||
@@ -4,13 +4,10 @@ import base64
|
||||
import logging
|
||||
import math
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -84,7 +81,6 @@ class MrpWorkOrder(models.Model):
|
||||
_inherit = 'mrp.workorder'
|
||||
_description = '工单'
|
||||
|
||||
|
||||
tray_ids = fields.One2many('sf.tray', 'workorder_id', string='托盘')
|
||||
# def get_tray_info(self):
|
||||
# @api.onchange('X_axis', 'Y_axis', 'Z_axis')
|
||||
@@ -129,7 +125,8 @@ class MrpWorkOrder(models.Model):
|
||||
# 扫码绑定托盘方法
|
||||
def gettray(self):
|
||||
return ""
|
||||
#解除托盘绑定
|
||||
|
||||
# 解除托盘绑定
|
||||
def unbindtray(self):
|
||||
return ""
|
||||
|
||||
@@ -176,37 +173,70 @@ class MrpWorkOrder(models.Model):
|
||||
|
||||
cnc_ids = fields.One2many("cnc.processing", 'workorder_id', string="CNC加工")
|
||||
|
||||
# @api.depends('tray_id')
|
||||
# def updateTrayState(self):
|
||||
#
|
||||
# for item in self:
|
||||
# if item.tray_code == False:
|
||||
# continue
|
||||
# trayInfo = self.env['sf.tray'].sudo.search([('code', '=', item.tray_code)])
|
||||
# if trayInfo:
|
||||
# trayInfo.update(
|
||||
# {
|
||||
# 'production_id': item.production_id,
|
||||
# 'state': "占用",
|
||||
# }
|
||||
# )
|
||||
tray_code = fields.Char( string="托盘",compute='updateTrayState')
|
||||
|
||||
|
||||
@api.depends('tray_code')
|
||||
def updateTrayState(self):
|
||||
tray = self.env['sf.tray'].search([("code",'=',self.tray_code)])
|
||||
if tray:
|
||||
tray.workorder_id = self
|
||||
else:
|
||||
return ""
|
||||
|
||||
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)
|
||||
return ""
|
||||
|
||||
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 ""
|
||||
|
||||
cnc_id = fields.Many2many('ir.attachment', 'cnc_attachment', string="cnc程序获取")
|
||||
|
||||
|
||||
def fetchCNC(self):
|
||||
return ""
|
||||
|
||||
|
||||
'''
|
||||
制造订单绑定托盘信息
|
||||
'''
|
||||
@@ -215,12 +245,83 @@ class MrpWorkOrder(models.Model):
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
_description = "制造订单"
|
||||
|
||||
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):
|
||||
_inherit = 'ir.attachment'
|
||||
|
||||
cnc_model = fields.Binary('cnc文件', attachment=False)
|
||||
model_name = fields.Char('模型名称')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<!-- 打印尺寸-->
|
||||
<record id="sf_tray1" model="report.paperformat">
|
||||
<field name="name">Dymo Label Sheet</field>
|
||||
<field name="default" eval="True"/>
|
||||
@@ -16,6 +16,7 @@
|
||||
<field name="dpi">96</field>
|
||||
</record>
|
||||
|
||||
<!-- 打印动作-->
|
||||
<record id="label_sf_tray_code" model="ir.actions.report">
|
||||
<field name="name">打印条形码</field>
|
||||
<field name="model">sf.tray</field>
|
||||
@@ -27,7 +28,7 @@
|
||||
<field name="paperformat_id" ref="sf_route_workcenter.sf_tray1"/>
|
||||
|
||||
</record>
|
||||
|
||||
<!-- 打印模板-->
|
||||
<template id="sf_tray_template">
|
||||
<t t-call="web.html_container">
|
||||
<t t-call="web.external_layout">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="sf_tray_form_inherit" model="ir.ui.view">
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<field name="routing_type" invisible="1"/>
|
||||
<field name="processing_panel" readonly = "1" />
|
||||
<field name="tray_code"/>
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<button type="object" class="oe_highlight" name="gettray" string="扫描托盘"
|
||||
attrs='{"invisible": [("production_id","=",False)]}'
|
||||
@@ -153,11 +154,12 @@
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//page[last()]" position="after">
|
||||
<page string="CNC加工" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<group>
|
||||
<page string="CNC程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
|
||||
|
||||
<field name="cnc_ids" widget="one2many">
|
||||
<tree>
|
||||
<field name="cnc_id" />
|
||||
<field name="FNo" />
|
||||
<field name="FPGName" />
|
||||
<field name="FKnifeName" />
|
||||
@@ -175,7 +177,7 @@
|
||||
</field>
|
||||
|
||||
|
||||
</group>
|
||||
|
||||
</page>
|
||||
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user