diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py
index 948ee9e1..9ca91077 100644
--- a/sf_demand_plan/models/sf_demand_plan.py
+++ b/sf_demand_plan/models/sf_demand_plan.py
@@ -173,6 +173,7 @@ class SfDemandPlan(models.Model):
status_line = line.line_ids.filtered(lambda p: p.status == '60')
if line.sale_order_id.state == 'cancel':
line.state = '50'
+ line.line_ids.status = '100'
elif len(line.line_ids) == len(status_line):
line.state = '40'
elif bool(status_line):
diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py
index bf27d5ee..3be61e85 100644
--- a/sf_demand_plan/models/sf_production_demand_plan.py
+++ b/sf_demand_plan/models/sf_production_demand_plan.py
@@ -257,8 +257,11 @@ class SfProductionDemandPlan(models.Model):
@api.depends('status')
def _compute_mrp_production_ids(self):
for record in self:
- record.mrp_production_ids = self.env['mrp.production'].sudo().search(
- [('demand_plan_line_id', '=', record.id)]).ids
+ if record.status in ('50', '60'):
+ record.mrp_production_ids = self.env['mrp.production'].sudo().search(
+ [('demand_plan_line_id', '=', record.id)]).ids
+ else:
+ record.mrp_production_ids = None
@api.depends('mrp_production_ids.state')
def _compute_hide_release_production_order(self):
@@ -274,10 +277,11 @@ class SfProductionDemandPlan(models.Model):
if record.planned_start_date and record.planned_start_date < fields.Date.today():
raise ValidationError("计划开工日期必须大于或等于今天。")
- def release_production_order(self):
+ def button_release_production(self):
+ self.ensure_one()
if not self.planned_start_date:
raise ValidationError("请先填写计划开工日期")
- pro_plan_list = self.env['sf.production.plan'].search(
+ pro_plan_list = self.env['sf.production.plan'].sudo().search(
[('production_id', 'in', self.mrp_production_ids.ids), ('state', '=', 'draft')])
sf_production_line = self.env['sf.production.line'].sudo().search(
[('name', '=', '1#CNC自动生产线')], limit=1)
@@ -290,11 +294,19 @@ class SfProductionDemandPlan(models.Model):
pro_plan_list.date_planned_start = date_planned_start
self._do_production_schedule(pro_plan_list)
self.status = '60'
+ self.update_sale_order_state()
def _do_production_schedule(self, pro_plan_list):
for pro_plan in pro_plan_list:
pro_plan.do_production_schedule()
+ def update_sale_order_state(self):
+ demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
+ demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
+ if not demand_plan_state:
+ # 修改销售订单为加工中
+ self.sale_order_id.state = 'processing'
+
def edit_button(self):
self.ensure_one()
action = {
@@ -563,6 +575,7 @@ class SfProductionDemandPlan(models.Model):
self.write({'status': '50'})
else:
self.write({'status': '60'})
+ self.update_sale_order_state()
def mrp_bom_create(self):
if self.supply_method in ('automation', 'manual'):
diff --git a/sf_demand_plan/models/sf_production_plan.py b/sf_demand_plan/models/sf_production_plan.py
deleted file mode 100644
index daf527f6..00000000
--- a/sf_demand_plan/models/sf_production_plan.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# -*- coding: utf-8 -*-
-from odoo import models, fields, api, _
-
-
-class SfProductionPlan(models.Model):
- _inherit = 'sf.production.plan'
-
- demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
- string="需求计划明细", readonly=True)
-
- @api.model
- def create(self, vals):
- res = super(SfProductionPlan, self).create(vals)
- res.demand_plan_line_id = res.production_id.demand_plan_line_id.id
- return res
diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml
index dc8a99c9..a466f691 100644
--- a/sf_demand_plan/views/demand_plan.xml
+++ b/sf_demand_plan/views/demand_plan.xml
@@ -43,7 +43,7 @@