From df4995fa248159ec4996ea77c82a737a9e334870 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Fri, 4 Jul 2025 10:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AE=A1=E5=88=92=E4=B8=8B?= =?UTF-8?q?=E8=BE=BE=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sf_demand_plan.py | 2 +- .../models/sf_production_demand_plan.py | 46 +++++++++++++++++-- sf_demand_plan/views/demand_plan.xml | 3 +- sf_demand_plan/views/demand_plan_info.xml | 2 +- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index 4748724b..15e82844 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -193,7 +193,7 @@ class SfDemandPlan(models.Model): result.append((plan.id, plan.sale_order_id.name)) return result - def button_batch_release_plan(self): + 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: diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 8164e595..2cc93f0a 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -172,9 +172,10 @@ class SfProductionDemandPlan(models.Model): bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True) location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True) - @api.onchange('plan_uom_qty') - def _onchange_plan_uom_qty(self): - if self.plan_uom_qty == 0 or self.plan_uom_qty < 0: + @api.constrains('plan_uom_qty') + def _check_plan_uom_qty(self): + line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0) + if line_ids: raise ValidationError(_("计划量不能小于等于0")) @api.depends('new_supply_method') @@ -583,6 +584,45 @@ class SfProductionDemandPlan(models.Model): raise ValidationError(f"最后一条计划,不能删除!") self.unlink() + def button_batch_release_plan(self): + filtered_plan = self.filtered(lambda mo: mo.status == '30') + if not filtered_plan: + raise UserError(_("没有需要下达的计划!")) + # 按产品分组并计算总数 + product_data = {} + for plan in filtered_plan: + if plan.product_id not in product_data: + # 初始化产品数据,从产品上获取需求量 + product_data[plan.product_id] = { + 'plan_uom_qty': 0.0, + 'product_uom_qty': plan.product_uom_qty + } + + # 累加计划数量 + product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty + # 检查需求超过计划数量的产品 + warning_messages = [] + for product, data in product_data.items(): + if data['plan_uom_qty'] > data['product_uom_qty']: + warning_messages.append( + _("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") % + (product.display_name, data['plan_uom_qty'], data['product_uom_qty']) + ) + if warning_messages: + warning_message = "\n".join(warning_messages) + return { + 'name': _('需求计划'), + 'type': 'ir.actions.act_window', + 'views': [(self.env.ref( + 'sf_demand_plan.sf_release_plan_wizard_form').id, + 'form')], + 'res_model': 'sf.release.plan.wizard', + 'target': 'new', + 'context': { + 'default_demand_plan_line_id': self.ids, + 'default_release_message': warning_message, + }} + def button_release_plan(self): self.ensure_one() if not self.new_supply_method: diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index d6b7e4e6..da16fc8a 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -8,9 +8,8 @@
diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml index 3b58bb63..74d9f213 100644 --- a/sf_demand_plan/views/demand_plan_info.xml +++ b/sf_demand_plan/views/demand_plan_info.xml @@ -7,7 +7,7 @@
-