优化制造订单

This commit is contained in:
jinling.yang
2024-11-15 17:31:28 +08:00
parent 018d51e25f
commit 8add4b5ad1
6 changed files with 177 additions and 180 deletions

View File

@@ -609,35 +609,41 @@ class MrpProduction(models.Model):
workorders_values.append( workorders_values.append(
self.env['mrp.workorder'].json_workorder_str('', production, route_embryo)) self.env['mrp.workorder'].json_workorder_str('', production, route_embryo))
production.workorder_ids = workorders_values production.workorder_ids = workorders_values
production.get_subcontract_pick()
for workorder in production.workorder_ids: for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected() workorder.duration_expected = workorder._get_duration_expected()
# 生成采购单 # 生成采购单
def get_subcontract_purchase(self): def get_subcontract_purchase(self):
for production in self: production_all = self.sorted(lambda x: x.id)
for production in production_all:
for special in production.technology_design_ids: for special in production.technology_design_ids:
if special.process_parameters_id.gain_way == '外协': if special.process_parameters_id.gain_way == '外协':
product_id_to_production_names = {} product_id_to_production_names = {}
grouped_product_ids = {k: list(g) for k, g in grouped_product_ids = {k: list(g) for k, g in
groupby(special.production_id, key=lambda x: x.product_id.id)} groupby(production_all, key=lambda x: x.product_id.id)}
for product_id, production in grouped_product_ids.items(): for product_id, pd in grouped_product_ids.items():
product_id_to_production_names[product_id] = [p.name for p in production] product_id_to_production_names[product_id] = [p.name for p in pd]
self.env['purchase.order'].get_purchase_order(special.process_parameters_id, self.env['purchase.order'].get_purchase_order(special.process_parameters_id,
special.production_id, special.production_id,
product_id_to_production_names) product_id_to_production_names)
# 外协出入库单处理 # 外协出入库单处理
def get_subcontract_pick(self): def get_subcontract_pick_purchase(self):
for production in self: production_all = self.sorted(lambda x: x.id)
product_id_to_production_names = {}
grouped_product_ids = {k: list(g) for k, g in
groupby(production_all, key=lambda x: x.product_id.id)}
for product_id, pd in grouped_product_ids.items():
product_id_to_production_names[product_id] = [p.name for p in pd]
for production in production_all:
process_parameter_workorder = self.env['mrp.workorder'].search( process_parameter_workorder = self.env['mrp.workorder'].search(
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id), [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id),
('is_subcontract', '=', True)]) ('is_subcontract', '=', True)], order='sequence asc')
if process_parameter_workorder: if process_parameter_workorder:
is_pick = False is_pick = False
consecutive_workorders = [] consecutive_workorders = []
m = 0 m = 0
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id) sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.sequence)
for i in range(len(sorted_workorders) - 1): for i in range(len(sorted_workorders) - 1):
if m == 0: if m == 0:
is_pick = False is_pick = False
@@ -653,6 +659,9 @@ class MrpProduction(models.Model):
if m == len(consecutive_workorders) - 1 and m != 0: if m == len(consecutive_workorders) - 1 and m != 0:
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
production) production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
if sorted_workorders[i] in consecutive_workorders: if sorted_workorders[i] in consecutive_workorders:
is_pick = True is_pick = True
consecutive_workorders = [] consecutive_workorders = []
@@ -661,20 +670,35 @@ class MrpProduction(models.Model):
if is_pick is False: if is_pick is False:
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
production) production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
if m == len(consecutive_workorders) - 1 and m != 0: if m == len(consecutive_workorders) - 1 and m != 0:
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
production) production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
if sorted_workorders[i] in consecutive_workorders: if sorted_workorders[i] in consecutive_workorders:
is_pick = True is_pick = True
consecutive_workorders = [] consecutive_workorders = []
m = 0 m = 0
if m == len(consecutive_workorders) - 1 and m != 0: if m == len(consecutive_workorders) - 1 and m != 0:
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
if is_pick is False and m == 0: if is_pick is False and m == 0:
if len(sorted_workorders) == 1: if len(sorted_workorders) == 1:
self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production) self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
else: else:
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production) self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production,
product_id_to_production_names)
# 工单排序 # 工单排序
def _reset_work_order_sequence1(self, k): def _reset_work_order_sequence1(self, k):

View File

@@ -182,10 +182,13 @@ class ResMrpWorkOrder(models.Model):
def _compute_surface_technics_purchase_ids(self): def _compute_surface_technics_purchase_ids(self):
for order in self: for order in self:
if order.routing_type == '表面工艺': if order.routing_type == '表面工艺':
production_programming = self.env['mrp.production'].search( if order.production_id.production_type == '自动化产线加工':
[('origin', '=', order.production_id.origin)], order='name asc') domain = [('programming_no', '=', order.production_id.programming_no)]
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False) else:
domain = [('origin', '=', order.production_id.origin)]
production_programming = self.env['mrp.production'].search(domain, order='name asc')
production_list = [production.name for production in production_programming] production_list = [production.name for production in production_programming]
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
technology_design = self.env['sf.technology.design'].search( technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', order.surface_technics_parameters_id.id), [('process_parameters_id', '=', order.surface_technics_parameters_id.id),
('production_id', '=', order.production_id.id)]) ('production_id', '=', order.production_id.id)])
@@ -205,8 +208,12 @@ class ResMrpWorkOrder(models.Model):
def action_view_surface_technics_purchase(self): def action_view_surface_technics_purchase(self):
self.ensure_one() self.ensure_one()
production_programming = self.env['mrp.production'].search( if self.routing_type == '表面工艺':
[('origin', '=', self.production_id.origin)], order='name asc') if self.production_id.production_type == '自动化产线加工':
domain = [('programming_no', '=', self.production_id.programming_no)]
else:
domain = [('origin', '=', self.production_id.origin)]
production_programming = self.env['mrp.production'].search(domain, order='name asc')
production_list = [production.name for production in production_programming] production_list = [production.name for production in production_programming]
technology_design = self.env['sf.technology.design'].search( technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', self.surface_technics_parameters_id.id), [('process_parameters_id', '=', self.surface_technics_parameters_id.id),
@@ -702,6 +709,7 @@ class ResMrpWorkOrder(models.Model):
'operation_id': False, 'operation_id': False,
'name': route.route_id.name, 'name': route.route_id.name,
'processing_panel': route.panel, 'processing_panel': route.panel,
'sequence': route.sequence,
'quality_point_ids': route.route_id.quality_point_ids, 'quality_point_ids': route.route_id.quality_point_ids,
'routing_type': route.route_id.routing_type, 'routing_type': route.route_id.routing_type,
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.route_id.workcenter_ids.ids, 'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.route_id.workcenter_ids.ids,
@@ -750,6 +758,7 @@ class ResMrpWorkOrder(models.Model):
'operation_id': False, 'operation_id': False,
'name': route.process_parameters_id.display_name, 'name': route.process_parameters_id.display_name,
'processing_panel': '', 'processing_panel': '',
'sequence': route.sequence,
'routing_type': '表面工艺', 'routing_type': '表面工艺',
'surface_technics_parameters_id': route.process_parameters_id.id, 'surface_technics_parameters_id': route.process_parameters_id.id,
'work_state': '', 'work_state': '',
@@ -932,7 +941,7 @@ class ResMrpWorkOrder(models.Model):
if (workorder.sequence == 1 and not workorder.blocked_by_workorder_ids) or ( if (workorder.sequence == 1 and not workorder.blocked_by_workorder_ids) or (
workorder.blocked_by_workorder_ids.state in ('done', 'cancel')) or ( workorder.blocked_by_workorder_ids.state in ('done', 'cancel')) or (
previous_workorder.state in ( previous_workorder.state in (
'done', 'cancel') and not workorder.blocked_by_workorder_ids): 'done', 'cancel') and not workorder.blocked_by_workorder_ids):
workorder.state = 'ready' workorder.state = 'ready'
continue continue
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'): if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
@@ -1012,7 +1021,7 @@ class ResMrpWorkOrder(models.Model):
'done', 'rework', 'done', 'rework',
'cancel']: 'cancel']:
if workorder.production_id.is_rework is False: if workorder.production_id.is_rework is False:
if re_work or cnc_workorder or unclamp_workorder : if re_work or cnc_workorder or unclamp_workorder:
workorder.state = 'ready' workorder.state = 'ready'
# if (re_work or cnc_workorder) and workorder.production_id.is_rework is False: # if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# workorder.state = 'ready' # workorder.state = 'ready'
@@ -1220,8 +1229,8 @@ class ResMrpWorkOrder(models.Model):
# if record.is_rework is False: # if record.is_rework is False:
# if not record.material_center_point: # if not record.material_center_point:
# raise UserError("坯料中心点为空,请检查") # raise UserError("坯料中心点为空,请检查")
# if record.X_deviation_angle <= 0: # if record.X_deviation_angle <= 0:
# raise UserError("X偏差角度小于等于0请检查本次计算的X偏差角度为%s" % record.X_deviation_angle) # raise UserError("X偏差角度小于等于0请检查本次计算的X偏差角度为%s" % record.X_deviation_angle)
record.process_state = '待加工' record.process_state = '待加工'
# record.write({'process_state': '待加工'}) # record.write({'process_state': '待加工'})
record.production_id.process_state = '待加工' record.production_id.process_state = '待加工'

View File

@@ -299,130 +299,74 @@ class StockRule(models.Model):
('origin', '=', production_item.origin)], ('origin', '=', production_item.origin)],
limit=1, order='id asc') limit=1, order='id asc')
if production_item.product_id.id in product_id_to_production_names: if production_item.product_id.id in product_id_to_production_names:
if production_item.product_id.model_process_parameters_ids: # 同一个产品多个制造订单对应一个编程单和模型库
is_purchase = False # 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, if not production_item.programming_no and production.production_type == '自动化产线加工':
key=lambda w: w.id) if not production_programming.programming_no:
production_item.fetchCNC(
consecutive_process_parameters = [] ', '.join(product_id_to_production_names[production_item.product_id.id]))
m = 0 else:
for i in range(len(sorted_process_parameters) - 1): production_item.write({'programming_no': production_programming.programming_no,
if m == 0: 'programming_state': '编程中'})
is_purchase = False if not technology_design_values:
if self.env['product.template']._get_process_parameters_product( if production_item.product_id.categ_id.type == '成品':
sorted_process_parameters[i]).partner_id == self.env[ production_item.product_id.model_processing_panel = 'ZM,FM'
'product.template']._get_process_parameters_product(sorted_process_parameters[ # 根据加工面板的面数及成品工序模板生成工序设计
i + 1]).partner_id and \ i = 0
sorted_process_parameters[i].gain_way == '外协': for k in (production_item.product_id.model_processing_panel.split(',')):
if sorted_process_parameters[i] not in consecutive_process_parameters: # 新增的成品工序模版暂未添加,后续添加
consecutive_process_parameters.append(sorted_process_parameters[i]) if production_item.production_type == '自动化产线加工':
consecutive_process_parameters.append(sorted_process_parameters[i + 1]) model = 'sf.product.model.type.routing.sort'
m += 1
continue
else: else:
if m == len(consecutive_process_parameters) - 1 and m != 0: model = 'sf.product.model.type.routing.sort'
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, product_routing_workcenter = self.env[model].search(
production_item, [('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)],
product_id_to_production_names)
if sorted_process_parameters[i] in consecutive_process_parameters:
is_purchase = True
consecutive_process_parameters = []
m = 0
# 当前面的连续外协采购单生成再生成当前外协采购单
if is_purchase is False:
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production_item,
product_id_to_production_names)
if m == len(consecutive_process_parameters) - 1 and m != 0:
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production_item,
product_id_to_production_names)
if sorted_process_parameters[i] in consecutive_process_parameters:
is_purchase = True
consecutive_process_parameters = []
m = 0
if m == len(consecutive_process_parameters) - 1 and m != 0:
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
production_item,
product_id_to_production_names)
if is_purchase is False and m == 0:
if len(sorted_process_parameters) == 1:
self.env['purchase.order'].get_purchase_order(sorted_process_parameters,
production_item,
product_id_to_production_names)
else:
self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i],
production_item,
product_id_to_production_names)
if not technology_design_values:
if production.product_id.categ_id.type == '成品':
production.product_id.model_processing_panel = 'ZM,FM'
# 根据加工面板的面数及成品工序模板生成工序设计
i = 0
for k in (production.product_id.model_processing_panel.split(',')):
# 新增的成品工序模版暂未添加,后续添加
if production.production_type == '自动化产线加工':
model = 'sf.product.model.type.routing.sort'
else:
model = 'sf.product.model.type.routing.sort'
product_routing_workcenter = self.env[model].search(
[('product_model_type_id', '=', production.product_id.product_model_type_id.id)],
order='sequence asc'
)
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
elif production.product_id.categ_id.type == '坯料':
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
order='sequence asc' order='sequence asc'
) )
for route_embryo in embryo_routing_workcenter: for route in product_routing_workcenter:
i += 1 i += 1
technology_design_values.append( technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i, self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
False)) elif production.product_id.categ_id.type == '坯料':
surface_technics_arr = [] embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
route_workcenter_arr = [] [('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: order='sequence asc'
if item.route_workcenter_id.surface_technics_id.id: )
for process_param in production.product_id.model_process_parameters_ids: for route_embryo in embryo_routing_workcenter:
if item.route_workcenter_id.surface_technics_id == process_param.process_id: i += 1
surface_technics_arr.append( technology_design_values.append(
item.route_workcenter_id.surface_technics_id.id) self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
route_workcenter_arr.append(item.route_workcenter_id.id) False))
if surface_technics_arr: surface_technics_arr = []
production_process = self.env['sf.production.process'].search( route_workcenter_arr = []
[('id', 'in', surface_technics_arr)], for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
order='sequence asc' if item.route_workcenter_id.surface_technics_id.id:
) for process_param in production_item.product_id.model_process_parameters_ids:
for p in production_process: if item.route_workcenter_id.surface_technics_id == process_param.process_id:
logging.info('production_process:%s' % p.name) surface_technics_arr.append(
process_parameter = production.product_id.model_process_parameters_ids.filtered( item.route_workcenter_id.surface_technics_id.id)
lambda pm: pm.process_id.id == p.id) route_workcenter_arr.append(item.route_workcenter_id.id)
if process_parameter: if surface_technics_arr:
i += 1 production_process = self.env['sf.production.process'].search(
route_production_process = self.env[ [('id', 'in', surface_technics_arr)],
'mrp.routing.workcenter'].search( order='sequence asc'
[('surface_technics_id', '=', p.id), )
('id', 'in', route_workcenter_arr)]) for p in production_process:
technology_design_values.append( logging.info('production_process:%s' % p.name)
self.env['sf.technology.design'].json_technology_design_str(False, process_parameter = production_item.product_id.model_process_parameters_ids.filtered(
route_production_process, lambda pm: pm.process_id.id == p.id)
i, if process_parameter:
process_parameter)) i += 1
route_production_process = self.env[
'mrp.routing.workcenter'].search(
[('surface_technics_id', '=', p.id),
('id', 'in', route_workcenter_arr)])
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False,
route_production_process,
i,
process_parameter))
productions.technology_design_ids = technology_design_values productions.technology_design_ids = technology_design_values
# 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
# if not production_item.programming_no and production.production_type == '自动化产线加工':
# if not production_programming.programming_no:
# production_item.fetchCNC(
# ', '.join(product_id_to_production_names[production_item.product_id.id]))
# else:
# production_item.write({'programming_no': production_programming.programming_no,
# 'programming_state': '编程中'})
return True return True

View File

@@ -347,16 +347,17 @@
<field name="technology_design_ids" widget="one2many"> <field name="technology_design_ids" widget="one2many">
<tree editable="bottom"> <tree editable="bottom">
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="sequence"/> <!-- <field name="sequence"/>-->
<field name="id"/>
<field name="route_id" context="{'production_id': production_id}" <field name="route_id" context="{'production_id': production_id}"
attrs="{'readonly': [('is_auto', '=', True)]}" options="{'no_create': True}"/> attrs="{'readonly': [('id', '!=', False)]}" options="{'no_create': True}"/>
<field name="process_parameters_id" attrs="{'readonly': [('is_auto', '=', True)]}" <field name="process_parameters_id" attrs="{'readonly': [('id', '!=', False)]}"
string="参数" context="{'route_id':route_id}" options="{'no_create': True}"/> string="参数" context="{'route_id':route_id}" options="{'no_create': True}"/>
<field name="panel" readonly="1"/> <field name="panel" readonly="1"/>
<field name="routing_tag" readonly="1" widget="badge" <field name="routing_tag" readonly="1" widget="badge"
decoration-success="routing_tag == 'standard'" decoration-success="routing_tag == 'standard'"
decoration-warning="routing_tag == 'special'"/> decoration-warning="routing_tag == 'special'"/>
<field name="time_cycle_manual" attrs="{'readonly': [('is_auto', '=', True)]}"/> <field name="time_cycle_manual" attrs="{'readonly': [('id', '!=', False)]}"/>
<field name="is_auto" invisible="1"/> <field name="is_auto" invisible="1"/>
<field name="production_id" invisible="1"/> <field name="production_id" invisible="1"/>
<button name="unlink_technology_design" confirm="是否确认删除?" class="oe_highlight" <button name="unlink_technology_design" confirm="是否确认删除?" class="oe_highlight"

View File

@@ -17,43 +17,48 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
domain = [('origin', '=', self.origin), ('state', '=', 'confirmed')] domain = [('origin', '=', self.origin), ('state', '=', 'confirmed')]
else: else:
domain = [('id', '=', self.production_id.id)] domain = [('id', '=', self.production_id.id)]
technology_designs = self.production_id.technology_design_ids technology_designs = self.env['sf.technology.design'].sudo().search(
[('production_id', '=', self.production_id.id), ('active', 'in', [True, False])])
productions = self.env['mrp.production'].search(domain) productions = self.env['mrp.production'].search(domain)
workorders_values = [] for production_item in productions:
for production_my in productions:
# 该制造订单的其他同一销售订单的制造订单的工艺设计处理 # 该制造订单的其他同一销售订单的制造订单的工艺设计处理
if production_my != self.production_id: if production_item != self.production_id:
for td_other in production_my.technology_design_ids: for td_other in production_item.technology_design_ids:
if td_other.is_auto is False:
td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
if not td_del or td_del.active is False:
td_other.write({'active': False})
for td_main in technology_designs: for td_main in technology_designs:
route_other = production_my.technology_design_ids.filtered( route_other = production_item.technology_design_ids.filtered(
lambda td: td.route_id.id == td_main.route_id.id) lambda td: td.route_id.id == td_main.route_id.id)
if not route_other: if not route_other and td_main.active is True:
production_my.write({'technology_design_ids': [(0, 0, { production_item.write({'technology_design_ids': [(0, 0, {
'route_id': td_main.route_id.id, 'route_id': td_main.route_id.id,
'process_parameters_id': False if td_main.process_parameters_id is False else 'process_parameters_id': False if td_main.process_parameters_id is False else
self.env[ self.env[
'sf.production.process.parameter'].search( 'sf.production.process.parameter'].search(
[('id', '=', td_main.process_parameters_id.id)]).id, [('id', '=', td_main.process_parameters_id.id)]).id,
'sequence': td_main.sequence})]}) 'sequence': td_main.sequence,
'is_auto': td_main.is_auto})]})
else: else:
if td_main.route_id == td_other.route_id: for ro in route_other:
if td_main.route_id.routing_type == '表面工艺': domain = [('production_id', '=', self.production_id.id), ('active', 'in', [True, False]),
display_name = td_main.process_parameters_id.display_name ('route_id', '=', ro.route_id.id)]
else: if ro.route_id.routing_type == '表面工艺':
display_name = td_main.route_id.display_name domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
if (td_main.panel is not False and td_main.panel == td_other.panel) or ( elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
display_name == td_other.display_name): display_name = ro.route_id.display_name
if td_main.sequence != td_other.sequence: domain += [('name', 'ilike', display_name)]
td_other.write({'sequence': td_main.sequence}) elif ro.panel is not False:
logging.info(td_main.route_id.name) domain += [('panel', '=', ro.panel)]
logging.info(td_main.sequence) td_upd = self.env['sf.technology.design'].sudo().search(domain)
logging.info(td_other.route_id.name) if td_upd:
logging.info(td_other.sequence) ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
special_design = self.env['sf.technology.design'].sudo().search( special_design = self.env['sf.technology.design'].sudo().search(
[('routing_tag', '=', 'special'), ('production_id', '=', production_my.id), [('routing_tag', '=', 'special'), ('production_id', '=', production_item.id),
('is_auto', '=', False), ('active', 'in', [True, False])]) ('is_auto', '=', False), ('active', 'in', [True, False])])
for special in special_design: for special in special_design:
workorders_values = []
if special.active is False: if special.active is False:
# 工单采购单外协出入库单皆需取消 # 工单采购单外协出入库单皆需取消
domain = [('production_id', '=', special.production_id.id)] domain = [('production_id', '=', special.production_id.id)]
@@ -65,7 +70,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if workorder.state != 'cancel': if workorder.state != 'cancel':
workorder.write({'state': 'cancel'}) workorder.write({'state': 'cancel'})
workorder.picking_ids.write({'state': 'cancel'}) workorder.picking_ids.write({'state': 'cancel'})
# workorder.picking_ids. workorder.picking_ids.move_ids.write({'state': 'cancel'})
purchase_order = self.env['purchase.order'].search( purchase_order = self.env['purchase.order'].search(
[('origin', '=', workorder.production_id.origin)]) [('origin', '=', workorder.production_id.origin)])
for line in purchase_order.order_line: for line in purchase_order.order_line:
@@ -87,22 +92,20 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
'mrp.workorder']._json_workorder_surface_process_str(special.production_id, special, 'mrp.workorder']._json_workorder_surface_process_str(special.production_id, special,
product_production_process.seller_ids[ product_production_process.seller_ids[
0].partner_id.id)) 0].partner_id.id))
if special.process_parameters_id.gain_way == '外协':
special.production_id.get_subcontract_purchase()
else: else:
workorders_values.append( workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(special.production_id, special)) self.env['mrp.workorder'].json_workorder_str(special.production_id, special))
special.production_id.write({'workorder_ids': workorders_values}) special.production_id.write({'workorder_ids': workorders_values})
special.production_id.get_subcontract_pick() special.production_id.get_subcontract_pick()
special.production_id._reset_work_order_sequence()
workorders_values = []
else: else:
if len(workorder.blocked_by_workorder_ids) > 1: if len(workorder.blocked_by_workorder_ids) > 1:
if workorder.sequence == 1: if workorder.sequence == 1:
workorder.blocked_by_workorder_ids = None workorder.blocked_by_workorder_ids = None
else: else:
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0] workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
special.production_id._reset_work_order_sequence()
special.production_id.get_subcontract_pick_purchase()
for item in productions: for item in productions:
workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
key=lambda a: a.sequence) key=lambda a: a.sequence)
workorder[0].state = 'waiting' workorders[0].state = 'waiting'

View File

@@ -23,10 +23,14 @@ class ProductionTechnologyWizard(models.TransientModel):
for production in productions: for production in productions:
if production != self.production_id: if production != self.production_id:
for td_other in production.technology_design_ids: for td_other in production.technology_design_ids:
if td_other.is_auto is False:
td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
if not td_del or td_del.active is False:
td_other.write({'active': False})
for td_main in technology_designs: for td_main in technology_designs:
route_other = production.technology_design_ids.filtered( route_other = production.technology_design_ids.filtered(
lambda td: td.route_id.id == td_main.route_id.id) lambda td: td.route_id.id == td_main.route_id.id)
if not route_other: if not route_other and td_main.active is True:
production.write({'technology_design_ids': [(0, 0, { production.write({'technology_design_ids': [(0, 0, {
'route_id': td_main.route_id.id, 'route_id': td_main.route_id.id,
'process_parameters_id': False if td_main.process_parameters_id is False else self.env[ 'process_parameters_id': False if td_main.process_parameters_id is False else self.env[
@@ -34,13 +38,25 @@ class ProductionTechnologyWizard(models.TransientModel):
[('id', '=', td_main.process_parameters_id.id)]).id, [('id', '=', td_main.process_parameters_id.id)]).id,
'sequence': td_main.sequence})]}) 'sequence': td_main.sequence})]})
else: else:
if td_main.sequence != td_other.sequence: for ro in route_other:
td_other.sequence = td_main.sequence domain = [('production_id', '=', self.production_id.id),
special = production.technology_design_ids.filtered( ('active', 'in', [True, False]),
lambda td: td.is_auto is False and td.process_parameters_id is not False) ('route_id', '=', ro.route_id.id)]
if special: if ro.route_id.routing_type == '表面工艺':
production.get_subcontract_purchase() domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
display_name = ro.route_id.display_name
domain += [('name', 'ilike', display_name)]
elif ro.panel is not False:
domain += [('panel', '=', ro.panel)]
td_upd = self.env['sf.technology.design'].sudo().search(domain)
if td_upd:
ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
# special = production.technology_design_ids.filtered(
# lambda td: td.is_auto is False and td.process_parameters_id is not False)
# # if special:
productions._create_workorder(False) productions._create_workorder(False)
productions.get_subcontract_pick_purchase()
for item in productions: for item in productions:
workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
key=lambda a: a.sequence) key=lambda a: a.sequence)