diff --git a/sf_demand_plan/models/__init__.py b/sf_demand_plan/models/__init__.py
index 3f627a01..bbab565f 100644
--- a/sf_demand_plan/models/__init__.py
+++ b/sf_demand_plan/models/__init__.py
@@ -7,3 +7,4 @@ from . import stock_route
from . import mrp_bom
from . import mrp_production
from . import stock_rule
+from . import purchase_request
diff --git a/sf_demand_plan/models/purchase_request.py b/sf_demand_plan/models/purchase_request.py
new file mode 100644
index 00000000..0f25d890
--- /dev/null
+++ b/sf_demand_plan/models/purchase_request.py
@@ -0,0 +1,24 @@
+from odoo import models, fields, api, _
+
+
+class PurchaseRequestLine(models.Model):
+ _inherit = 'purchase.request.line'
+ _description = '采购申请明细'
+
+ supply_method = fields.Selection([
+ ('automation', "自动化产线加工"),
+ ('manual', "人工线下加工"),
+ ('purchase', "外购"),
+ ('outsourcing', "委外加工"),
+ ], string='供货方式', readonly=True)
+
+ demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
+ string="需求计划明细", readonly=True)
+
+ @api.depends('demand_plan_line_id')
+ def _compute_supply_method(self):
+ for prl in self:
+ if prl.demand_plan_line_id:
+ prl.supply_method = prl.demand_plan_line_id.supply_method
+ else:
+ prl.supply_method = None
diff --git a/sf_demand_plan/models/sale_order.py b/sf_demand_plan/models/sale_order.py
index d5de7b9a..2e87799e 100644
--- a/sf_demand_plan/models/sale_order.py
+++ b/sf_demand_plan/models/sale_order.py
@@ -10,12 +10,15 @@ class ReSaleOrder(models.Model):
string='与此销售订单相关联的制造订单',
groups='mrp.group_mrp_user', store=True)
+ demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
+ string="需求计划", readonly=True)
+
demand_plan_count = fields.Integer(
"需求计划生成计数",
compute='_compute_demand_plan_count',
)
- @api.depends('procurement_group_id')
+ @api.depends('demand_plan_id.line_ids.status')
def _compute_purchase_request_count(self):
for so in self:
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', so.name)])
@@ -24,6 +27,7 @@ class ReSaleOrder(models.Model):
else:
so.purchase_request_purchase_order_count = 0
+ @api.depends('demand_plan_id.line_ids')
def _compute_demand_plan_count(self):
for line in self:
demand_plan = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', line.id)])
@@ -48,6 +52,7 @@ class ReSaleOrder(models.Model):
'type': '1',
}
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
+ ret.order_id.demand_plan_id = demand_plan_info.id
return ret
def confirm_to_supply_method(self):
diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py
index b5a2eda0..948ee9e1 100644
--- a/sf_demand_plan/models/sf_demand_plan.py
+++ b/sf_demand_plan/models/sf_demand_plan.py
@@ -15,7 +15,7 @@ class SfDemandPlan(models.Model):
return list
state = fields.Selection([
- ('10', '草稿'),
+ ('10', '需求确认'),
('20', '待工艺设计'),
('30', '部分下达'),
('40', '已下达'),
diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py
index e9bc2fa5..da1c2bd3 100644
--- a/sf_demand_plan/models/sf_production_demand_plan.py
+++ b/sf_demand_plan/models/sf_production_demand_plan.py
@@ -544,9 +544,9 @@ class SfProductionDemandPlan(models.Model):
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
- else:
+ elif self.supply_method == 'outsourcing':
line_ids = self.demand_plan_id.line_ids.filtered(
- lambda p: p.supply_method in ('purchase', 'outsourcing') and p.status == '60')
+ lambda p: p.supply_method == 'outsourcing' and p.status == '60')
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
diff --git a/sf_demand_plan/models/stock_rule.py b/sf_demand_plan/models/stock_rule.py
index 59705101..fe9c07eb 100644
--- a/sf_demand_plan/models/stock_rule.py
+++ b/sf_demand_plan/models/stock_rule.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-from odoo import models
+from odoo import api, fields, models
class StockRule(models.Model):
@@ -14,3 +13,10 @@ class StockRule(models.Model):
if self.env.context.get('demand_plan_line_id'):
res['demand_plan_line_id'] = self.env.context.get('demand_plan_line_id')
return res
+
+ @api.model
+ def _prepare_purchase_request_line(self, request_id, procurement):
+ res = super()._prepare_purchase_request_line(request_id, procurement)
+ if self.env.context.get('demand_plan_line_id'):
+ res['demand_plan_line_id'] = self.env.context.get('demand_plan_line_id')
+ return res
diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml
index 569c5b55..4f618137 100644
--- a/sf_demand_plan/views/demand_plan_info.xml
+++ b/sf_demand_plan/views/demand_plan_info.xml
@@ -52,7 +52,7 @@
-
+