diff --git a/jikimo_workorder_exception/controllers/main.py b/jikimo_workorder_exception/controllers/main.py
index 03744ff9..cf208700 100644
--- a/jikimo_workorder_exception/controllers/main.py
+++ b/jikimo_workorder_exception/controllers/main.py
@@ -4,6 +4,7 @@ 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__)
@@ -30,6 +31,7 @@ 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': '无效的工单'}
@@ -41,7 +43,10 @@ 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)
diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py
index 2a5e4d3e..64a981ad 100644
--- a/sf_manufacturing/controllers/controllers.py
+++ b/sf_manufacturing/controllers/controllers.py
@@ -596,6 +596,9 @@ 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']}
diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index 1a35b251..0d4ca196 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -577,16 +577,19 @@ class MrpProduction(models.Model):
# 编程单更新
# 增加触发时间参数
- def update_programming_state(self, trigger_time=None):
+ def update_programming_state(self, trigger_time=None, reprogramming_reason=None):
try:
- manufacturing_type = 'rework'
+ manufacturing_type = None
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}
+ 'trigger_time': trigger_time,
+ 'reprogramming_reason': reprogramming_reason}
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'])
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 1980ae1a..ef121e1b 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -455,6 +455,32 @@ 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
@@ -1543,7 +1569,8 @@ class ResMrpWorkOrder(models.Model):
# 修改工单状态
self.write({'state': 'to be detected'})
# 若关联的【质量检查_需送检】=true,则质量检查单的状态从“等待”更新为“待处理”
- self.check_ids.filtered(lambda ch: ch.is_inspect is True).write({'quality_state': 'none'})
+ self.check_ids.filtered(lambda ch: ch.is_inspect is True and ch.quality_state == 'waiting').write(
+ {'quality_state': 'none'})
class CNCprocessing(models.Model):
diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py
index 986173f1..ca1f2973 100644
--- a/sf_manufacturing/models/stock.py
+++ b/sf_manufacturing/models/stock.py
@@ -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())
diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml
index 505d0c41..3dba032c 100644
--- a/sf_manufacturing/views/mrp_workorder_view.xml
+++ b/sf_manufacturing/views/mrp_workorder_view.xml
@@ -163,6 +163,7 @@
+
@@ -182,7 +183,7 @@
+ attrs="{'invisible': ['|', '|', '|',('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('is_user_working', '=', False),'&','&',('state', 'in', ('progress')), ('is_inspect', '=', True), ('routing_type','!=','CNC加工')]}"/>
+
+
+
@@ -533,7 +537,7 @@
diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py
index 8c2c7be9..69cc45ca 100644
--- a/sf_mrs_connect/controllers/controllers.py
+++ b/sf_mrs_connect/controllers/controllers.py
@@ -200,6 +200,17 @@ 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('无对应状态,不需更新编程记录')
diff --git a/sf_quality/models/quality.py b/sf_quality/models/quality.py
index 55b831cc..201103f1 100644
--- a/sf_quality/models/quality.py
+++ b/sf_quality/models/quality.py
@@ -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':
+ if qc.point_id.is_inspect and qc.quality_state == 'none' and qc.workorder_id.state != 'to be detected':
qc.quality_state = 'waiting'
elif not qc.point_id.is_inspect and qc.quality_state == 'waiting':
qc.quality_state = 'none'
@@ -62,7 +62,9 @@ class QualityCheck(models.Model):
def do_pass(self):
self.ensure_one()
super().do_pass()
- if self.workorder_id and self.individuation_page_PTD is True:
+ if self.workorder_id:
+ if self.workorder_id.state in ('pending', 'waiting'):
+ raise ValidationError('工单未就绪!')
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
if self.test_results in ['返工', '报废']:
raise ValidationError('请重新选择【判定结果】-【检测结果】')
@@ -74,7 +76,9 @@ class QualityCheck(models.Model):
def do_fail(self):
self.ensure_one()
super().do_fail()
- if self.workorder_id and self.individuation_page_PTD is True:
+ if self.workorder_id:
+ if self.workorder_id.state in ('pending', 'waiting'):
+ raise ValidationError('工单未就绪!')
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
if not self.test_results:
raise ValidationError('请填写【判定结果】里的信息')
diff --git a/sf_quality/views/quality_check_view.xml b/sf_quality/views/quality_check_view.xml
index 19f272f4..61309737 100644
--- a/sf_quality/views/quality_check_view.xml
+++ b/sf_quality/views/quality_check_view.xml
@@ -9,22 +9,24 @@
-
-
+
+
+ attrs="{'invisible': ['|',('model_file', '=', False), ('production_id', '=', False)]}"/>
-
+
+
+
-
+ attrs="{'invisible': [('production_id', '=', False)]}"/>
+
-
+
-
+
@@ -35,25 +37,33 @@
-
+
-
+
+ attrs="{'invisible': ['|',('quality_state', 'not in', ['pass', 'fail']), ('production_id', '=', False)]}">
+
+ 合格
+
{'invisible': ['|',('quality_state', '!=', 'fail'),('work_state','in', ('done', 'rework'))]}
+ 合格
+
+
+ 不合格
{'invisible': ['|',('quality_state', '!=', 'pass'),('work_state','in', ('done', 'rework'))]}
+ 不合格
diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py
index 73837271..31681932 100644
--- a/sf_sale/models/sale_order.py
+++ b/sf_sale/models/sale_order.py
@@ -130,7 +130,10 @@ class ReSaleOrder(models.Model):
'order_id': self.id,
'product_id': product.id,
'name': '%s/%s/%s/%s/%s/%s' % (
- product.model_long, product.model_width, product.model_height, product.model_volume,
+ self.format_float(product.model_long),
+ self.format_float(product.model_width),
+ self.format_float(product.model_height),
+ self.format_float(product.model_volume),
machining_accuracy_name,
product.materials_id.name),
'price_unit': product.list_price,
@@ -143,6 +146,20 @@ 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: