优化制造订单的获取cnc程序

This commit is contained in:
jinling.yang
2024-05-09 18:29:30 +08:00
parent 6a4fd4d922
commit 3d56e54fb2
5 changed files with 56 additions and 42 deletions

View File

@@ -154,7 +154,7 @@ class MrpProduction(models.Model):
production.maintenance_count = len(production.request_ids) production.maintenance_count = len(production.request_ids)
# cnc程序获取 # cnc程序获取
def fetchCNC(self): def fetchCNC(self, production_names):
cnc = self.env['mrp.production'].search([('id', '=', self.id)]) cnc = self.env['mrp.production'].search([('id', '=', self.id)])
quick_order = self.env['quick.easy.order'].search( quick_order = self.env['quick.easy.order'].search(
[('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])]) [('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])])
@@ -166,8 +166,8 @@ class MrpProduction(models.Model):
if quick_order: if quick_order:
programme_way = 'manual operation' programme_way = 'manual operation'
try: try:
res = {'model_code': '' if not cnc.product_id.model_code else cnc.product_id.model_code, res = {'model_code': cnc.product_id.name,
'production_no': cnc.name, 'production_no': production_names,
'machine_tool_code': "", 'machine_tool_code': "",
'material_code': self.env['sf.production.materials'].search( 'material_code': self.env['sf.production.materials'].search(
[('id', '=', cnc.product_id.materials_id.id)]).materials_no, [('id', '=', cnc.product_id.materials_id.id)]).materials_no,
@@ -185,7 +185,10 @@ class MrpProduction(models.Model):
'model_file': '' if not cnc.product_id.model_file else base64.b64encode( 'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
cnc.product_id.model_file).decode('utf-8') cnc.product_id.model_file).decode('utf-8')
} }
logging.info('res:%s' % res) # 打印出除了 model_file 之外的所有键值对
for key, value in res.items():
if key != 'model_file':
logging.info('%s: %s' % (key, value))
configsettings = self.env['res.config.settings'].get_values() configsettings = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
url = '/api/intelligent_programming/create' url = '/api/intelligent_programming/create'
@@ -263,15 +266,15 @@ class MrpProduction(models.Model):
# 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心; # 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心;
def _create_workorder3(self): def _create_workorder3(self):
production_names = [production.name for production in self if production.product_id.categ_id.type == '成品']
programming_no = None programming_no = None
product_id_new = None product_first = None
production_ids = []
for production in self: for production in self:
if not production.bom_id or not production.product_id: if not production.bom_id or not production.product_id:
continue continue
workorders_values = [] workorders_values = []
if product_id_new is None: if product_first is None:
product_id_new = production.product_id product_first = production.product_id
product_qty = production.product_uom_id._compute_quantity(production.product_qty, product_qty = production.product_uom_id._compute_quantity(production.product_qty,
production.bom_id.product_uom_id) production.bom_id.product_uom_id)
@@ -296,16 +299,13 @@ class MrpProduction(models.Model):
'state': 'pending', 'state': 'pending',
}] }]
if production.product_id.categ_id.type == '成品': if production.product_id.categ_id.type == '成品':
if production_ids is None:
production_ids.append({production.name})
if programming_no is None: if programming_no is None:
production.fetchCNC() production.fetchCNC(production_names)
programming_no = production.programming_no programming_no = production.programming_no
else: else:
if production.product_id == product_id_new: if production.product_id == product_first:
if not production.programming_no: if not production.programming_no:
production.write({'programming_no': programming_no, 'programming_state': '编程中'}) production.write({'programming_no': programming_no, 'programming_state': '编程中'})
# 根据加工面板的面数及对应的工序模板生成工单 # 根据加工面板的面数及对应的工序模板生成工单
i = 0 i = 0
processing_panel_len = len(production.product_id.model_processing_panel.split(',')) processing_panel_len = len(production.product_id.model_processing_panel.split(','))

View File

@@ -975,6 +975,23 @@ class CNCprocessing(models.Model):
# cnc_workorder.time_ids.date_end = datetime.now() # cnc_workorder.time_ids.date_end = datetime.now()
# cnc_workorder.button_finish() # cnc_workorder.button_finish()
def _json_cnc_processing(self, obj):
cnc_processing_str = [0, 0, {
'sequence_number': obj['sequence_number'],
'program_name': obj['program_name'],
'cutting_tool_name': obj['cutting_tool_name'],
'cutting_tool_no': obj['cutting_tool_no'],
'processing_type': obj['processing_type'],
'margin_x_y': obj['margin_x_y'],
'margin_z': obj['margin_z'],
'depth_of_processing_z': obj['depth_of_processing_z'],
'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
'estimated_processing_time': obj['estimated_processing_time'],
'remark': obj['remark']
}]
return cnc_processing_str
# 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配 # 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配
def get_cnc_processing_file(self, serverdir, cnc_processing, program_path): def get_cnc_processing_file(self, serverdir, cnc_processing, program_path):
logging.info('serverdir:%s' % serverdir) logging.info('serverdir:%s' % serverdir)
@@ -1228,8 +1245,8 @@ class WorkPieceDelivery(models.Model):
same_route_id = item.route_id.id same_route_id = item.route_id.id
if item.route_id.id != same_route_id: if item.route_id.id != same_route_id:
is_not_route += 1 is_not_route += 1
else: # else:
raise UserError('请选择【任务路线】再进行配送') # raise UserError('请选择【任务路线】再进行配送')
if production_type != item.type: if production_type != item.type:
raise UserError('请选择类型为%s的制造订单进行配送' % production_type) raise UserError('请选择类型为%s的制造订单进行配送' % production_type)
if down_status != item.status: if down_status != item.status:
@@ -1309,21 +1326,22 @@ class WorkPieceDelivery(models.Model):
feeder_station_destination = None feeder_station_destination = None
route_id = None route_id = None
for item in self: for item in self:
delivery_Arr.append(item.name)
if item.type in ['上产线', '下产线']:
if route_id is None: if route_id is None:
route_id = item.route_id.id route_id = item.route_id.id
if feeder_station_start is None: if feeder_station_start is None:
feeder_station_start = item.feeder_station_start_id.name feeder_station_start = item.feeder_station_start_id.name
if feeder_station_destination is None: if feeder_station_destination is None:
feeder_station_destination = item.feeder_station_destination_id.name feeder_station_destination = item.feeder_station_destination_id.name
if item.type in ['上产线', '下产线']:
item.route_id = route_id item.route_id = route_id
delivery_Arr.append(item.name)
else: else:
self = self.create( self = self.create(
{'name': self.env['ir.sequence'].next_by_code('sf.workpiece.delivery'), {'name': self.env['ir.sequence'].next_by_code('sf.workpiece.delivery'),
'route_id': self.route_id.id, 'route_id': self.route_id.id,
'feeder_station_start_id': self.feeder_station_start_id.id, 'feeder_station_start_id': self.feeder_station_start_id.id,
'feeder_station_destination_id': self.feeder_station_destination_id.id}) 'feeder_station_destination_id': self.feeder_station_destination_id.id})
delivery_Arr.append(self.name)
delivery_str = ','.join(map(str, delivery_Arr)) delivery_str = ','.join(map(str, delivery_Arr))
if feeder_station_start is not None: if feeder_station_start is not None:
positionCode_Arr.append({ positionCode_Arr.append({

View File

@@ -30,7 +30,7 @@ access_mrp_workcenter_group_sf_mrp_user,mrp_workcenter,model_mrp_workcenter,sf_b
access_mrp_workcenter_manager,mrp_workcenter,model_mrp_workcenter,sf_base.group_sf_mrp_manager,1,1,1,0 access_mrp_workcenter_manager,mrp_workcenter,model_mrp_workcenter,sf_base.group_sf_mrp_manager,1,1,1,0
access_mrp_workcenter_productivity_group_sf_mrp_user,mrp_workcenter_productivity,model_mrp_workcenter_productivity,sf_base.group_sf_mrp_user,1,0,0,0 access_mrp_workcenter_productivity_group_sf_mrp_user,mrp_workcenter_productivity,model_mrp_workcenter_productivity,sf_base.group_sf_mrp_user,1,0,0,0
access_mrp_workcenter_productivity_manager,mrp_workcenter_productivity,model_mrp_workcenter_productivity,sf_base.group_sf_mrp_manager,1,1,1,0 access_mrp_workcenter_productivity_manager,mrp_workcenter_productivity,model_mrp_workcenter_productivity,sf_base.group_sf_mrp_manager,1,1,1,0
access_sf_workpiece_delivery_group_sf_order_user,sf_workpiece_delivery_group_sf_order_user,model_sf_workpiece_delivery,sf_base.group_sf_order_user,1,1,0,0 access_sf_workpiece_delivery_group_sf_order_user,sf_workpiece_delivery_group_sf_order_user,model_sf_workpiece_delivery,sf_base.group_sf_order_user,1,1,1,0
access_sf_workpiece_delivery_group_sf_equipment_user,sf_workpiece_delivery_group_sf_equipment_user,model_sf_workpiece_delivery,sf_base.group_sf_equipment_user,1,1,0,0 access_sf_workpiece_delivery_group_sf_equipment_user,sf_workpiece_delivery_group_sf_equipment_user,model_sf_workpiece_delivery,sf_base.group_sf_equipment_user,1,1,0,0
access_sf_workpiece_delivery_manager,sf_workpiece_delivery,model_sf_workpiece_delivery,sf_base.group_sf_mrp_manager,1,1,0,0 access_sf_workpiece_delivery_manager,sf_workpiece_delivery,model_sf_workpiece_delivery,sf_base.group_sf_mrp_manager,1,1,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
30 access_mrp_workcenter_manager mrp_workcenter model_mrp_workcenter sf_base.group_sf_mrp_manager 1 1 1 0
31 access_mrp_workcenter_productivity_group_sf_mrp_user mrp_workcenter_productivity model_mrp_workcenter_productivity sf_base.group_sf_mrp_user 1 0 0 0
32 access_mrp_workcenter_productivity_manager mrp_workcenter_productivity model_mrp_workcenter_productivity sf_base.group_sf_mrp_manager 1 1 1 0
33 access_sf_workpiece_delivery_group_sf_order_user sf_workpiece_delivery_group_sf_order_user model_sf_workpiece_delivery sf_base.group_sf_order_user 1 1 0 1 0
34 access_sf_workpiece_delivery_group_sf_equipment_user sf_workpiece_delivery_group_sf_equipment_user model_sf_workpiece_delivery sf_base.group_sf_equipment_user 1 1 0 0
35 access_sf_workpiece_delivery_manager sf_workpiece_delivery model_sf_workpiece_delivery sf_base.group_sf_mrp_manager 1 1 0 0
36 access_sf_workpiece_delivery_admin sf_workpiece_delivery_admin model_sf_workpiece_delivery base.group_system 1 1 1 0

View File

@@ -144,8 +144,7 @@
<!-- groups="sf_base.group_sf_mrp_user" --> <!-- groups="sf_base.group_sf_mrp_user" -->
<!-- attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '!=', 'blocked'),('state','=','done')]}"/> --> <!-- attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '!=', 'blocked'),('state','=','done')]}"/> -->
<button name="button_workpiece_delivery" type="object" string="工件配送" class="btn-primary" <button name="button_workpiece_delivery" type="object" string="工件配送" class="btn-primary"
attrs="{'invisible': ['|',('routing_type','!=','装夹预调'),('is_delivery','=',True)]}"/> attrs="{'invisible': ['|','|',('routing_type','!=','装夹预调'),('is_delivery','=',True),('state','!=','done')]}"/>
</xpath> </xpath>
<xpath expr="//page[1]" position="before"> <xpath expr="//page[1]" position="before">
<page string="开料要求" attrs='{"invisible": [("routing_type","!=","切割")]}'> <page string="开料要求" attrs='{"invisible": [("routing_type","!=","切割")]}'>
@@ -266,13 +265,13 @@
<page string="工件装夹" attrs='{"invisible": [("routing_type","!=","装夹预调")]}'> <page string="工件装夹" attrs='{"invisible": [("routing_type","!=","装夹预调")]}'>
<group> <group>
<field name="_barcode_scanned" widget="barcode_handler"/> <field name="_barcode_scanned" widget="barcode_handler"/>
<group string="卡盘"> <!-- <group string="卡盘">-->
<field name="chuck_serial_number"/> <!-- <field name="chuck_serial_number"/>-->
<field name="chuck_name"/> <!-- <field name="chuck_name"/>-->
<field name="chuck_brand_id"/> <!-- <field name="chuck_brand_id"/>-->
<field name="chuck_type_id"/> <!-- <field name="chuck_type_id"/>-->
<field name="chuck_model_id"/> <!-- <field name="chuck_model_id"/>-->
</group> <!-- </group>-->
<group string="托盘"> <group string="托盘">
<field name="tray_serial_number" readonly="1" string="序列号"/> <field name="tray_serial_number" readonly="1" string="序列号"/>
<field name="tray_product_id" readonly="1" string="名称"/> <field name="tray_product_id" readonly="1" string="名称"/>
@@ -446,7 +445,8 @@
<field name='X_deviation_angle' readonly="1"/> <field name='X_deviation_angle' readonly="1"/>
</group> </group>
</page> </page>
<page string="工件配送" attrs='{"invisible": [("routing_type","!=","装夹预调")]}'> <page string="工件配送"
attrs="{'invisible': ['|',('routing_type','!=','装夹预调'),('state','!=','done')]}">
<field name="workpiece_delivery_ids"> <field name="workpiece_delivery_ids">
<tree editable="bottom"> <tree editable="bottom">
<field name="production_id" invisible="1"/> <field name="production_id" invisible="1"/>
@@ -457,7 +457,7 @@
<field name="production_line_id"/> <field name="production_line_id"/>
<field name="task_delivery_time" readonly="1"/> <field name="task_delivery_time" readonly="1"/>
<field name="task_completion_time" readonly="1"/> <field name="task_completion_time" readonly="1"/>
<field name="status"/> <field name="status" readonly="1"/>
</tree> </tree>
</field> </field>
</page> </page>

View File

@@ -48,7 +48,7 @@ class Sf_Mrs_Connect(http.Controller):
# program_path_tmp = os.path.join('/tmp', ret['folder_name'], 'return', r) # program_path_tmp = os.path.join('/tmp', ret['folder_name'], 'return', r)
program_path_tmp = "C://Users//43484//Desktop//机企猫工作文档//其他//model_analysis" program_path_tmp = "C://Users//43484//Desktop//机企猫工作文档//其他//model_analysis"
files = os.listdir(program_path_tmp) files = os.listdir(program_path_tmp)
cnc_processing_arr = None cnc_processing_arr = []
for f in files: for f in files:
program_path = os.path.join(program_path_tmp, f) program_path = os.path.join(program_path_tmp, f)
logging.info('cnc程序路径 :%s' % program_path) logging.info('cnc程序路径 :%s' % program_path)
@@ -60,15 +60,11 @@ class Sf_Mrs_Connect(http.Controller):
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path, request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path,
program_path_tmp) program_path_tmp)
if cnc_processing: if cnc_processing:
if cnc_processing_arr is None: cnc_processing_arr.append(cnc_processing._json_cnc_processing(cnc_processing))
cnc_processing_arr = cnc_processing
else:
cnc_processing_arr |= cnc_processing
if cnc_program and cnc_processing_arr: if cnc_program and cnc_processing_arr:
cnc_program.write({'programming_state': '已编程', 'work_state': '已编程'})
cnc_program.workorder_ids.filtered(lambda b: b.routing_type == 'CNC加工').write( cnc_program.workorder_ids.filtered(lambda b: b.routing_type == 'CNC加工').write(
{'cnc_ids': cnc_processing_arr}) {'cnc_ids': cnc_processing_arr})
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
else: else:
res = {'status': 0, 'message': '该制造订单暂未开始'} res = {'status': 0, 'message': '该制造订单暂未开始'}