diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index a3e0da75..caf0c5db 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -287,18 +287,15 @@ class ResMrpWorkOrder(models.Model): # if technology_design.is_auto is False: # domain = [('origin', '=', order.production_id.name)] # else: - domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name), + domain = [('purchase_type', '=', 'consignment'), ('origin', 'like', '%' + self.production_id.name + '%'), ('state', '!=', 'cancel')] purchase = self.env['purchase.order'].search(domain) purchase_num = 0 if not purchase: order.surface_technics_purchase_count = 0 for po in purchase: - for line in po.order_line: - if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id: - if line.product_qty == 1: - purchase_num += 1 - order.surface_technics_purchase_count = purchase_num + if all(line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id for line in po.order_line): + order.surface_technics_purchase_count = 1 else: order.surface_technics_purchase_count = 0 @@ -1062,13 +1059,20 @@ class ResMrpWorkOrder(models.Model): purchase_orders_id = self._get_surface_technics_purchase_ids() 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)) continue else: workorder.state = 'waiting' continue else: workorder.state = 'ready' - continue + continue # ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]========================== if (workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework' or workorder.production_id.schedule_state != '已排' @@ -1091,12 +1095,22 @@ class ResMrpWorkOrder(models.Model): if workorder.is_subcontract is False: workorder.state = 'ready' else: - purchase_orders_id = self._get_surface_technics_purchase_ids() - if purchase_orders_id: - workorder.state = 'ready' if purchase_orders_id.state == 'purchase' else 'waiting' - else: - workorder.state = 'waiting' - + 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() + if purchase_orders_id: + 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: + workorder.state = 'waiting' # 重写工单开始按钮方法 def button_start(self): # 判断工单状态是否为等待组件 diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index 2813883e..e13129d5 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -44,18 +44,18 @@ class PurchaseOrder(models.Model): production_id = self.env['mrp.production'].search([('origin', 'in', origins)]) purchase.production_count = len(production_id) - def button_confirm(self): - super().button_confirm() - workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')]) - for workorder in workorders: - if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: - 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)) - return True + # def button_confirm(self): + # super().button_confirm() + # workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')]) + # for workorder in workorders: + # if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: + # 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)) + # return True 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,