需求计划下达计划
This commit is contained in:
@@ -193,7 +193,7 @@ class SfDemandPlan(models.Model):
|
|||||||
result.append((plan.id, plan.sale_order_id.name))
|
result.append((plan.id, plan.sale_order_id.name))
|
||||||
return result
|
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')
|
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||||
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
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:
|
||||||
|
|||||||
@@ -172,9 +172,10 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
||||||
|
|
||||||
@api.onchange('plan_uom_qty')
|
@api.constrains('plan_uom_qty')
|
||||||
def _onchange_plan_uom_qty(self):
|
def _check_plan_uom_qty(self):
|
||||||
if self.plan_uom_qty == 0 or self.plan_uom_qty < 0:
|
line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
||||||
|
if line_ids:
|
||||||
raise ValidationError(_("计划量不能小于等于0"))
|
raise ValidationError(_("计划量不能小于等于0"))
|
||||||
|
|
||||||
@api.depends('new_supply_method')
|
@api.depends('new_supply_method')
|
||||||
@@ -583,6 +584,45 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
raise ValidationError(f"最后一条计划,不能删除!")
|
raise ValidationError(f"最后一条计划,不能删除!")
|
||||||
self.unlink()
|
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):
|
def button_release_plan(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if not self.new_supply_method:
|
if not self.new_supply_method:
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
<header>
|
<header>
|
||||||
<button string="打印" name="button_action_print" type="object"
|
<button string="打印" name="button_action_print" type="object"
|
||||||
class="btn-primary"/>
|
class="btn-primary"/>
|
||||||
<button string="下达计划" name="button_release_plan" type="object"
|
<button string="下达计划" name="button_batch_release_plan" type="object"
|
||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
|
||||||
/>
|
/>
|
||||||
</header>
|
</header>
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<header>
|
<header>
|
||||||
<field name="state" widget="statusbar"/>
|
<field name="state" widget="statusbar"/>
|
||||||
<field name="hide_button_release_plan" invisible="1"/>
|
<field name="hide_button_release_plan" invisible="1"/>
|
||||||
<button string="下达计划" name="button_batch_release_plan" type="object"
|
<button string="下达计划" name="button_production_release_plan" type="object"
|
||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>
|
attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
Reference in New Issue
Block a user