104 lines
6.1 KiB
Python
104 lines
6.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of YiZuo. See LICENSE file for full copyright and licensing details.
|
|
import logging
|
|
from odoo.exceptions import UserError, ValidationError
|
|
from collections import defaultdict, namedtuple
|
|
from odoo.addons.stock.models.stock_rule import ProcurementException
|
|
from datetime import datetime
|
|
from odoo import models, api, fields, _
|
|
|
|
|
|
class ProductionWizard(models.TransientModel):
|
|
_name = 'sf.production.wizard'
|
|
_description = '制造订单向导'
|
|
|
|
production_id = fields.Many2one('mrp.production', string='制造订单号')
|
|
reprogramming_num = fields.Integer('重新编程次数', default=0)
|
|
is_reprogramming = fields.Boolean(string='申请重新编程', default=False)
|
|
is_remanufacture = fields.Boolean(string='重新生成制造订单', default=True)
|
|
programming_states = fields.Selection(
|
|
[('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'),
|
|
('已下发', '已下发')],
|
|
string='编程状态')
|
|
|
|
@api.onchange('is_remanufacture')
|
|
def _onchange_is_reprogramming(self):
|
|
if self.is_remanufacture is False:
|
|
self.is_reprogramming = False
|
|
|
|
def confirm(self):
|
|
self.production_id.detection_result_ids.write({'handle_result': '已处理'})
|
|
self.production_id.write({'state': 'cancel', 'scrap_ids': [(0, 0, {
|
|
'name': self.env['ir.sequence'].next_by_code('stock.scrap') or _('New'),
|
|
'product_id': self.production_id.product_id.id,
|
|
'scrap_qty': 1,
|
|
'origin': self.production_id.origin,
|
|
'date_done': fields.datetime.now(),
|
|
'lot_id': self.env['stock.move.line'].search(
|
|
[('move_id', '=', self.production_id.move_raw_ids[0].id)]).lot_id.id,
|
|
'location_id': self.production_id.move_raw_ids.filtered(lambda x: x.state not in (
|
|
'done',
|
|
'cancel')) and self.production_id.location_src_id.id or self.production_id.location_dest_id.id,
|
|
'scrap_location_id': self.env['stock.scrap']._get_default_scrap_location_id(),
|
|
'state': 'done'})]})
|
|
self.production_id.action_cancel()
|
|
if self.is_remanufacture is True:
|
|
ret = {'programming_list': [], 'is_reprogramming': self.is_reprogramming}
|
|
if self.is_reprogramming is True:
|
|
self.production_id.update_programming_state()
|
|
else:
|
|
scrap_cnc = self.production_id.workorder_ids.filtered(lambda crw: crw.routing_type == 'CNC加工').cnc_ids
|
|
scrap_cmm = self.production_id.workorder_ids.filtered(lambda cm: cm.routing_type == 'CNC加工').cmm_ids
|
|
for item_line in scrap_cnc:
|
|
vals = {
|
|
'sequence_number': item_line.sequence_number,
|
|
'program_name': item_line.program_name,
|
|
'cutting_tool_name': item_line.cutting_tool_name,
|
|
'cutting_tool_no': item_line.cutting_tool_no,
|
|
'processing_type': item_line.processing_type,
|
|
'margin_x_y': item_line.margin_x_y,
|
|
'margin_z': item_line.margin_z,
|
|
'depth_of_processing_z': item_line.depth_of_processing_z,
|
|
'cutting_tool_extension_length': item_line.cutting_tool_extension_length,
|
|
'estimated_processing_time': item_line.estimated_processing_time,
|
|
'cutting_tool_handle_type': item_line.cutting_tool_handle_type,
|
|
'ftp_path': item_line.program_path,
|
|
'processing_panel': item_line.workorder_id.processing_panel,
|
|
'program_create_date': datetime.strftime(item_line.program_create_date,
|
|
'%Y-%m-%d %H:%M:%S'),
|
|
'remark': item_line.remark
|
|
}
|
|
ret['programming_list'].append(vals)
|
|
for cmm_line in scrap_cmm:
|
|
vals = {
|
|
'sequence_number': cmm_line.sequence_number,
|
|
'program_name': cmm_line.program_name,
|
|
'ftp_path': cmm_line.program_path,
|
|
'processing_panel': item_line.workorder_id.processing_panel,
|
|
'program_create_date': datetime.strftime(
|
|
cmm_line.program_create_date,
|
|
'%Y-%m-%d %H:%M:%S')
|
|
}
|
|
ret['programming_list'].append(vals)
|
|
|
|
new_production = self.production_id.recreateManufacturing(ret)
|
|
self.production_id.write({'remanufacture_production_id': new_production.id})
|
|
if self.is_reprogramming is False:
|
|
for panel in new_production.product_id.model_processing_panel.split(','):
|
|
scrap_cnc_workorder = max(
|
|
self.production_id.workorder_ids.filtered(
|
|
lambda
|
|
scn: scn.processing_panel == panel and scn.routing_type == 'CNC加工'),
|
|
key=lambda w: w.create_date)
|
|
scrap_pre_workorder = max(self.production_id.workorder_ids.filtered(
|
|
lambda
|
|
pr: pr.processing_panel == panel and pr.routing_type == '装夹预调'),
|
|
key=lambda w1: w1.create_date)
|
|
new_cnc_workorder = new_production.workorder_ids.filtered(
|
|
lambda
|
|
nc: nc.processing_panel == panel and nc.routing_type == 'CNC加工')
|
|
new_cnc_workorder.write({'cnc_worksheet': scrap_cnc_workorder.cnc_worksheet})
|
|
new_pre_workorder = new_production.workorder_ids.filtered(lambda
|
|
p: p.routing_type == '装夹预调' and p.processing_panel == panel)
|
|
new_pre_workorder.write({'processing_drawing': scrap_pre_workorder.processing_drawing})
|