优化工单

This commit is contained in:
jinling.yang
2024-11-13 17:59:47 +08:00
parent ff072a32bb
commit 33a1837274
7 changed files with 214 additions and 166 deletions

View File

@@ -1,10 +1,6 @@
# -*- 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 itertools import groupby
from odoo import models, api, fields, _
@@ -18,58 +14,54 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
def confirm(self):
if self.is_technology_re_adjust is True:
domain = [('origin', '=', self.origin),('state', '=', 'confirmed')]
domain = [('origin', '=', self.origin), ('state', '=', 'confirmed')]
else:
domain = [('id', '=', self.production_id.id)]
productions = self.env['mrp.production'].search(domain)
workorders_values = []
for item in productions:
special_design = item.technology_design_ids.filtered(
lambda a: a.routing_tag == 'special' and a.is_auto is False and a.active in [True, False])
workorders_values = []
for item in special_design:
if item.active is False:
special_design = self.env['sf.technology.design'].sudo().search(
[('routing_tag', '=', 'special'), ('production_id', '=', item.id),
('is_auto', '=', False), ('active', 'in', [True, False])])
for special in special_design:
if special.active is False:
# 工单采购单外协出入库单皆需取消
domain = [('production_id', '=', item.id)]
if item.process_parameters_id:
domain += [('surface_technics_parameters_id', '=', item.process_parameters_id)]
domain = [('production_id', '=', special.production_id.id)]
if special.process_parameters_id:
domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id)]
else:
domain += [('name', '=', item.route_id.name)]
domain += [('name', '=', special.route_id.name)]
workorder = self.env['mrp.workorder'].search(domain)
if workorder:
if workorder.state != 'cancel':
workorder.write({'state': 'cancel'})
workorder.picking_ids.write({'state': 'cancel'})
# workorder.picking_ids.
purchase_order = self.env['purchase.order'].search(
[('origin', '=', workorder.production_id.origin)])
for line in purchase.order_line:
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:
workorder = self.env['mrp.workorder'].search([('name', '=', item.route_id.name)])
workorder = self.env['mrp.workorder'].search([('name', '=', special.route_id.display_name)])
if not workorder:
if item.route_id.routing_type == '表面工艺':
if special.route_id.routing_type == '表面工艺':
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', item.process_parameters_id.id)])
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
workorders_values.append(
self.env[
'mrp.workorder']._json_workorder_surface_process_str(self, item,
'mrp.workorder']._json_workorder_surface_process_str(special.production_id, special,
product_production_process.seller_ids[
0].partner_id.id))
if item.process_parameters_id.gain_way == '外协':
product_id_to_production_names = {}
# grouped_product_ids = {k: list(g) for k, g in
# groupby(self, key=lambda x: x.product_id.id)}
product_id_to_production_names[self.product_id] = [production.name for production in self]
self.env['purchase.order'].get_purchase_order(item.process_parameters_id,
self,
product_id_to_production_names)
if special.process_parameters_id.gain_way == '外协':
special.production_id.get_subcontract_purchase()
else:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(self, item))
if workorders_values:
self.write({'workorder_ids': workorders_values})
self._reset_work_order_sequence()
self.env['mrp.workorder'].json_workorder_str(special.production_id, special))
if workorders_values:
productions.write({'workorder_ids': workorders_values})
productions.get_subcontract_pick()
productions._reset_work_order_sequence()
for item in productions:
workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
key=lambda a: a.sequence)
workorder[0].state = 'waiting'

View File

@@ -1,10 +1,7 @@
# -*- 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 itertools import groupby
from odoo import models, api, fields, _
@@ -22,4 +19,13 @@ class ProductionTechnologyWizard(models.TransientModel):
else:
domain = [('id', '=', self.production_id.id)]
productions = self.env['mrp.production'].search(domain)
productions._create_workorder(self.production_id)
for production in productions:
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)
workorder[0].state = 'waiting'