Compare commits
1 Commits
feature/取消
...
feature/cu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
186ac391ea |
@@ -4,7 +4,6 @@ import json
|
||||
import logging
|
||||
from odoo.addons.sf_mrs_connect.controllers.controllers import Sf_Mrs_Connect
|
||||
from odoo.addons.sf_manufacturing.controllers.controllers import Manufacturing_Connect
|
||||
from datetime import datetime
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -31,7 +30,6 @@ class WorkorderExceptionConroller(http.Controller):
|
||||
workorder = request.env['mrp.workorder'].sudo().search([
|
||||
('rfid_code', '=', ret['RfidCode']),
|
||||
('routing_type', '=', 'CNC加工'),
|
||||
('state', '!=', 'rework')
|
||||
])
|
||||
if not workorder:
|
||||
res = {'Succeed': False, 'ErrorCode': 401, 'Error': '无效的工单'}
|
||||
@@ -43,10 +41,7 @@ class WorkorderExceptionConroller(http.Controller):
|
||||
'exception_code': ret.get('coding'),
|
||||
'exception_content': ret.get('Error', '')
|
||||
})
|
||||
# 申请重新编程
|
||||
workorder.production_id.update_programming_state(trigger_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
reprogramming_reason=ret.get('Error', ''))
|
||||
workorder.production_id.write({'programming_state': '编程中', 'work_state': '编程中', 'is_rework': False})
|
||||
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
_logger.info('workder_exception error:%s' % e)
|
||||
|
||||
@@ -132,26 +132,6 @@ class Sf_Bf_Connect(http.Controller):
|
||||
request.cr.rollback()
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/api/bfm_cancel_order', type='http', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_bfm_cancel_order(self, **kw):
|
||||
"""
|
||||
业务平台取消销售订单
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
res = {'status': 1, 'message': '工厂取消销售订单成功'}
|
||||
logging.info('get_bfm_cancel_order:%s' % kw['order_number'])
|
||||
try:
|
||||
sale_order_info = request.env['sale.order'].sudo().search([('name', '=', kw['order_number'])])
|
||||
sale_order_info._action_cancel()
|
||||
return json.JSONEncoder().encode(res)
|
||||
except Exception as e:
|
||||
logging.error('get_bfm_cancel_order error: %s' % e)
|
||||
res['status'] = -1
|
||||
res['message'] = '工厂取消销售订单失败,请联系管理员'
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
|
||||
class jdElcp(http.Controller):
|
||||
|
||||
|
||||
@@ -596,9 +596,6 @@ class Manufacturing_Connect(http.Controller):
|
||||
if panel_workorder:
|
||||
panel_workorder.write({'production_line_state': '已下产线'})
|
||||
workorder.write({'state': 'to be detected'})
|
||||
workorder.check_ids.filtered(
|
||||
lambda ch: ch.quality_state == 'waiting').write(
|
||||
{'quality_state': 'none'})
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 204,
|
||||
'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']}
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import asyncio
|
||||
import base64
|
||||
import cProfile
|
||||
import concurrent
|
||||
import datetime
|
||||
import io
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import pstats
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
|
||||
import requests
|
||||
from itertools import groupby
|
||||
from collections import defaultdict, namedtuple
|
||||
|
||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||
from odoo import api, fields, models, SUPERUSER_ID, _, tools
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
from odoo.tools import float_compare, float_round, float_is_zero, format_datetime
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
_description = "制造订单"
|
||||
@@ -577,19 +584,16 @@ class MrpProduction(models.Model):
|
||||
|
||||
# 编程单更新
|
||||
# 增加触发时间参数
|
||||
def update_programming_state(self, trigger_time=None, reprogramming_reason=None):
|
||||
def update_programming_state(self, trigger_time=None):
|
||||
try:
|
||||
manufacturing_type = None
|
||||
manufacturing_type = 'rework'
|
||||
if self.is_scrap:
|
||||
manufacturing_type = 'scrap'
|
||||
elif self.tool_state == '2':
|
||||
manufacturing_type = 'invalid_tool_rework'
|
||||
elif self.is_rework:
|
||||
manufacturing_type = 'rework'
|
||||
res = {'programming_no': self.programming_no,
|
||||
'manufacturing_type': manufacturing_type,
|
||||
'trigger_time': trigger_time,
|
||||
'reprogramming_reason': reprogramming_reason}
|
||||
'trigger_time': trigger_time}
|
||||
logging.info('res=%s:' % res)
|
||||
configsettings = self.env['res.config.settings'].get_values()
|
||||
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
|
||||
@@ -762,64 +766,105 @@ class MrpProduction(models.Model):
|
||||
# if self.product_id.tracking == 'serial':
|
||||
# self._set_qty_producing()
|
||||
|
||||
|
||||
# 重载根据工序生成工单的程序:如果产品BOM中没有工序时,
|
||||
# 根据产品对应的模板类型中工序,去生成工单;
|
||||
# CNC加工工序的选取规则:
|
||||
# 如果自动报价有带过来预分配的机床,
|
||||
# 则根据设备找到工作中心;否则采用前面描述的工作中心分配机制;
|
||||
# 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心;
|
||||
def process_production(self):
|
||||
workorders_values = []
|
||||
# production = self.env['mrp.production'].browse(production_id)
|
||||
product_qty = self.product_uom_id._compute_quantity(self.product_qty,
|
||||
self.bom_id.product_uom_id)
|
||||
exploded_boms, dummy = self.bom_id.explode(self.product_id,
|
||||
product_qty / self.bom_id.product_qty,
|
||||
picking_type=self.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': self.id,
|
||||
'workcenter_id': operation.workcenter_id.id,
|
||||
'product_uom_id': self.product_uom_id.id,
|
||||
'operation_id': operation.id,
|
||||
'state': 'pending',
|
||||
}]
|
||||
if self.product_id.categ_id.type in ['成品', '坯料']:
|
||||
# # 根据工序设计生成工单
|
||||
technology_design_ids = sorted(self.technology_design_ids, key=lambda x: x.sequence)
|
||||
for route in technology_design_ids:
|
||||
workorder_has = self.env['mrp.workorder'].search(
|
||||
[('technology_design_id', '=', route.id), ('production_id', '=', self.id)])
|
||||
if not workorder_has:
|
||||
if route.route_id.routing_type not in ['表面工艺']:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(self, route))
|
||||
else:
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', route.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
self, route, product_production_process.seller_ids[0].partner_id.id))
|
||||
return workorders_values
|
||||
|
||||
def _set_workorder_duration_expected(self):
|
||||
try:
|
||||
# 在每个线程中创建独立的 ORM 环境
|
||||
with api.Environment.manage():
|
||||
new_cr = self.pool.cursor()
|
||||
self = self.with_env(self.env(cr=new_cr))
|
||||
# program_ids = self.sudo().env['loyalty.program'].browse(program_ids.ids)
|
||||
# 使用独立的环境来处理数据库事务
|
||||
# 在独立的环境中对 workorder 进行操作
|
||||
production = self.sudo().env['mrp.production'].browse(self.id)
|
||||
workorders_values = production.process_production()
|
||||
production.write({'workorder_ids': workorders_values})
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
# 可以进行其他与工作单相关的操作
|
||||
# workorder_env.write({'...'})
|
||||
return production
|
||||
except Exception as e:
|
||||
logging.error(f"Error processing workorder {workorder.id}: {e}")
|
||||
# workorders_values = self.process_production(self)
|
||||
# print('_set_workorder_duration_expected wqio ', self)
|
||||
# self.write({'workorder_ids': workorders_values})
|
||||
# for workorder in self.workorder_ids:
|
||||
# workorder.duration_expected = workorder._get_duration_expected()
|
||||
|
||||
def _create_workorder3(self, item):
|
||||
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)):
|
||||
with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
|
||||
futures = []
|
||||
for production in self:
|
||||
if not production.bom_id or not production.product_id:
|
||||
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',
|
||||
}]
|
||||
if production.product_id.categ_id.type in ['成品', '坯料']:
|
||||
# # 根据工序设计生成工单
|
||||
technology_design_ids = sorted(production.technology_design_ids, key=lambda x: x.sequence)
|
||||
for route in technology_design_ids:
|
||||
workorder_has = self.env['mrp.workorder'].search(
|
||||
[('technology_design_id', '=', route.id), ('production_id', '=', production.id)])
|
||||
if not workorder_has:
|
||||
if route.route_id.routing_type not in ['表面工艺']:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(production, route))
|
||||
else:
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', route.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route, product_production_process.seller_ids[0].partner_id.id))
|
||||
production.workorder_ids = workorders_values
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
# 提交每个生产任务到线程池
|
||||
futures.append(executor.submit(production._set_workorder_duration_expected))
|
||||
|
||||
# 等待所有线程完成任务
|
||||
results = []
|
||||
for future in futures:
|
||||
try:
|
||||
result = future.result()
|
||||
if result:
|
||||
results.append(result)
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Error processing production: {e}")
|
||||
return results
|
||||
|
||||
# 外协出入库单处理
|
||||
def get_subcontract_pick_purchase(self):
|
||||
production_all = self.sorted(lambda x: x.id)
|
||||
def get_subcontract_pick_purchase(self,productions):
|
||||
production_all = productions.sorted(lambda x: x.id)
|
||||
product_id_to_production_names = {}
|
||||
grouped_product_ids = {k: list(g) for k, g in
|
||||
groupby(production_all, key=lambda x: x.product_id.id)}
|
||||
@@ -828,9 +873,10 @@ class MrpProduction(models.Model):
|
||||
sorted_workorders = None
|
||||
for production in production_all:
|
||||
proc_workorders = []
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id),
|
||||
('is_subcontract', '=', True), ('state', '!=', 'cancel')], order='sequence asc')
|
||||
process_parameter_workorder=production.workorder_ids.filtered(lambda w: w.surface_technics_parameters_id and w.is_subcontract and w.state!='cancel')
|
||||
# process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
# [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id),
|
||||
# ('is_subcontract', '=', True), ('state', '!=', 'cancel')], order='sequence asc')
|
||||
if process_parameter_workorder:
|
||||
# 将这些特殊表面工艺工单的采购单与调拨单置为失效
|
||||
for workorder in process_parameter_workorder:
|
||||
@@ -945,48 +991,49 @@ class MrpProduction(models.Model):
|
||||
if purchase_order_line:
|
||||
line.unlink()
|
||||
|
||||
def _reset_work_order_sequence(self):
|
||||
def _process_reset_work_order_sequence(self,rec):
|
||||
workorder_ids = rec.workorder_ids
|
||||
technology_design_ids = rec.technology_design_ids
|
||||
if workorder_ids.filtered(lambda item: item.state in ('返工', 'rework')):
|
||||
# 获取返工后新生成的工单
|
||||
work_ids = workorder_ids.filtered(lambda item: item.sequence == 0)
|
||||
# 对工单进行逐个插入
|
||||
for work_id in work_ids:
|
||||
order_rework_ids = rec.workorder_ids.filtered(
|
||||
lambda item: (item.sequence > 0 and work_id.name == item.name
|
||||
and work_id.processing_panel == item.processing_panel))
|
||||
order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True)
|
||||
work_id.sequence = order_rework_ids[0].sequence + 1
|
||||
# 对该工单之后的工单工序进行加一
|
||||
work_order_ids = rec.workorder_ids.filtered(
|
||||
lambda item: item.sequence >= work_id.sequence and item.id != work_id.id)
|
||||
for work in work_order_ids:
|
||||
work.sequence = work.sequence + 1
|
||||
|
||||
else:
|
||||
# 将工艺设计生成的工单序号赋值给工单的序号
|
||||
for work in workorder_ids:
|
||||
td_ids = technology_design_ids.filtered(
|
||||
lambda item: (item.route_id.name in work.name and item.process_parameters_id
|
||||
and item.process_parameters_id == work.surface_technics_parameters_id) or
|
||||
(item.route_id.name == work.name and item.panel
|
||||
and item.panel == work.processing_panel))
|
||||
if work.name == '人工线下加工':
|
||||
td_ids = technology_design_ids.filtered(lambda item: (item.route_id.name in work.name))
|
||||
if td_ids:
|
||||
work.sequence = td_ids[0].sequence
|
||||
cancel_work_ids = workorder_ids.filtered(lambda item: item.state in ('已取消', 'cancel'))
|
||||
if cancel_work_ids:
|
||||
sequence = max(workorder_ids.filtered(lambda item: item.state not in ('已取消', 'cancel')),
|
||||
key=lambda w: w.sequence).sequence
|
||||
for cw in cancel_work_ids:
|
||||
cw.sequence = sequence + 1
|
||||
def _reset_work_order_sequence(self,productions):
|
||||
"""
|
||||
工单工序排序方法(新)
|
||||
"""
|
||||
for rec in self:
|
||||
workorder_ids = rec.workorder_ids
|
||||
technology_design_ids = rec.technology_design_ids
|
||||
if workorder_ids.filtered(lambda item: item.state in ('返工', 'rework')):
|
||||
# 获取返工后新生成的工单
|
||||
work_ids = workorder_ids.filtered(lambda item: item.sequence == 0)
|
||||
# 对工单进行逐个插入
|
||||
for work_id in work_ids:
|
||||
order_rework_ids = rec.workorder_ids.filtered(
|
||||
lambda item: (item.sequence > 0 and work_id.name == item.name
|
||||
and work_id.processing_panel == item.processing_panel))
|
||||
order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True)
|
||||
work_id.sequence = order_rework_ids[0].sequence + 1
|
||||
# 对该工单之后的工单工序进行加一
|
||||
work_order_ids = rec.workorder_ids.filtered(
|
||||
lambda item: item.sequence >= work_id.sequence and item.id != work_id.id)
|
||||
for work in work_order_ids:
|
||||
work.sequence = work.sequence + 1
|
||||
|
||||
else:
|
||||
# 将工艺设计生成的工单序号赋值给工单的序号
|
||||
for work in workorder_ids:
|
||||
td_ids = technology_design_ids.filtered(
|
||||
lambda item: (item.route_id.name in work.name and item.process_parameters_id
|
||||
and item.process_parameters_id == work.surface_technics_parameters_id) or
|
||||
(item.route_id.name == work.name and item.panel
|
||||
and item.panel == work.processing_panel))
|
||||
if work.name == '人工线下加工':
|
||||
td_ids = technology_design_ids.filtered(lambda item: (item.route_id.name in work.name))
|
||||
if td_ids:
|
||||
work.sequence = td_ids[0].sequence
|
||||
cancel_work_ids = workorder_ids.filtered(lambda item: item.state in ('已取消', 'cancel'))
|
||||
if cancel_work_ids:
|
||||
sequence = max(workorder_ids.filtered(lambda item: item.state not in ('已取消', 'cancel')),
|
||||
key=lambda w: w.sequence).sequence
|
||||
for cw in cancel_work_ids:
|
||||
cw.sequence = sequence + 1
|
||||
|
||||
for rec in productions:
|
||||
self._process_reset_work_order_sequence(rec)
|
||||
def _reset_work_order_sequence_1(self):
|
||||
"""
|
||||
工单工序排序方法(旧)
|
||||
@@ -1082,9 +1129,9 @@ class MrpProduction(models.Model):
|
||||
|
||||
# 创建工单并进行排序
|
||||
def _create_workorder(self, item):
|
||||
self._create_workorder3(item)
|
||||
self._reset_work_order_sequence()
|
||||
return True
|
||||
productions = self._create_workorder3(item)
|
||||
self._reset_work_order_sequence(productions)
|
||||
return productions
|
||||
|
||||
def production_process(self, pro_plan):
|
||||
type_map = {'装夹预调': False, 'CNC加工': False, '解除装夹': False}
|
||||
@@ -1305,7 +1352,6 @@ class MrpProduction(models.Model):
|
||||
# 对制造订单所以面的cnc工单的程序用刀进行校验
|
||||
try:
|
||||
logging.info(f'已更新制造订单:{productions_not_delivered}')
|
||||
productions = productions.filtered(lambda p: p.production_type == '自动化产线加工')
|
||||
productions.production_cnc_tool_checkout()
|
||||
except Exception as e:
|
||||
logging.info(f'对cnc工单的程序用刀进行校验报错:{e}')
|
||||
@@ -1678,13 +1724,13 @@ class MrpProduction(models.Model):
|
||||
url = '/api/intelligent_programming/reset_state_again'
|
||||
config_url = configsettings['sf_url'] + url
|
||||
ret = requests.post(config_url, json=res, data=None, headers=config_header)
|
||||
# ret = ret.json()
|
||||
# result = json.loads(ret['result'])
|
||||
# logging.info('update_programming_state-ret:%s' % result)
|
||||
# if result['status'] == 1:
|
||||
# self.write({'is_rework': True})
|
||||
# else:
|
||||
# raise UserError(ret['message'])
|
||||
ret = ret.json()
|
||||
result = json.loads(ret['result'])
|
||||
logging.info('update_programming_state-ret:%s' % result)
|
||||
if result['status'] == 1:
|
||||
self.write({'is_rework': True})
|
||||
else:
|
||||
raise UserError(ret['message'])
|
||||
except Exception as e:
|
||||
logging.info('update_programming_state error:%s' % e)
|
||||
raise UserError("更新编程单状态失败,请联系管理员")
|
||||
@@ -1760,3 +1806,5 @@ class sf_processing_panel(models.Model):
|
||||
|
||||
name = fields.Char('加工面')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
|
||||
@@ -455,32 +455,6 @@ class ResMrpWorkOrder(models.Model):
|
||||
("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因", tracking=True)
|
||||
detailed_reason = fields.Text('详细原因')
|
||||
is_rework = fields.Boolean(string='是否返工', default=False)
|
||||
# rework_flag = fields.Boolean(string='返工标志', compute='_compute_rework_flag')
|
||||
#
|
||||
# @api.depends('state', 'production_line_state')
|
||||
# def _compute_rework_flag(self):
|
||||
# for record in self:
|
||||
# if record.state == 'done' and record.routing_type == '装夹预调':
|
||||
# next_workorder = record.production_id.workorder_ids.filtered(
|
||||
# lambda w: w.sequence == record.sequence + 1)
|
||||
# if next_workorder and next_workorder.routing_type == 'CNC加工' and next_workorder.state in ['ready',
|
||||
# 'waiting',
|
||||
# 'pending'] and next_workorder.production_line_state == '待上产线':
|
||||
# record.rework_flag = False
|
||||
# elif next_workorder and next_workorder.routing_type == '表面工艺' and next_workorder.state in ['ready',
|
||||
# 'waiting',
|
||||
# 'pending']:
|
||||
# record.rework_flag = False
|
||||
# else:
|
||||
# record.rework_flag = True
|
||||
# else:
|
||||
# record.rework_flag = True
|
||||
#
|
||||
# def button_rework(self):
|
||||
# for item in self:
|
||||
# item.state = 'progress'
|
||||
# for time_id in item.time_ids:
|
||||
# time_id.write({'date_end': None})
|
||||
|
||||
def button_change_env(self):
|
||||
self.is_test_env = not self.is_test_env
|
||||
@@ -1569,8 +1543,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
# 修改工单状态
|
||||
self.write({'state': 'to be detected'})
|
||||
# 若关联的【质量检查_需送检】=true,则质量检查单的状态从“等待”更新为“待处理”
|
||||
self.check_ids.filtered(lambda ch: ch.is_inspect is True and ch.quality_state == 'waiting').write(
|
||||
{'quality_state': 'none'})
|
||||
self.check_ids.filtered(lambda ch: ch.is_inspect is True).write({'quality_state': 'none'})
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
import json
|
||||
from odoo import models, fields, api, _
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -24,8 +24,6 @@ class SaleOrder(models.Model):
|
||||
self.state = 'supply method'
|
||||
|
||||
def action_confirm(self):
|
||||
if self._get_forbidden_state_confirm() & set(self.mapped('state')):
|
||||
raise UserError(_('订单状态已发生变化,请刷新当前页面'))
|
||||
# 判断是否所有产品都选择了供货方式
|
||||
filter_line = self.order_line.filtered(lambda line: not line.supply_method)
|
||||
if filter_line:
|
||||
|
||||
@@ -180,14 +180,14 @@ class StockRule(models.Model):
|
||||
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||
productions_values)
|
||||
# 将这一批制造订单的采购组根据成品设置为不同的采购组
|
||||
# product_group_id = {}
|
||||
# for index, production in enumerate(productions):
|
||||
# if production.product_id.id not in product_group_id.keys():
|
||||
# product_group_id[production.product_id.id] = production.procurement_group_id.id
|
||||
# else:
|
||||
# productions_values[index].update({'name': production.name})
|
||||
# procurement_group_vals = production._prepare_procurement_group_vals(productions_values[index])
|
||||
# production.procurement_group_id = self.env["procurement.group"].create(procurement_group_vals).id
|
||||
product_group_id = {}
|
||||
for index, production in enumerate(productions):
|
||||
if production.product_id.id not in product_group_id.keys():
|
||||
product_group_id[production.product_id.id] = production.procurement_group_id.id
|
||||
else:
|
||||
productions_values[index].update({'name': production.name})
|
||||
procurement_group_vals = production._prepare_procurement_group_vals(productions_values[index])
|
||||
production.procurement_group_id = self.env["procurement.group"].create(procurement_group_vals).id
|
||||
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
@@ -197,7 +197,7 @@ class StockRule(models.Model):
|
||||
'''
|
||||
# productions._create_workorder()
|
||||
#
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
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
|
||||
@@ -289,7 +289,7 @@ class StockRule(models.Model):
|
||||
if production_item.product_id.id in product_id_to_production_names:
|
||||
# 同一个产品多个制造订单对应一个编程单和模型库
|
||||
# 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
|
||||
if not production_item.programming_no and production_item.production_type in ['自动化产线加工', '人工线下加工']:
|
||||
if not production_item.programming_no and production_item.production_type == '自动化产线加工':
|
||||
if not production_programming.programming_no:
|
||||
production_item.fetchCNC(
|
||||
', '.join(product_id_to_production_names[production_item.product_id.id]))
|
||||
|
||||
@@ -74,9 +74,7 @@
|
||||
<xpath expr="//field[@name='production_real_duration']" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='state']" position="after">
|
||||
<field name="programming_state" optional="hide"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -117,11 +115,11 @@
|
||||
<xpath expr="//sheet//group//group//div[3]" position="after">
|
||||
<field name="production_type" readonly="1"/>
|
||||
<field name="manual_quotation" readonly="1"
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工', '人工线下加工'])]}"/>
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工'])]}"/>
|
||||
<field name="programming_no" readonly="1"
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工', '人工线下加工'])]}"/>
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工'])]}"/>
|
||||
<field name="programming_state" readonly="1"
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工', '人工线下加工'])]}"
|
||||
attrs="{'invisible': [('production_type', 'not in', ['自动化产线加工'])]}"
|
||||
decoration-success="programming_state == '已编程'"
|
||||
decoration-warning="programming_state =='编程中'"
|
||||
decoration-danger="programming_state =='已编程未下发'"/>
|
||||
@@ -632,8 +630,6 @@
|
||||
<field name="state" icon="fa-filter" enable_counters="1"/>
|
||||
<field name="delivery_status" icon="fa-filter" enable_counters="1"/>
|
||||
<field name="production_type" icon="fa-filter" enable_counters="1"/>
|
||||
<field name="programming_state" icon="fa-filter" enable_counters="1"/>
|
||||
|
||||
</searchpanel>
|
||||
</xpath>
|
||||
<filter name='todo' position="replace"/>
|
||||
|
||||
@@ -163,7 +163,6 @@
|
||||
<field name='is_delivery' invisible="1"/>
|
||||
<field name="is_trayed" invisible="1"/>
|
||||
<field name="is_inspect" invisible="1"/>
|
||||
<!-- <field name="rework_flag" invisible="1"/>-->
|
||||
<!-- <field name='is_send_program_again' invisible="1"/>-->
|
||||
<!-- 工单form页面的开始停工按钮等 -->
|
||||
<!-- <button name="button_start" type="object" string="开始" class="btn-success" -->
|
||||
@@ -183,7 +182,7 @@
|
||||
<button name="button_pending" type="object" string="暂停" class="btn-warning"
|
||||
attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('is_user_working', '=', False)]}"/>
|
||||
<button name="button_finish" type="object" string="完成" class="btn-success" confirm="是否确认完工"
|
||||
attrs="{'invisible': ['|', '|', '|',('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('is_user_working', '=', False),'&','&',('state', 'in', ('progress')), ('is_inspect', '=', True), ('routing_type','!=','CNC加工')]}"/>
|
||||
attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('is_user_working', '=', False)]}"/>
|
||||
|
||||
<button name="%(mrp.act_mrp_block_workcenter_wo)d" type="action" string="阻塞"
|
||||
context="{'default_workcenter_id': workcenter_id}" class="btn-danger"
|
||||
@@ -212,9 +211,6 @@
|
||||
attrs="{'invisible': ['|', '|', '|', ('routing_type','!=','装夹预调'),('state','!=','progress'), ('is_trayed', '=', False), ('state', 'in', ('done'))]}"/>
|
||||
<button name="print_method" type="object" string="打印二维码" class="btn-primary"
|
||||
attrs="{'invisible': ['|',('routing_type','!=','解除装夹'),('state','!=','done')]}"/>
|
||||
<!-- <button type="object" class="oe_highlight jikimo_button_confirm" name="button_rework"-->
|
||||
<!-- string="返工"-->
|
||||
<!-- attrs='{"invisible": [("rework_flag","=",True)]}' confirm="是否返工"/>-->
|
||||
</xpath>
|
||||
<xpath expr="//page[1]" position="before">
|
||||
<page string="开料要求" attrs='{"invisible": [("routing_type","not in",("切割", "线切割", "人工线下加工"))]}'>
|
||||
@@ -493,7 +489,7 @@
|
||||
</group>
|
||||
</page>
|
||||
|
||||
<page string="2D加工图纸" attrs='{"invisible": [("routing_type","not in",["装夹预调", "人工线下加工"])]}'>
|
||||
<page string="2D加工图纸" attrs="{'invisible': [('routing_type','!=','装夹预调')]}">
|
||||
<field name="machining_drawings" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
|
||||
@@ -537,7 +533,7 @@
|
||||
<page string="后置三元检测" attrs='{"invisible": [("individuation_page_PTD", "=", False)]}'>
|
||||
<group>
|
||||
<field name="test_results"
|
||||
attrs='{"readonly":["&","|",("state","!=","to be detected"), "|",("routing_type","=","CNC加工"),("is_inspect", "=", True),("state","in",["done","rework"])],
|
||||
attrs='{"readonly":[("state","!=","to be detected"), "|",("routing_type","=","CNC加工"),("is_inspect", "=", True)],
|
||||
"invisible":[("results","!=",False)]}'/>
|
||||
<!-- <field name="is_remanufacture" attrs='{"invisible":[("test_results","!=","报废")]}'/>-->
|
||||
<!-- <field name="is_fetchcnc"-->
|
||||
@@ -565,7 +561,7 @@
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="//page[1]" position="before">
|
||||
<page string="CNC程序" attrs='{"invisible": [("routing_type","not in",["CNC加工", "人工线下加工"])]}'>
|
||||
<page string="CNC程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<field name="cnc_ids" widget="one2many" string="工作程序" default_order="sequence_number,id"
|
||||
readonly="0">
|
||||
<tree>
|
||||
@@ -589,7 +585,7 @@
|
||||
</field>
|
||||
|
||||
</page>
|
||||
<page string="CMM程序" attrs='{"invisible": [("routing_type","not in",["CNC加工", "人工线下加工"])]}'>
|
||||
<page string="CMM程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<field name="cmm_ids" widget="one2many" string="CMM程序" readonly="1">
|
||||
<tree>
|
||||
<field name="sequence_number"/>
|
||||
@@ -642,7 +638,7 @@
|
||||
<field name="inherit_id" ref="sf_manufacturing.view_mrp_production_workorder_tray_form_inherit_sf"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form//sheet//group//group[2]" position="replace">
|
||||
<group string="装夹图纸" attrs="{'invisible': [('routing_type', 'not in', ['装夹预调', '人工线下加工'])]}">
|
||||
<group string="装夹图纸" attrs="{'invisible': [('routing_type', '!=', '装夹预调')]}">
|
||||
<!-- 隐藏加工图纸字段名 -->
|
||||
<field name="processing_drawing" widget="pdf_viewer" string="" readonly="1"/>
|
||||
<!-- <field name="production_id" invisible="0"/>-->
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of YiZuo. See LICENSE file for full copyright and licensing details.
|
||||
import logging
|
||||
from itertools import groupby
|
||||
import cProfile
|
||||
import io
|
||||
import pstats
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from odoo import models, api, fields, _
|
||||
|
||||
|
||||
@@ -13,6 +15,71 @@ class ProductionTechnologyWizard(models.TransientModel):
|
||||
origin = fields.Char(string='源单据')
|
||||
is_technology_confirm = fields.Boolean(default=True)
|
||||
|
||||
def _process_production(self,productions,technology_designs):
|
||||
for production in productions:
|
||||
# self._process_production_special_design(production,technology_designs)
|
||||
with ThreadPoolExecutor(max_workers=4) as executor:
|
||||
executor.submit(self._process_production_special_design, production,technology_designs)
|
||||
def _process_production_special_design(self,production,technology_designs):
|
||||
if production != self.production_id:
|
||||
self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs,
|
||||
production)
|
||||
# 特殊表面工艺
|
||||
special_design = self.env['sf.technology.design'].sudo().search(
|
||||
[('routing_tag', '=', 'special'), ('production_id', '=', production.id),
|
||||
('is_auto', '=', False), ('active', 'in', [True, False])])
|
||||
for special in special_design:
|
||||
workorders_values = []
|
||||
if special.active is False:
|
||||
# is_cancel = False
|
||||
# 工单采购单外协出入库单皆需取消
|
||||
domain = [('production_id', '=', special.production_id.id)]
|
||||
if special.process_parameters_id:
|
||||
domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id),
|
||||
('state', '!=', 'cancel')]
|
||||
else:
|
||||
domain += [('technology_design_id', '=', special.id), ('state', '!=', 'cancel')]
|
||||
workorder = self.env['mrp.workorder'].search(domain)
|
||||
# previous_workorder = self.env['mrp.workorder'].search(
|
||||
# [('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'),
|
||||
# ('production_id', '=', workorder.production_id.id)])
|
||||
# if previous_workorder:
|
||||
# if previous_workorder.supplier_id != workorder.supplier_id:
|
||||
# is_cancel = True
|
||||
# if workorder.state != 'cancel' and is_cancel is True:
|
||||
workorder.write({'state': 'cancel'})
|
||||
workorder.picking_ids.write({'state': 'cancel'})
|
||||
workorder.picking_ids.move_ids.write({'state': 'cancel'})
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('origin', '=', workorder.production_id.name), ('purchase_type', '=', 'consignment')])
|
||||
for line in purchase_order.order_line:
|
||||
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id:
|
||||
purchase_order.write({'state': 'cancel'})
|
||||
else:
|
||||
if special.production_id.workorder_ids:
|
||||
workorder = self.env['mrp.workorder'].search(
|
||||
[('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id),
|
||||
('state', '!=', 'cancel')])
|
||||
if not workorder:
|
||||
if special.route_id.routing_type == '表面工艺':
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(special.production_id, special,
|
||||
product_production_process.seller_ids[
|
||||
0].partner_id.id))
|
||||
else:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(special.production_id, special))
|
||||
special.production_id.write({'workorder_ids': workorders_values})
|
||||
else:
|
||||
if len(workorder.blocked_by_workorder_ids) > 1:
|
||||
if workorder.sequence == 1:
|
||||
workorder.blocked_by_workorder_ids = None
|
||||
else:
|
||||
if workorder.blocked_by_workorder_ids:
|
||||
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
|
||||
def confirm(self):
|
||||
if self.is_technology_confirm is True and self.production_id.product_id.categ_id.type in ['成品', '坯料']:
|
||||
domain = [('origin', '=', self.origin), ('state', '=', 'technology_to_confirmed'),
|
||||
@@ -23,72 +90,24 @@ class ProductionTechnologyWizard(models.TransientModel):
|
||||
[('production_id', '=', self.production_id.id), ('active', 'in', [True, False])])
|
||||
# technology_designs = self.production_id.technology_design_ids
|
||||
productions = self.env['mrp.production'].search(domain)
|
||||
for production in productions:
|
||||
if production != self.production_id:
|
||||
self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs,
|
||||
production)
|
||||
# 特殊表面工艺
|
||||
special_design = self.env['sf.technology.design'].sudo().search(
|
||||
[('routing_tag', '=', 'special'), ('production_id', '=', production.id),
|
||||
('is_auto', '=', False), ('active', 'in', [True, False])])
|
||||
for special in special_design:
|
||||
workorders_values = []
|
||||
if special.active is False:
|
||||
# is_cancel = False
|
||||
# 工单采购单外协出入库单皆需取消
|
||||
domain = [('production_id', '=', special.production_id.id)]
|
||||
if special.process_parameters_id:
|
||||
domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id), ('state', '!=', 'cancel')]
|
||||
else:
|
||||
domain += [('technology_design_id', '=', special.id), ('state', '!=', 'cancel')]
|
||||
workorder = self.env['mrp.workorder'].search(domain)
|
||||
# previous_workorder = self.env['mrp.workorder'].search(
|
||||
# [('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'),
|
||||
# ('production_id', '=', workorder.production_id.id)])
|
||||
# if previous_workorder:
|
||||
# if previous_workorder.supplier_id != workorder.supplier_id:
|
||||
# is_cancel = True
|
||||
# if workorder.state != 'cancel' and is_cancel is True:
|
||||
workorder.write({'state': 'cancel'})
|
||||
workorder.picking_ids.write({'state': 'cancel'})
|
||||
workorder.picking_ids.move_ids.write({'state': 'cancel'})
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('origin', '=', workorder.production_id.name), ('purchase_type', '=', 'consignment')])
|
||||
for line in purchase_order.order_line:
|
||||
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id:
|
||||
purchase_order.write({'state': 'cancel'})
|
||||
else:
|
||||
if special.production_id.workorder_ids:
|
||||
workorder = self.env['mrp.workorder'].search(
|
||||
[('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id), ('state', '!=', 'cancel')])
|
||||
if not workorder:
|
||||
if special.route_id.routing_type == '表面工艺':
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(special.production_id, special,
|
||||
product_production_process.seller_ids[
|
||||
0].partner_id.id))
|
||||
else:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(special.production_id, special))
|
||||
special.production_id.write({'workorder_ids': workorders_values})
|
||||
else:
|
||||
if len(workorder.blocked_by_workorder_ids) > 1:
|
||||
if workorder.sequence == 1:
|
||||
workorder.blocked_by_workorder_ids = None
|
||||
else:
|
||||
if workorder.blocked_by_workorder_ids:
|
||||
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
|
||||
productions._create_workorder(False)
|
||||
pr = cProfile.Profile()
|
||||
pr.enable()
|
||||
self._process_production(productions,technology_designs)
|
||||
productions = productions._create_workorder(False)
|
||||
if self.production_id.product_id.categ_id.type == '成品':
|
||||
productions.get_subcontract_pick_purchase()
|
||||
productions.is_adjust = False
|
||||
self.production_id.get_subcontract_pick_purchase(productions)
|
||||
for item in productions:
|
||||
item.is_adjust = False
|
||||
workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
|
||||
key=lambda a: a.sequence)
|
||||
if workorder[0].state in ['pending']:
|
||||
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
|
||||
workorder[0].state = 'waiting'
|
||||
pr.disable() # 停止性能分析
|
||||
|
||||
# 将结果输出到 StringIO
|
||||
s = io.StringIO()
|
||||
ps = pstats.Stats(pr, stream=s)
|
||||
ps.strip_dirs().sort_stats('cumulative').print_stats()
|
||||
analysis_output = s.getvalue()
|
||||
return productions
|
||||
|
||||
@@ -16,7 +16,6 @@ class SFMessageProduct(models.Model):
|
||||
mrp_production_list = self.env['mrp.production'].sudo().search(
|
||||
[('product_id', '=', product_product.id)])
|
||||
production_num = 0
|
||||
routing_type = None
|
||||
for mrp_production_info in mrp_production_list:
|
||||
routing_type = '人工线下加工' if mrp_production_info.production_type == '人工线下加工' else '装夹预调'
|
||||
mrp_production_ready = mrp_production_info.workorder_ids.filtered(
|
||||
@@ -24,7 +23,7 @@ class SFMessageProduct(models.Model):
|
||||
if mrp_production_ready:
|
||||
production_num += 1
|
||||
if production_num >= 1:
|
||||
url = self.get_request_url(routing_type)
|
||||
url = self.get_request_url()
|
||||
content = content.replace('{{product_id}}', product_product.name).replace(
|
||||
'{{number}}', str(production_num)).replace(
|
||||
'{{request_url}}', url)
|
||||
@@ -43,15 +42,11 @@ class SFMessageProduct(models.Model):
|
||||
contents.append(content)
|
||||
return contents, message_queue_ids
|
||||
|
||||
def get_request_url(self, routing_type):
|
||||
def get_request_url(self):
|
||||
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
action_id = self.env.ref('sf_message.mrp_workorder_issued_action').id
|
||||
menu_id = self.env.ref('mrp.menu_mrp_root').id
|
||||
if routing_type == '人工线下加工':
|
||||
routing_name = '线下工作中心'
|
||||
else:
|
||||
routing_name = '工件装夹中心'
|
||||
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', routing_name)]).id
|
||||
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', '工件装夹中心')]).id
|
||||
# 查询参数
|
||||
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
|
||||
'view_type': 'list', 'active_id': active_id}
|
||||
|
||||
@@ -200,17 +200,6 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
|
||||
'send_time': ret['send_time'],
|
||||
})
|
||||
logging.info('已创建无效功能刀具的编程记录:%s' % production.name)
|
||||
elif ret['reprogramming_reason']:
|
||||
production.programming_record_ids.create({
|
||||
'number': len(production.programming_record_ids) + 1,
|
||||
'production_id': production.id,
|
||||
'reason': ret['reprogramming_reason'],
|
||||
'programming_method': ret['programme_way'],
|
||||
'current_programming_count': ret['reprogramming_num'],
|
||||
'target_production_id': productions_reprogram,
|
||||
'apply_time': ret['trigger_time'],
|
||||
'send_time': ret['send_time'],
|
||||
})
|
||||
else:
|
||||
logging.info('无对应状态,不需更新编程记录')
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class QualityCheck(models.Model):
|
||||
@api.depends('point_id.is_inspect')
|
||||
def _compute_quality_state(self):
|
||||
for qc in self:
|
||||
if qc.point_id.is_inspect and qc.quality_state == 'none' and qc.workorder_id.state != 'to be detected':
|
||||
if qc.point_id.is_inspect and qc.quality_state == 'none':
|
||||
qc.quality_state = 'waiting'
|
||||
elif not qc.point_id.is_inspect and qc.quality_state == 'waiting':
|
||||
qc.quality_state = 'none'
|
||||
@@ -62,9 +62,7 @@ class QualityCheck(models.Model):
|
||||
def do_pass(self):
|
||||
self.ensure_one()
|
||||
super().do_pass()
|
||||
if self.workorder_id:
|
||||
if self.workorder_id.state in ('pending', 'waiting'):
|
||||
raise ValidationError('工单未就绪!')
|
||||
if self.workorder_id and self.individuation_page_PTD is True:
|
||||
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
|
||||
if self.test_results in ['返工', '报废']:
|
||||
raise ValidationError('请重新选择【判定结果】-【检测结果】')
|
||||
@@ -76,9 +74,7 @@ class QualityCheck(models.Model):
|
||||
def do_fail(self):
|
||||
self.ensure_one()
|
||||
super().do_fail()
|
||||
if self.workorder_id:
|
||||
if self.workorder_id.state in ('pending', 'waiting'):
|
||||
raise ValidationError('工单未就绪!')
|
||||
if self.workorder_id and self.individuation_page_PTD is True:
|
||||
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
|
||||
if not self.test_results:
|
||||
raise ValidationError('请填写【判定结果】里的信息')
|
||||
|
||||
@@ -9,24 +9,22 @@
|
||||
<field name="production_id" invisible="1"/>
|
||||
<field name="work_state" invisible="1"/>
|
||||
<field name="individuation_page_PTD" invisible="1"/>
|
||||
<field name="production_line_id" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<field name="equipment_id" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<field name="production_line_id" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
<field name="equipment_id" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
<field name="model_file" widget="Viewer3D" string="模型" readonly="1" force_save="1"
|
||||
attrs="{'invisible': ['|',('model_file', '=', False), ('production_id', '=', False)]}"/>
|
||||
attrs="{'invisible': ['|', '|',('model_file', '=', False), ('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="processing_panel" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<!-- <field name="production_id" string="制造订单" readonly="1"-->
|
||||
<!-- attrs="{'invisible': [('production_id', '=', False)]}"/>-->
|
||||
<field name="processing_panel" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
<field name="workorder_id" string="工单号" readonly="1"
|
||||
attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<field name="is_inspect" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
<field name="is_inspect" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='notes']" position="before">
|
||||
<page string="检测报告" attrs="{'invisible': [('production_id', '=', False)]}">
|
||||
<page string="检测报告" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}">
|
||||
<field name="detection_report" string="" widget="pdf_viewer"/>
|
||||
</page>
|
||||
<page string="判定结果" attrs="{'invisible': [('production_id', '=', False)]}">
|
||||
<page string="判定结果" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}">
|
||||
<group>
|
||||
<group>
|
||||
<field name="test_results" attrs="{'readonly': [('quality_state','in', ['pass', 'fail'])]}"/>
|
||||
@@ -37,33 +35,25 @@
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page string="2D图纸" attrs="{'invisible': [('production_id', '=', False)]}">
|
||||
<page string="2D图纸" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}">
|
||||
<field name="machining_drawings" string="" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
<page string="客户质量标准" attrs="{'invisible': [('production_id', '=', False)]}">
|
||||
<page string="客户质量标准" attrs="{'invisible': ['|',('production_id', '=', False), ('individuation_page_PTD', '=', False)]}">
|
||||
<field name="quality_standard" string="" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
<page string="其他"
|
||||
attrs="{'invisible': ['|',('quality_state', 'not in', ['pass', 'fail']), ('production_id', '=', False)]}">
|
||||
attrs="{'invisible': ['|','|', ('quality_state', 'not in', ['pass', 'fail']), ('production_id', '=', False),('individuation_page_PTD', '=', False)]}">
|
||||
<group>
|
||||
<field name="write_uid" widget='many2one_avatar_user' string="判定人" readonly="1"/>
|
||||
<field name="write_date" string="判定时间" readonly="1"/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="//header//button[@name='do_pass'][1]" position="attributes">
|
||||
<attribute name="string">合格</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//header//button[@name='do_pass'][2]" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|',('quality_state', '!=', 'fail'),('work_state','in', ('done', 'rework'))]}</attribute>
|
||||
<attribute name="string">合格</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//header//button[@name='do_fail'][1]" position="attributes">
|
||||
<attribute name="string">不合格</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//header//button[@name='do_fail'][2]" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|',('quality_state', '!=', 'pass'),('work_state','in', ('done', 'rework'))]}</attribute>
|
||||
<attribute name="string">不合格</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -130,10 +130,7 @@ class ReSaleOrder(models.Model):
|
||||
'order_id': self.id,
|
||||
'product_id': product.id,
|
||||
'name': '%s/%s/%s/%s/%s/%s' % (
|
||||
self.format_float(product.model_long),
|
||||
self.format_float(product.model_width),
|
||||
self.format_float(product.model_height),
|
||||
self.format_float(product.model_volume),
|
||||
product.model_long, product.model_width, product.model_height, product.model_volume,
|
||||
machining_accuracy_name,
|
||||
product.materials_id.name),
|
||||
'price_unit': product.list_price,
|
||||
@@ -146,20 +143,6 @@ class ReSaleOrder(models.Model):
|
||||
}
|
||||
return self.env['sale.order.line'].with_context(skip_procurement=True).create(vals)
|
||||
|
||||
def format_float(self, value):
|
||||
# 将浮点数转换为字符串
|
||||
value_str = str(value)
|
||||
# 检查小数点的位置
|
||||
if '.' in value_str:
|
||||
# 获取小数部分
|
||||
decimal_part = value_str.split('.')[1]
|
||||
# 判断小数位数是否超过2位
|
||||
if len(decimal_part) > 2:
|
||||
# 超过2位则保留2位小数
|
||||
return "{:.2f}".format(value)
|
||||
# 否则保持原来的位数
|
||||
return float(value_str)
|
||||
|
||||
@api.constrains('order_line')
|
||||
def check_order_line(self):
|
||||
for item in self:
|
||||
|
||||
Reference in New Issue
Block a user