# -*- coding: utf-8 -*- # Part of YiZuo. See LICENSE file for full copyright and licensing details. import logging from itertools import groupby from odoo import models, api, fields, _ class ProductionTechnologyWizard(models.TransientModel): _name = 'sf.production.technology.wizard' _description = '制造订单工艺确认向导' production_id = fields.Many2one('mrp.production', string='制造订单号') origin = fields.Char(string='源单据') is_technology_confirm = fields.Boolean(default=True) 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'), ('product_id', '=', self.production_id.product_id.id)] else: domain = [('id', '=', self.production_id.id)] technology_designs = self.env['sf.technology.design'].sudo().search( [('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) if self.production_id.product_id.categ_id.type == '成品': productions.get_subcontract_pick_purchase() productions.is_adjust = False for item in productions: 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' return productions