优化制造订单

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(
self.env['mrp.workorder'].json_workorder_str('', production, route_embryo))
production.workorder_ids = workorders_values
production.get_subcontract_pick()
for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected()
# 生成采购单
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:
if special.process_parameters_id.gain_way == '外协':
product_id_to_production_names = {}
grouped_product_ids = {k: list(g) for k, g in
groupby(special.production_id, key=lambda x: x.product_id.id)}
for product_id, production in grouped_product_ids.items():
product_id_to_production_names[product_id] = [p.name for p in production]
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]
self.env['purchase.order'].get_purchase_order(special.process_parameters_id,
special.production_id,
product_id_to_production_names)
# 外协出入库单处理
def get_subcontract_pick(self):
for production in self:
def get_subcontract_pick_purchase(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(
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id),
('is_subcontract', '=', True)])
('is_subcontract', '=', True)], order='sequence asc')
if process_parameter_workorder:
is_pick = False
consecutive_workorders = []
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):
if m == 0:
is_pick = False
@@ -653,6 +659,9 @@ class MrpProduction(models.Model):
if m == len(consecutive_workorders) - 1 and m != 0:
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 sorted_workorders[i] in consecutive_workorders:
is_pick = True
consecutive_workorders = []
@@ -661,20 +670,35 @@ class MrpProduction(models.Model):
if is_pick is False:
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)
if m == len(consecutive_workorders) - 1 and m != 0:
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 sorted_workorders[i] in consecutive_workorders:
is_pick = True
consecutive_workorders = []
m = 0
if m == len(consecutive_workorders) - 1 and m != 0:
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 len(sorted_workorders) == 1:
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:
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):

View File

@@ -182,10 +182,13 @@ class ResMrpWorkOrder(models.Model):
def _compute_surface_technics_purchase_ids(self):
for order in self:
if order.routing_type == '表面工艺':
production_programming = self.env['mrp.production'].search(
[('origin', '=', order.production_id.origin)], order='name asc')
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
if order.production_id.production_type == '自动化产线加工':
domain = [('programming_no', '=', order.production_id.programming_no)]
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_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', order.surface_technics_parameters_id.id),
('production_id', '=', order.production_id.id)])
@@ -205,8 +208,12 @@ class ResMrpWorkOrder(models.Model):
def action_view_surface_technics_purchase(self):
self.ensure_one()
production_programming = self.env['mrp.production'].search(
[('origin', '=', self.production_id.origin)], order='name asc')
if self.routing_type == '表面工艺':
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]
technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', self.surface_technics_parameters_id.id),
@@ -702,6 +709,7 @@ class ResMrpWorkOrder(models.Model):
'operation_id': False,
'name': route.route_id.name,
'processing_panel': route.panel,
'sequence': route.sequence,
'quality_point_ids': route.route_id.quality_point_ids,
'routing_type': route.route_id.routing_type,
'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,
'name': route.process_parameters_id.display_name,
'processing_panel': '',
'sequence': route.sequence,
'routing_type': '表面工艺',
'surface_technics_parameters_id': route.process_parameters_id.id,
'work_state': '',

View File

@@ -299,74 +299,28 @@ class StockRule(models.Model):
('origin', '=', production_item.origin)],
limit=1, order='id asc')
if production_item.product_id.id in product_id_to_production_names:
if production_item.product_id.model_process_parameters_ids:
is_purchase = False
sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids,
key=lambda w: w.id)
consecutive_process_parameters = []
m = 0
for i in range(len(sorted_process_parameters) - 1):
if m == 0:
is_purchase = False
if self.env['product.template']._get_process_parameters_product(
sorted_process_parameters[i]).partner_id == self.env[
'product.template']._get_process_parameters_product(sorted_process_parameters[
i + 1]).partner_id and \
sorted_process_parameters[i].gain_way == '外协':
if sorted_process_parameters[i] not in consecutive_process_parameters:
consecutive_process_parameters.append(sorted_process_parameters[i])
consecutive_process_parameters.append(sorted_process_parameters[i + 1])
m += 1
continue
# 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次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:
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 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)
production_item.write({'programming_no': production_programming.programming_no,
'programming_state': '编程中'})
if not technology_design_values:
if production.product_id.categ_id.type == '成品':
production.product_id.model_processing_panel = 'ZM,FM'
if production_item.product_id.categ_id.type == '成品':
production_item.product_id.model_processing_panel = 'ZM,FM'
# 根据加工面板的面数及成品工序模板生成工序设计
i = 0
for k in (production.product_id.model_processing_panel.split(',')):
for k in (production_item.product_id.model_processing_panel.split(',')):
# 新增的成品工序模版暂未添加,后续添加
if production.production_type == '自动化产线加工':
if production_item.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)],
[('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)],
order='sequence asc'
)
for route in product_routing_workcenter:
@@ -375,7 +329,7 @@ class StockRule(models.Model):
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)],
[('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
order='sequence asc'
)
for route_embryo in embryo_routing_workcenter:
@@ -385,9 +339,9 @@ class StockRule(models.Model):
False))
surface_technics_arr = []
route_workcenter_arr = []
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
if item.route_workcenter_id.surface_technics_id.id:
for process_param in production.product_id.model_process_parameters_ids:
for process_param in production_item.product_id.model_process_parameters_ids:
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
surface_technics_arr.append(
item.route_workcenter_id.surface_technics_id.id)
@@ -399,7 +353,7 @@ class StockRule(models.Model):
)
for p in production_process:
logging.info('production_process:%s' % p.name)
process_parameter = production.product_id.model_process_parameters_ids.filtered(
process_parameter = production_item.product_id.model_process_parameters_ids.filtered(
lambda pm: pm.process_id.id == p.id)
if process_parameter:
i += 1
@@ -413,16 +367,6 @@ class StockRule(models.Model):
i,
process_parameter))
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

View File

@@ -347,16 +347,17 @@
<field name="technology_design_ids" widget="one2many">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="sequence"/>
<!-- <field name="sequence"/>-->
<field name="id"/>
<field name="route_id" context="{'production_id': production_id}"
attrs="{'readonly': [('is_auto', '=', True)]}" options="{'no_create': True}"/>
<field name="process_parameters_id" attrs="{'readonly': [('is_auto', '=', True)]}"
attrs="{'readonly': [('id', '!=', False)]}" options="{'no_create': True}"/>
<field name="process_parameters_id" attrs="{'readonly': [('id', '!=', False)]}"
string="参数" context="{'route_id':route_id}" options="{'no_create': True}"/>
<field name="panel" readonly="1"/>
<field name="routing_tag" readonly="1" widget="badge"
decoration-success="routing_tag == 'standard'"
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="production_id" invisible="1"/>
<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')]
else:
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)
workorders_values = []
for production_my in productions:
for production_item in productions:
# 该制造订单的其他同一销售订单的制造订单的工艺设计处理
if production_my != self.production_id:
for td_other in production_my.technology_design_ids:
if production_item != self.production_id:
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:
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)
if not route_other:
production_my.write({'technology_design_ids': [(0, 0, {
if not route_other and td_main.active is True:
production_item.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})]})
'sequence': td_main.sequence,
'is_auto': td_main.is_auto})]})
else:
if td_main.route_id == td_other.route_id:
if td_main.route_id.routing_type == '表面工艺':
display_name = td_main.process_parameters_id.display_name
else:
display_name = td_main.route_id.display_name
if (td_main.panel is not False and td_main.panel == td_other.panel) or (
display_name == td_other.display_name):
if td_main.sequence != td_other.sequence:
td_other.write({'sequence': td_main.sequence})
logging.info(td_main.route_id.name)
logging.info(td_main.sequence)
logging.info(td_other.route_id.name)
logging.info(td_other.sequence)
for ro in route_other:
domain = [('production_id', '=', self.production_id.id), ('active', 'in', [True, False]),
('route_id', '=', ro.route_id.id)]
if ro.route_id.routing_type == '表面工艺':
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_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])])
for special in special_design:
workorders_values = []
if special.active is False:
# 工单采购单外协出入库单皆需取消
domain = [('production_id', '=', special.production_id.id)]
@@ -65,7 +70,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if workorder.state != 'cancel':
workorder.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(
[('origin', '=', workorder.production_id.origin)])
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,
product_production_process.seller_ids[
0].partner_id.id))
if special.process_parameters_id.gain_way == '外协':
special.production_id.get_subcontract_purchase()
else:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(special.production_id, special))
special.production_id.write({'workorder_ids': workorders_values})
special.production_id.get_subcontract_pick()
special.production_id._reset_work_order_sequence()
workorders_values = []
else:
if len(workorder.blocked_by_workorder_ids) > 1:
if workorder.sequence == 1:
workorder.blocked_by_workorder_ids = None
else:
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:
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)
workorder[0].state = 'waiting'
workorders[0].state = 'waiting'

View File

@@ -23,10 +23,14 @@ class ProductionTechnologyWizard(models.TransientModel):
for production in productions:
if production != self.production_id:
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:
route_other = production.technology_design_ids.filtered(
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, {
'route_id': td_main.route_id.id,
'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,
'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()
for ro in route_other:
domain = [('production_id', '=', self.production_id.id),
('active', 'in', [True, False]),
('route_id', '=', ro.route_id.id)]
if ro.route_id.routing_type == '表面工艺':
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.get_subcontract_pick_purchase()
for item in productions:
workorder = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
key=lambda a: a.sequence)