49 lines
2.4 KiB
Python
49 lines
2.4 KiB
Python
# -*- 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=False)
|
|
|
|
def confirm(self):
|
|
if self.is_technology_confirm is True:
|
|
domain = [('origin', '=', self.origin)]
|
|
else:
|
|
domain = [('id', '=', self.production_id.id)]
|
|
technology_designs = self.production_id.technology_design_ids
|
|
productions = self.env['mrp.production'].search(domain)
|
|
for production in productions:
|
|
if production != self.production_id:
|
|
for td_other in production.technology_design_ids:
|
|
for td_main in technology_designs:
|
|
route_other = production.technology_design_ids.filtered(
|
|
lambda td: td.route_id.id == td_main.route_id.id)
|
|
if not route_other:
|
|
production.write({'technology_design_ids': [(0, 0, {
|
|
'route_id': td_main.route_id.id,
|
|
'process_parameters_id': False if td_main.process_parameters_id is False else self.env[
|
|
'sf.production.process.parameter'].search(
|
|
[('id', '=', td_main.process_parameters_id.id)]).id,
|
|
'sequence': td_main.sequence})]})
|
|
else:
|
|
if td_main.sequence != td_other.sequence:
|
|
td_other.sequence = td_main.sequence
|
|
special = production.technology_design_ids.filtered(
|
|
lambda td: td.is_auto is False and td.process_parameters_id is not False)
|
|
if special:
|
|
production.get_subcontract_purchase()
|
|
productions._create_workorder(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']:
|
|
workorder[0].state = 'waiting'
|