diff --git a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py index fe90f66a..3c63bedb 100644 --- a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py +++ b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py @@ -2,6 +2,7 @@ import logging from itertools import groupby from odoo import models, api, fields, _ +from odoo.exceptions import UserError class ProductionTechnologyReAdjustWizard(models.TransientModel): @@ -76,4 +77,11 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): if workorders[ 0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': workorders[0].state = 'waiting' - + pr_ids = self.env['purchase.request'].sudo().search( + [('origin', 'like', item.name), ('is_subcontract', '=', 'True'), ('state', '!=', 'rejected')]) + if not pr_ids: + continue + if not all(pr.state == 'draft' for pr in pr_ids): + # 如果发现有记录的 state 不是 'draft',抛出异常 + raise UserError("有采购申请的状态不是 '草稿'") + pr_ids.state = 'rejected' \ No newline at end of file