Compare commits

...

7 Commits

Author SHA1 Message Date
guanhuan
4225a8fe1b 采购申请单完成操作提示调整 2025-06-10 10:45:06 +08:00
guanhuan
a828c823dd 采购申请单完成操作修改 2025-06-09 17:55:34 +08:00
guanhuan
9cf2bac9c6 修复返工问题 2025-06-09 17:39:55 +08:00
guanhuan
38109028d4 采购申请关闭修改 2025-05-23 15:13:01 +08:00
guanhuan
cf16a9dd59 采购申请关闭修改 2025-05-23 14:53:34 +08:00
guanhuan
1b0dd96b40 采购申请关闭修改 2025-05-23 14:20:48 +08:00
guanhuan
2c52372b0a 采购申请隐藏处理中按钮 2025-05-22 11:44:14 +08:00
3 changed files with 53 additions and 37 deletions

View File

@@ -2,6 +2,7 @@ import re
import ast import ast
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from itertools import groupby from itertools import groupby
from odoo.tools import float_compare
class PurchaseRequest(models.Model): class PurchaseRequest(models.Model):
@@ -36,11 +37,14 @@ class PurchaseRequest(models.Model):
lines = self.mapped("line_ids.purchase_lines.order_id") lines = self.mapped("line_ids.purchase_lines.order_id")
# 采购单产品和数量 # 采购单产品和数量
product_summary = {} product_summary = {}
product_rounding = {}
if lines: if lines:
for line in lines: for line in lines:
for line_item in line.order_line: for line_item in line.order_line:
if line_item.state == 'purchase':
product_id = line_item.product_id.id product_id = line_item.product_id.id
qty = line_item.product_qty qty = line_item.product_qty
product_rounding[product_id] = line_item.product_id.uom_id.rounding
if product_id in product_summary: if product_id in product_summary:
product_summary[product_id] += qty product_summary[product_id] += qty
else: else:
@@ -50,17 +54,17 @@ class PurchaseRequest(models.Model):
discrepancies = [] discrepancies = []
for product_id, qty in product_qty_map.items(): for product_id, qty in product_qty_map.items():
if product_id in product_summary: if product_id in product_summary:
if product_summary[product_id] != qty: if float_compare(product_summary[product_id], qty, precision_rounding=product_rounding[product_id]) < 0:
discrepancies.append((product_id, qty, product_summary[product_id])) discrepancies.append((product_id, qty, product_summary[product_id]))
else: else:
discrepancies.append((product_id, qty, 0)) discrepancies.append((product_id, qty, 0))
if discrepancies: if discrepancies:
# 弹出提示框 # 弹出提示框
message = "产品数量不一致:\n" message = "产品与采购数量不一致:\n"
for product_id, required_qty, order_qty in discrepancies: for product_id, required_qty, order_qty in discrepancies:
product_name = self.env['product.product'].browse(product_id).display_name # 获取产品名称 product_name = self.env['product.product'].browse(product_id).display_name # 获取产品名称
message += f"产品 {product_name},需求数量 {required_qty},关联采购订单数量 {order_qty}(含询价状态)\n" message += f"产品 {product_name},需求数量 {required_qty},关联采购订单确认的数量 {order_qty}\n"
# 添加确认框 # 添加确认框
message += "确认关闭?" message += "确认关闭?"
return { return {
@@ -96,7 +100,8 @@ class PurchaseRequestLine(models.Model):
('outsourcing', "委外加工"), ('outsourcing', "委外加工"),
], string='供货方式', compute='_compute_supply_method', store=True) ], string='供货方式', compute='_compute_supply_method', store=True)
purchase_request_count = fields.Integer(string='采购申请数量', compute='_compute_purchase_request_count', readonly=True) purchase_request_count = fields.Integer(string='采购申请数量', compute='_compute_purchase_request_count',
readonly=True)
purchase_count = fields.Integer(string="采购订单数量", compute="_compute_purchase_count", readonly=True) purchase_count = fields.Integer(string="采购订单数量", compute="_compute_purchase_count", readonly=True)
@api.depends("purchase_lines") @api.depends("purchase_lines")

View File

@@ -17,6 +17,9 @@
</xpath> </xpath>
<xpath expr="//button[@name='button_done']" position="attributes"> <xpath expr="//button[@name='button_done']" position="attributes">
<attribute name="class"/> <attribute name="class"/>
</xpath>
<xpath expr="//button[@name='button_in_progress']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath> </xpath>
<xpath expr="//button[@name='button_in_progress']/following-sibling::button[1]" position="attributes"> <xpath expr="//button[@name='button_in_progress']/following-sibling::button[1]" position="attributes">
<attribute name="class">oe_highlight</attribute> <attribute name="class">oe_highlight</attribute>

View File

@@ -227,6 +227,14 @@ class ResMrpWorkOrder(models.Model):
# finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0 # finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0
else: else:
next_workorder = sorted_workorders[position + 1] next_workorder = sorted_workorders[position + 1]
# 持续获取下一个工单,直到找到一个不是返工的工单
while next_workorder and next_workorder.state == 'rework':
position += 1
if position + 1 < len(sorted_workorders):
next_workorder = sorted_workorders[position + 1]
else:
next_workorder = None
if next_workorder:
next_state = next_workorder.state next_state = next_workorder.state
if next_state not in ['pending', 'waiting', 'ready']: if next_state not in ['pending', 'waiting', 'ready']:
raise UserError('下工序已经开始,无法回退') raise UserError('下工序已经开始,无法回退')