diff --git a/sf_demand_plan/models/mrp_production.py b/sf_demand_plan/models/mrp_production.py
index 4a618cea..ebb87971 100644
--- a/sf_demand_plan/models/mrp_production.py
+++ b/sf_demand_plan/models/mrp_production.py
@@ -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
diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py
index 1a41c3ec..4748724b 100644
--- a/sf_demand_plan/models/sf_demand_plan.py
+++ b/sf_demand_plan/models/sf_demand_plan.py
@@ -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()
diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py
index 8fc5763d..8164e595 100644
--- a/sf_demand_plan/models/sf_production_demand_plan.py
+++ b/sf_demand_plan/models/sf_production_demand_plan.py
@@ -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()
diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml
index 6c1a39d4..d6b7e4e6 100644
--- a/sf_demand_plan/views/demand_plan.xml
+++ b/sf_demand_plan/views/demand_plan.xml
@@ -8,6 +8,10 @@
@@ -26,6 +30,7 @@
attrs="{'readonly': ['|',('status', '!=', '30'),('readonly_custom_made_type', '=', True)],
'required': [('new_supply_method', '=', 'custom_made')]}"/>
+
@@ -77,6 +82,10 @@
+
diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml
index f7f49ee4..3b58bb63 100644
--- a/sf_demand_plan/views/demand_plan_info.xml
+++ b/sf_demand_plan/views/demand_plan_info.xml
@@ -5,10 +5,11 @@