# -*- coding: utf-8 -*- # Part of YiZuo. See LICENSE file for full copyright and licensing details. import logging from odoo.exceptions import UserError, ValidationError from datetime import datetime from odoo import models, api, fields, _ class ReworkWizard(models.TransientModel): _name = 'sf.rework.wizard' _description = '返工向导' workorder_id = fields.Many2one('mrp.workorder', string='工单') product_id = fields.Many2one('product.product') production_id = fields.Many2one('mrp.production', string='制造订单号') rework_reason = fields.Selection( [("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), ("operate computer", "操机"), ("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因", tracking=True) detailed_reason = fields.Text('详细原因') routing_type = fields.Selection([ ('装夹预调', '装夹预调'), ('CNC加工', 'CNC加工')], string="工序类型") # 根据工单的加工面来显示 processing_panel_id = fields.Many2one('sf.processing.panel', string="加工面") is_reprogramming = fields.Boolean(string='申请重新编程', default=False) def confirm(self): if self.is_reprogramming is True: if self.production_id.workorder_ids: panel_workorder = self.production_id.workorder_ids.filtered( lambda ap: ap.processing_panel == self.processing_panel_id.name) if panel_workorder: panel_workorder.write({'state': 'rework'}) product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search( [('product_model_type_id', '=', self.production_id.product_id.product_model_type_id.id)], order='sequence asc' ) workorders_values = [] for route in product_routing_workcenter: if route.is_repeat is True: workorders_values.append( self.env['mrp.workorder'].json_workorder_str(self.processing_panel_id.name, self.production_id, route, False)) if workorders_values: self.production_id.write({'workorder_ids': workorders_values, 'programming_state': '编程中'}) self.production_id._reset_work_order_sequence() self.production_id.update_programming_state() else: self.workorder_id.is_rework = True self.production_id.write({'detection_result_ids': [(0, 0, { 'rework_reason': self.rework_reason, 'detailed_reason': self.detailed_reason, # 'processing_panel': self.workorder_id.processing_panel, 'routing_type': self.workorder_id.routing_type, 'test_results': self.workorder_id.test_results, 'test_report': self.workorder_id.detection_report})]}) @api.onchange('product_id') def onchange_processing_panel_id(self): for item in self: domain = [('id', '=', False)] product_id = item.product_id if product_id: if self.env.user.has_group('sf_base.group_sf_order_user'): panel_ids = [] for p in product_id.model_processing_panel.split(','): panel = self.env['sf.processing.panel'].search( [('name', 'ilike', p)]) if panel: panel_ids.append(panel.id) domain = {'processing_panel_id': [('id', 'in', panel_ids)]} return {'domain': domain}