需求计划下达计划
This commit is contained in:
@@ -21,6 +21,6 @@ class MrpProduction(models.Model):
|
||||
production.production_type = None
|
||||
|
||||
def _get_purchase_request(self):
|
||||
"""获取跟制造订单相关的采购申请单"""
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', '=', self.name)])
|
||||
"""获取跟制造订单相关的采购申请单(根据采购申请单行项目的产品匹配)"""
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('line_ids.demand_plan_line_id', 'in', self.demand_plan_line_id.ids)])
|
||||
return pr_ids
|
||||
|
||||
@@ -161,7 +161,7 @@ class SfDemandPlan(models.Model):
|
||||
def _compute_hide_button_release_plan(self):
|
||||
for line in self:
|
||||
line.hide_button_release_plan = bool(line.line_ids.filtered(
|
||||
lambda p: p.status != '60'))
|
||||
lambda p: p.status == '30'))
|
||||
|
||||
def button_release_plan(self):
|
||||
pass
|
||||
@@ -187,15 +187,28 @@ class SfDemandPlan(models.Model):
|
||||
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||
line.readonly_custom_made_type = bool(production_demand_plan)
|
||||
|
||||
def write(self, vals):
|
||||
res = super(SfDemandPlan, self).write(vals)
|
||||
line_ids = self.line_ids.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
||||
if line_ids:
|
||||
raise ValidationError(f"计划量不能小于等于0")
|
||||
return res
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for plan in self:
|
||||
result.append((plan.id, plan.sale_order_id.name))
|
||||
return result
|
||||
|
||||
def button_batch_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:
|
||||
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': line_ids.ids,
|
||||
'default_release_message': f"您正在下达计划量 {sum_product_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
||||
}}
|
||||
else:
|
||||
for demand_plan_line_id in line_ids:
|
||||
demand_plan_line_id.action_confirm()
|
||||
|
||||
@@ -53,7 +53,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
('custom_made', "自制"),
|
||||
('purchase', "外购"),
|
||||
('outsourcing', "委外加工"),
|
||||
], string='供货方式', readonly=True)
|
||||
], string='供货方式', required=True)
|
||||
|
||||
custom_made_type = fields.Selection([
|
||||
('automation', "自动化产线加工"),
|
||||
@@ -160,7 +160,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
#
|
||||
# outsourcing_purchase_request = fields.Char('委外采购申请单')
|
||||
|
||||
plan_uom_qty = fields.Float(string="计划量")
|
||||
plan_uom_qty = fields.Float(string="计划量", required=True)
|
||||
procurement_reason = fields.Selection([
|
||||
('销售订单', "销售订单"),
|
||||
('需求预测', "需求预测"),
|
||||
@@ -172,6 +172,11 @@ 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:
|
||||
raise ValidationError(_("计划量不能小于等于0"))
|
||||
|
||||
@api.depends('new_supply_method')
|
||||
def _compute_custom_made_type(self):
|
||||
DemandPlan = self.env['sf.production.demand.plan'].sudo()
|
||||
@@ -592,7 +597,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
'res_model': 'sf.release.plan.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_demand_plan_line_id': self.id,
|
||||
'default_demand_plan_line_id': self.ids,
|
||||
'default_release_message': f"您正在下达计划量 {self.plan_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
||||
}}
|
||||
self.action_confirm()
|
||||
|
||||
Reference in New Issue
Block a user