工艺确认后的错误提示

This commit is contained in:
liaodanlong
2025-01-13 16:46:13 +08:00
parent a8271d851d
commit b398d1236e
2 changed files with 16 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
from collections import defaultdict
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import OrderedSet
@@ -16,6 +17,20 @@ class PurchaseOrder(models.Model):
compute='_compute_workorder_count',
)
def button_cancel(self):
account_moves = set() # 使用集合以避免重复,并提高查找速度
accounts = self.env['account.move'].search(
[('id', 'in', self.invoice_ids.ids), ('state', 'not in', ['cancel', False])])
# 直接筛选掉状态为'cancel'或False的记录避免多次迭代
for account in accounts:
account_moves.add(account.name) # 使用set的add方法避免重复添加
# 如果你需要list形式的结果可以将set转换为list
account_moves = list(account_moves)
if account_moves:
raise UserError(_("请联系工厂生产经理对该采购单的账单进行取消"))
return super(PurchaseOrder, self).button_cancel()
def action_view_production(self):
origins = [order.name for order in self.picking_ids]
production_id = self.env['mrp.production'].search([('origin', 'in', origins)])