From 559c6bfb1d73f40e452547e479efa2006fb55ab8 Mon Sep 17 00:00:00 2001 From: "lixiaobin@jikimo.com" Date: Thu, 10 Jul 2025 14:29:06 +0800 Subject: [PATCH 1/2] 7231_lxb_commit --- sf_demand_plan/models/sf_demand_plan.py | 6 +++++- .../models/sf_production_demand_plan.py | 16 ++++++++++++++-- sf_demand_plan/views/demand_plan_info.xml | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index 63371dfd..5dace536 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -72,6 +72,8 @@ class SfDemandPlan(models.Model): ('4', '低'), ], string='优先级', default='3') + overdelivery_allowed = fields.Boolean('可超量发货', default=False) + hide_button_release_plan = fields.Boolean( string='显示下达计划按钮', compute='_compute_hide_button_release_plan', @@ -194,7 +196,9 @@ class SfDemandPlan(models.Model): def button_production_release_plan(self): line_ids = self.line_ids.filtered(lambda p: p.status == '30') sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty')) - if sum_product_uom_qty > self.product_uom_qty: + if sum_product_uom_qty > self.product_uom_qty and not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.name == '客户'): + raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") + elif sum_product_uom_qty > self.product_uom_qty: return { 'name': _('需求计划'), 'type': 'ir.actions.act_window', diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index a0b5bb92..ab70276e 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -592,6 +592,10 @@ class SfProductionDemandPlan(models.Model): filtered_plan = self.filtered(lambda mo: mo.status == '30') if not filtered_plan: raise UserError(_("没有需要下达的计划!")) + check_overdelivery_allowed = False + if not self.demand_plan_id.overdelivery_allowed: + if self.location_id.name == '客户': + check_overdelivery_allowed = True # 按产品分组并计算总数 product_data = {} for plan in filtered_plan: @@ -612,7 +616,9 @@ class SfProductionDemandPlan(models.Model): _("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") % (product.display_name, data['plan_uom_qty'], data['product_uom_qty']) ) - if warning_messages: + if warning_messages and check_overdelivery_allowed: + raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") + elif warning_messages: warning_message = "\n".join(warning_messages) return { 'name': _('需求计划'), @@ -631,7 +637,13 @@ class SfProductionDemandPlan(models.Model): self.ensure_one() if not self.new_supply_method: raise ValidationError(f"供货方式不能为空!") - if self.plan_uom_qty > self.product_uom_qty: + check_overdelivery_allowed = False + if not self.demand_plan_id.overdelivery_allowed: + if self.location_id.name == '客户': + check_overdelivery_allowed = True + if self.plan_uom_qty > self.product_uom_qty and check_overdelivery_allowed: + raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") + elif self.plan_uom_qty > self.product_uom_qty: return { 'name': _('需求计划'), 'type': 'ir.actions.act_window', diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml index 74d9f213..943fbc80 100644 --- a/sf_demand_plan/views/demand_plan_info.xml +++ b/sf_demand_plan/views/demand_plan_info.xml @@ -35,6 +35,7 @@ + From 7adaa7e79bc46d872209711e3df7ae26508e1eab Mon Sep 17 00:00:00 2001 From: "lixiaobin@jikimo.com" Date: Thu, 10 Jul 2025 16:33:43 +0800 Subject: [PATCH 2/2] 7231_lxb_commit --- sf_demand_plan/models/sf_demand_plan.py | 10 +++++++--- .../models/sf_production_demand_plan.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index 5dace536..f49ab660 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -196,9 +196,13 @@ class SfDemandPlan(models.Model): def button_production_release_plan(self): line_ids = self.line_ids.filtered(lambda p: p.status == '30') sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty')) - if sum_product_uom_qty > self.product_uom_qty and not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.name == '客户'): - raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") - elif sum_product_uom_qty > self.product_uom_qty: + customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers') + if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id): + if float_compare(sum_product_uom_qty, self.product_uom_qty, + precision_rounding=self.product_id.uom_id.rounding) == 1: + raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") + elif float_compare(sum_product_uom_qty, self.product_uom_qty, + precision_rounding=self.product_id.uom_id.rounding) == 1: return { 'name': _('需求计划'), 'type': 'ir.actions.act_window', diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index ab70276e..f6f33676 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -594,7 +594,8 @@ class SfProductionDemandPlan(models.Model): raise UserError(_("没有需要下达的计划!")) check_overdelivery_allowed = False if not self.demand_plan_id.overdelivery_allowed: - if self.location_id.name == '客户': + customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers') + if self.location_id.id == customer_location_id: check_overdelivery_allowed = True # 按产品分组并计算总数 product_data = {} @@ -611,7 +612,8 @@ class SfProductionDemandPlan(models.Model): # 检查需求超过计划数量的产品 warning_messages = [] for product, data in product_data.items(): - if data['plan_uom_qty'] > data['product_uom_qty']: + if 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']) @@ -639,11 +641,13 @@ class SfProductionDemandPlan(models.Model): raise ValidationError(f"供货方式不能为空!") check_overdelivery_allowed = False if not self.demand_plan_id.overdelivery_allowed: - if self.location_id.name == '客户': + customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers') + if self.location_id.id == customer_location_id: check_overdelivery_allowed = True - if self.plan_uom_qty > self.product_uom_qty and check_overdelivery_allowed: - raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") - elif self.plan_uom_qty > self.product_uom_qty: + if check_overdelivery_allowed: + if float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1: + raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。") + elif float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1: return { 'name': _('需求计划'), 'type': 'ir.actions.act_window',