优化工单

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

@@ -259,7 +259,8 @@ class MrpProduction(models.Model):
# 退回调整
def technology_back_adjust(self):
domain = [('state', '=', 'confirmed')]
process_parameters = []
domain = [('state', '=', 'confirmed'), ('origin', '=', self.origin)]
if self.production_type == '自动化产线加工':
cloud_programming = self._cron_get_programming_state()
if cloud_programming['send_state'] == 'sending':
@@ -267,6 +268,15 @@ class MrpProduction(models.Model):
domain += [('programming_no', '=', self.programming_no)]
# 带排程的制造订单
production_confirmed = self.env['mrp.production'].search(domain)
for special in production_confirmed.technology_design_ids:
if special.process_parameters_id:
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
if not product_production_process:
if special.process_parameters_id not in process_parameters:
process_parameters.append(special.process_parameters_id.display_name)
if process_parameters:
raise UserError(_("【工艺设计】-【参数】为%s的在【产品】中不存在,请先创建", ", ".join(process_parameters)))
if production_confirmed:
return {
'name': _('退回调整'),
@@ -284,20 +294,19 @@ class MrpProduction(models.Model):
process_parameters = []
account_moves = []
special_design = self.technology_design_ids.filtered(
lambda a: a.routing_tag == 'special' and a.active in [True, False] and special.is_auto is False)
lambda a: a.routing_tag == 'special' and a.is_auto is False)
for special in special_design:
if special.process_parameters_id and special.active is True:
if special.process_parameters_id:
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
if not product_production_process:
if special.process_parameters_id not in process_parameters:
process_parameters.append(special.process_parameters_id.display_name)
if special.active is False:
purchase = self.env['purchase.order'].search([('origin', '=', special.production_id.name)])
account = self.env['account.move'].search([('id', 'in', purchase.invoice_ids)])
if account.state != 'cancel':
if purchase.name not in account_moves:
account_moves.append(purchase.name)
purchase = self.env['purchase.order'].search([('origin', '=', special.production_id.name)])
account = self.env['account.move'].search([('id', 'in', purchase.invoice_ids)])
if account.state not in ['cancel', False]:
if purchase.name not in account_moves:
account_moves.append(purchase.name)
if account_moves:
raise UserError(_("请联系工厂生产经理对采购订单为%s生成的账单进行取消", ", ".join(account_moves)))
if process_parameters:
@@ -312,8 +321,8 @@ class MrpProduction(models.Model):
next_index = index + 1
next_design = technology_design[next_index]
next_design_routing_type = next_design.route_id.routing_type
logging.info('当前工序和加工面: %s-%s' % (design.route_id.name, design.panel))
logging.info('下一个工序和加工面: %s-%s' % (next_design.route_id.name, next_design.panel))
# logging.info('当前工序和加工面: %s-%s' % (design.route_id.name, design.panel))
# logging.info('下一个工序和加工面: %s-%s' % (next_design.route_id.name, next_design.panel))
if design.panel is not False:
if design.panel != next_design.panel:
if index == 0:
@@ -580,19 +589,13 @@ class MrpProduction(models.Model):
}]
if production.product_id.categ_id.type == '成品':
# # 根据工序设计生成工单
for route in item.technology_design_ids:
for route in production.technology_design_ids:
if route.route_id.routing_type not in ['表面工艺']:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(production, route))
else:
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', route.process_parameters_id.id)])
# if product_production_process:
# route_production_process = self.env[
# 'mrp.routing.workcenter'].search(
# [('surface_technics_id', '=', p.id),
# ('id', 'in', route_workcenter_arr)])
# if route_production_process:
workorders_values.append(
self.env[
'mrp.workorder']._json_workorder_surface_process_str(
@@ -606,6 +609,27 @@ 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:
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]
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:
process_parameter_workorder = self.env['mrp.workorder'].search(
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id),
('is_subcontract', '=', True)])
@@ -651,8 +675,6 @@ class MrpProduction(models.Model):
self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production)
else:
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected()
# 工单排序
def _reset_work_order_sequence1(self, k):