需求计划下达计划

This commit is contained in:
guanhuan
2025-07-04 10:18:28 +08:00
parent 6e877d0449
commit df4995fa24
4 changed files with 46 additions and 7 deletions

View File

@@ -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:

View File

@@ -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: