Merge branch 'refs/heads/develop' into feature/tool_standard_library_process
# Conflicts: # sf_manufacturing/models/mrp_workorder.py
This commit is contained in:
@@ -19,12 +19,8 @@ class AgvScheduling(models.Model):
|
||||
_order = 'id desc'
|
||||
|
||||
name = fields.Char('任务单号', index=True, copy=False)
|
||||
|
||||
def _get_agv_route_type_selection(self):
|
||||
return self.env['sf.agv.task.route'].fields_get(['route_type'])['route_type']['selection']
|
||||
|
||||
agv_route_type = fields.Selection(selection=_get_agv_route_type_selection, string='任务类型', required=True)
|
||||
agv_route_id = fields.Many2one('sf.agv.task.route', '任务路线')
|
||||
agv_route_type = fields.Selection(related='agv_route_id.route_type', string='任务类型', required=True)
|
||||
start_site_id = fields.Many2one('sf.agv.site', '起点接驳站', required=True)
|
||||
end_site_id = fields.Many2one('sf.agv.site', '终点接驳站', tracking=True)
|
||||
site_state = fields.Selection([
|
||||
|
||||
@@ -235,7 +235,7 @@ class MrpProduction(models.Model):
|
||||
programming_no = fields.Char('编程单号')
|
||||
work_state = fields.Char('业务状态')
|
||||
programming_state = fields.Selection(
|
||||
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发')],
|
||||
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发'), ('已取消', '已取消')],
|
||||
string='编程状态',
|
||||
tracking=True)
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
@@ -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'])
|
||||
@@ -643,6 +646,28 @@ class MrpProduction(models.Model):
|
||||
logging.info('update_programming_state error:%s' % e)
|
||||
raise UserError("更新编程单状态失败,请联系管理员")
|
||||
|
||||
# 修改编程单状态
|
||||
def _change_programming_state(self):
|
||||
try:
|
||||
res = {"programming_no": self.programming_no, "state": "已取消"}
|
||||
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'])
|
||||
url = '/api/intelligent_programming/set_state'
|
||||
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('change_programming_state-ret:%s' % result)
|
||||
if result['status'] == 1:
|
||||
self.write({'programming_state': '已取消'})
|
||||
else:
|
||||
raise UserError(ret['message'])
|
||||
except Exception as e:
|
||||
logging.info('change_programming_state error:%s' % e)
|
||||
raise UserError("修改编程单状态失败,请联系管理员")
|
||||
|
||||
|
||||
# cnc程序获取
|
||||
def fetchCNC(self, production_names):
|
||||
cnc = self.env['mrp.production'].search([('id', '=', self.id)])
|
||||
@@ -655,6 +680,8 @@ class MrpProduction(models.Model):
|
||||
programme_way = 'manual operation'
|
||||
else:
|
||||
programme_way = 'auto'
|
||||
if cnc.production_type == '人工线下加工':
|
||||
programme_way = 'manual operation'
|
||||
if quick_order:
|
||||
programme_way = 'manual operation'
|
||||
try:
|
||||
@@ -1254,6 +1281,7 @@ class MrpProduction(models.Model):
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_is_clamping': True if self.workorder_ids.filtered(lambda wk: wk.routing_type == '装夹预调') else False,
|
||||
'default_workorder_ids': workorder_ids.ids if workorder_ids.ids != [] else self.workorder_ids.ids,
|
||||
'default_hidden_workorder_ids': ','.join(map(str, work_id_list)) if work_id_list != [] else '',
|
||||
'default_reprogramming_num': cloud_programming.get('reprogramming_num') if cloud_programming else '',
|
||||
@@ -1292,7 +1320,7 @@ class MrpProduction(models.Model):
|
||||
for rework_item in rework_workorder:
|
||||
pending_workorder = production.workorder_ids.filtered(
|
||||
lambda m1: m1.state in [
|
||||
'pending'] and m1.processing_panel == rework_item.processing_panel and m1.routing_type == 'CNC加工')
|
||||
'pending'] and m1.processing_panel == rework_item.processing_panel and m1.routing_type in ['CNC加工', '人工线下加工'])
|
||||
if not pending_workorder.cnc_ids:
|
||||
production.get_new_program(rework_item.processing_panel)
|
||||
# production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False})
|
||||
@@ -1302,6 +1330,7 @@ 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}')
|
||||
@@ -1334,7 +1363,7 @@ class MrpProduction(models.Model):
|
||||
if productions:
|
||||
for production in productions:
|
||||
panel_workorder = production.workorder_ids.filtered(lambda
|
||||
pw: pw.processing_panel == processing_panel and pw.routing_type == 'CNC加工' and pw.state not in (
|
||||
pw: pw.processing_panel == processing_panel and pw.routing_type in ['CNC加工', '人工线下加工'] and pw.state not in (
|
||||
'rework', 'done'))
|
||||
if panel_workorder:
|
||||
if panel_workorder.cmm_ids:
|
||||
@@ -1360,7 +1389,7 @@ class MrpProduction(models.Model):
|
||||
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
logging.info('len(cnc_worksheet):%s' % len(panel_workorder.cnc_worksheet))
|
||||
pre_workorder = production.workorder_ids.filtered(lambda
|
||||
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state not in (
|
||||
ap: ap.routing_type in ['装夹预调', '人工线下加工'] and ap.processing_panel == processing_panel and ap.state not in (
|
||||
'rework', 'done'))
|
||||
if pre_workorder:
|
||||
pre_workorder.write(
|
||||
@@ -1698,7 +1727,7 @@ class sf_programming_record(models.Model):
|
||||
programming_method = fields.Selection([
|
||||
('auto', '自动'),
|
||||
('manual operation', '人工')], string="编程方式")
|
||||
current_programming_count = fields.Integer('当前编程次数')
|
||||
current_programming_count = fields.Integer('重新编程次数')
|
||||
target_production_id = fields.Char('目标制造单号')
|
||||
apply_time = fields.Datetime('申请时间')
|
||||
send_time = fields.Datetime('下发时间')
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import random
|
||||
import re
|
||||
import json
|
||||
import logging
|
||||
@@ -114,6 +113,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
record.back_button_display = False
|
||||
if cur_workorder.is_subcontract:
|
||||
record.back_button_display = False
|
||||
date_planned_start = fields.Datetime(tracking=True)
|
||||
|
||||
@api.depends('processing_panel')
|
||||
def _compute_processing_panel_selection(self):
|
||||
@@ -578,6 +578,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
|
||||
@@ -1183,7 +1209,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
if (workorder.production_id.production_type == '人工线下加工'
|
||||
and workorder.production_id.schedule_state == '已排'
|
||||
and len(workorder.production_id.picking_ids.filtered(
|
||||
lambda w: w.state not in ['done', 'cancel'])) == 0):
|
||||
lambda w: w.state not in ['done', 'cancel'])) == 0
|
||||
and workorder.production_id.programming_state == '已编程'):
|
||||
if workorder.is_subcontract is True:
|
||||
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
||||
if purchase_orders_id.state == 'purchase':
|
||||
@@ -1240,7 +1267,6 @@ class ResMrpWorkOrder(models.Model):
|
||||
mo.get_move_line(workorder.production_id, workorder))
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
|
||||
# 重写工单开始按钮方法
|
||||
def button_start(self):
|
||||
# 判断工单状态是否为等待组件
|
||||
@@ -1407,8 +1433,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
'detailed_reason': record.detailed_reason,
|
||||
'processing_panel': record.processing_panel,
|
||||
'routing_type': record.routing_type,
|
||||
'handle_result': '待处理' if record.test_results in ['返工',
|
||||
'报废'] or record.is_rework is True else '',
|
||||
'handle_result': '待处理' if record.test_results in ['返工', '报废'] or record.is_rework is True else '',
|
||||
'test_results': record.test_results,
|
||||
'test_report': record.detection_report})],
|
||||
'is_scrap': True if record.test_results == '报废' else False
|
||||
@@ -1425,8 +1450,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
raise UserError('请先完成该工单的工艺外协再进行操作')
|
||||
# 表面工艺外协,最后一张工单
|
||||
workorders = self.production_id.workorder_ids
|
||||
subcontract_workorders = workorders.filtered(
|
||||
lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
|
||||
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
|
||||
if self == subcontract_workorders[-1]:
|
||||
# 给下一个库存移动就绪
|
||||
self.move_subcontract_workorder_ids[0].move_dest_ids._action_done()
|
||||
@@ -1649,7 +1673,6 @@ class ResMrpWorkOrder(models.Model):
|
||||
# 根据工单对应的【作业_个性化记录】配置页签
|
||||
if any(item.code == 'PTD' for item in mw.routing_workcenter_id.individuation_page_ids):
|
||||
mw.individuation_page_PTD = True
|
||||
|
||||
# =============================================================================================
|
||||
|
||||
is_inspect = fields.Boolean('需送检', compute='_compute_is_inspect', store=True, default=False)
|
||||
@@ -1786,8 +1809,8 @@ class CNCprocessing(models.Model):
|
||||
|
||||
# 将FTP的多面的程序单文件下载到临时目录
|
||||
def download_file_tmp(self, production_no, processing_panel):
|
||||
remotepath = os.path.join('/home/ftp/ftp_root/NC', 'production_no', 'return', processing_panel)
|
||||
serverdir = os.path.join('/tmp', 'production_no', 'return', processing_panel)
|
||||
remotepath = os.path.join('/home/ftp/ftp_root/NC', production_no, 'return', processing_panel)
|
||||
serverdir = os.path.join('/tmp', production_no, 'return', processing_panel)
|
||||
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']), ftp_resconfig['ftp_user'],
|
||||
ftp_resconfig['ftp_password'])
|
||||
@@ -1959,11 +1982,7 @@ class WorkPieceDelivery(models.Model):
|
||||
feeder_station_destination_id = fields.Many2one('sf.agv.site', '目的接驳站')
|
||||
task_delivery_time = fields.Datetime('任务下发时间')
|
||||
task_completion_time = fields.Datetime('任务完成时间')
|
||||
|
||||
def _get_agv_route_type_selection(self):
|
||||
return self.env['sf.agv.task.route'].fields_get(['route_type'])['route_type']['selection']
|
||||
|
||||
type = fields.Selection(selection=_get_agv_route_type_selection, string='类型')
|
||||
type = fields.Selection(related='route_id.route_type', string='类型')
|
||||
delivery_duration = fields.Float('配送时长', compute='_compute_delivery_duration')
|
||||
status = fields.Selection(
|
||||
[('待下发', '待下发'), ('已下发', '待配送'), ('已配送', '已配送'), ('已取消', '已取消')], string='状态',
|
||||
|
||||
@@ -149,6 +149,23 @@ class SaleOrder(models.Model):
|
||||
product_bom_purchase.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
|
||||
purchase_embryo)
|
||||
return super(SaleOrder, self).action_confirm()
|
||||
|
||||
def action_show_cancel_wizard(self):
|
||||
wizard = self.env['sf.sale.order.cancel.wizard'].create({
|
||||
'order_id': self.id,
|
||||
})
|
||||
|
||||
# 创建关联单据行
|
||||
self.env['sf.sale.order.cancel.line'].create_from_order(wizard.id, self)
|
||||
|
||||
return {
|
||||
'name': '取消销售订单',
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'sf.sale.order.cancel.wizard',
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
'res_id': wizard.id,
|
||||
}
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
@@ -166,4 +183,6 @@ class SaleOrderLine(models.Model):
|
||||
for line in self:
|
||||
if vals['supply_method'] == 'automation' and line.manual_quotation:
|
||||
raise UserError('当前(%s)产品为人工编程产品,不能选择自动化产线加工' % ','.join(line.mapped('product_id.name')))
|
||||
if vals['supply_method'] == 'purchase' and line.is_incoming_material:
|
||||
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(line.mapped('product_id.name')))
|
||||
return super(SaleOrderLine, self).write(vals)
|
||||
|
||||
@@ -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 == '自动化产线加工':
|
||||
if not production_item.programming_no and production_item.production_type in ['自动化产线加工', '人工线下加工']:
|
||||
if not production_programming.programming_no:
|
||||
production_item.fetchCNC(
|
||||
', '.join(product_id_to_production_names[production_item.product_id.id]))
|
||||
@@ -314,6 +314,11 @@ class StockRule(models.Model):
|
||||
i += 1
|
||||
technology_design_values.append(
|
||||
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
|
||||
elif production_item.production_type == '人工线下加工':
|
||||
for route in product_routing_workcenter:
|
||||
i += 1
|
||||
technology_design_values.append(
|
||||
self.env['sf.technology.design'].json_technology_design_str('ZM', route, i, False))
|
||||
else:
|
||||
for route in product_routing_workcenter:
|
||||
i += 1
|
||||
@@ -606,6 +611,18 @@ class StockPicking(models.Model):
|
||||
return sequence_id
|
||||
|
||||
def button_validate(self):
|
||||
# 校验“收料入库单、客供料入库单”是否已经分配序列号,如果没有分配则自动分配
|
||||
if self.picking_type_id.use_existing_lots is False and self.picking_type_id.use_create_lots is True:
|
||||
for move in self.move_ids:
|
||||
if not move.move_line_nosuggest_ids:
|
||||
move.action_show_details()
|
||||
else:
|
||||
# 对已经生成的序列号做唯一性校验,如果重复则重新生成新的序列号
|
||||
line_lot_name = [line_id.lot_name for line_id in move.move_line_nosuggest_ids]
|
||||
lot_ids = self.env['stock.lot'].sudo().search([('name', 'in', line_lot_name)])
|
||||
if lot_ids:
|
||||
move.action_clear_lines_show_details()
|
||||
move.action_show_details()
|
||||
res = super().button_validate()
|
||||
picking_type_in = self.env.ref('sf_manufacturing.outcontract_picking_in').id
|
||||
if res is True and self.picking_type_id.id == picking_type_in:
|
||||
@@ -839,7 +856,8 @@ class ReStockMove(models.Model):
|
||||
self.next_serial = self._get_tool_next_serial(self.company_id, self.product_id, self.origin)
|
||||
else:
|
||||
self.next_serial = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
||||
if self.picking_type_id.sequence_code == 'DL' and not self.move_line_nosuggest_ids:
|
||||
if (self.picking_type_id.use_existing_lots is False
|
||||
and self.picking_type_id.use_create_lots is True and not self.move_line_nosuggest_ids):
|
||||
self.action_assign_serial_show_details()
|
||||
elif self.product_id.tracking == "lot":
|
||||
self._put_tool_lot(self.company_id, self.product_id, self.origin)
|
||||
|
||||
Reference in New Issue
Block a user