外协工艺合并采购单处理

This commit is contained in:
liaodanlong
2025-01-08 09:36:38 +08:00
parent ad02cbf8cb
commit 5774f241a0
2 changed files with 39 additions and 25 deletions

View File

@@ -287,18 +287,15 @@ class ResMrpWorkOrder(models.Model):
# if technology_design.is_auto is False: # if technology_design.is_auto is False:
# domain = [('origin', '=', order.production_id.name)] # domain = [('origin', '=', order.production_id.name)]
# else: # else:
domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name), domain = [('purchase_type', '=', 'consignment'), ('origin', 'like', '%' + self.production_id.name + '%'),
('state', '!=', 'cancel')] ('state', '!=', 'cancel')]
purchase = self.env['purchase.order'].search(domain) purchase = self.env['purchase.order'].search(domain)
purchase_num = 0 purchase_num = 0
if not purchase: if not purchase:
order.surface_technics_purchase_count = 0 order.surface_technics_purchase_count = 0
for po in purchase: for po in purchase:
for line in po.order_line: if all(line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id for line in po.order_line):
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id: order.surface_technics_purchase_count = 1
if line.product_qty == 1:
purchase_num += 1
order.surface_technics_purchase_count = purchase_num
else: else:
order.surface_technics_purchase_count = 0 order.surface_technics_purchase_count = 0
@@ -1062,6 +1059,13 @@ class ResMrpWorkOrder(models.Model):
purchase_orders_id = self._get_surface_technics_purchase_ids() purchase_orders_id = self._get_surface_technics_purchase_ids()
if purchase_orders_id.state == 'purchase': if purchase_orders_id.state == 'purchase':
workorder.state = 'ready' workorder.state = 'ready'
move_out = workorder.move_subcontract_workorder_ids[1]
for mo in move_out:
if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False})
if not mo.move_line_ids:
self.env['stock.move.line'].create(
mo.get_move_line(workorder.production_id, workorder))
continue continue
else: else:
workorder.state = 'waiting' workorder.state = 'waiting'
@@ -1091,12 +1095,22 @@ class ResMrpWorkOrder(models.Model):
if workorder.is_subcontract is False: if workorder.is_subcontract is False:
workorder.state = 'ready' workorder.state = 'ready'
else: else:
if len(workorder.production_id.picking_ids.filtered(
lambda w: w.state not in ['done',
'cancel'])) == 0 and workorder.production_id.programming_state == '已编程':
purchase_orders_id = self._get_surface_technics_purchase_ids() purchase_orders_id = self._get_surface_technics_purchase_ids()
if purchase_orders_id: if purchase_orders_id:
workorder.state = 'ready' if purchase_orders_id.state == 'purchase' else 'waiting' if purchase_orders_id.state == 'purchase':
workorder.state = 'ready'
move_out = workorder.move_subcontract_workorder_ids[1]
for mo in move_out:
if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False})
if not mo.move_line_ids:
self.env['stock.move.line'].create(
mo.get_move_line(workorder.production_id, workorder))
else: else:
workorder.state = 'waiting' workorder.state = 'waiting'
# 重写工单开始按钮方法 # 重写工单开始按钮方法
def button_start(self): def button_start(self):
# 判断工单状态是否为等待组件 # 判断工单状态是否为等待组件

View File

@@ -44,18 +44,18 @@ class PurchaseOrder(models.Model):
production_id = self.env['mrp.production'].search([('origin', 'in', origins)]) production_id = self.env['mrp.production'].search([('origin', 'in', origins)])
purchase.production_count = len(production_id) purchase.production_count = len(production_id)
def button_confirm(self): # def button_confirm(self):
super().button_confirm() # super().button_confirm()
workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')]) # workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')])
for workorder in workorders: # for workorder in workorders:
if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: # if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True:
move_out = workorder.move_subcontract_workorder_ids[1] # move_out = workorder.move_subcontract_workorder_ids[1]
for mo in move_out: # for mo in move_out:
if mo.state != 'done': # if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False}) # mo.write({'state': 'assigned', 'production_id': False})
if not mo.move_line_ids: # if not mo.move_line_ids:
self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder)) # self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder))
return True # return True
origin_sale_id = fields.Many2one('sale.order', string='销售订单号', store=True, compute='_compute_origin_sale_id') origin_sale_id = fields.Many2one('sale.order', string='销售订单号', store=True, compute='_compute_origin_sale_id')
origin_sale_ids = fields.Many2many('sale.order', string='销售订单号(多个)', store=True, origin_sale_ids = fields.Many2many('sale.order', string='销售订单号(多个)', store=True,