BUG_7276_lxb_commit
This commit is contained in:
@@ -615,6 +615,11 @@ class SfProductionDemandPlan(models.Model):
|
||||
# 按产品分组并计算总数
|
||||
product_data = {}
|
||||
for plan in filtered_plan:
|
||||
check_overdelivery_allowed = False
|
||||
if not plan.demand_plan_id.overdelivery_allowed:
|
||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||
if plan.location_id.id == customer_location_id:
|
||||
check_overdelivery_allowed = True
|
||||
if plan.product_id not in product_data:
|
||||
# 初始化产品数据,从产品上获取需求量
|
||||
product_data[plan.product_id] = {
|
||||
@@ -624,17 +629,22 @@ class SfProductionDemandPlan(models.Model):
|
||||
|
||||
# 累加计划数量
|
||||
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
|
||||
product_data[plan.product_id]['overdelivery_allowed'] = check_overdelivery_allowed
|
||||
# 检查需求超过计划数量的产品
|
||||
warning_messages = []
|
||||
error_messages = []
|
||||
for product, data in product_data.items():
|
||||
if float_compare(data['plan_uom_qty'], data['product_uom_qty'],
|
||||
if data['overdelivery_allowed'] and float_compare(data['plan_uom_qty'], data['product_uom_qty'],precision_rounding=product.uom_id.rounding) == 1:
|
||||
error_messages.append(f"您正在下达的产品 {product.display_name},已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||
elif float_compare(data['plan_uom_qty'], data['product_uom_qty'],
|
||||
precision_rounding=product.uom_id.rounding) == 1:
|
||||
warning_messages.append(
|
||||
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
||||
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
||||
)
|
||||
if warning_messages and check_overdelivery_allowed:
|
||||
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||
if error_messages:
|
||||
error_message = "\n".join(error_messages)
|
||||
raise ValidationError(error_message)
|
||||
elif warning_messages:
|
||||
warning_message = "\n".join(warning_messages)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user