diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py
index e65fdca7..59457102 100644
--- a/sf_demand_plan/__manifest__.py
+++ b/sf_demand_plan/__manifest__.py
@@ -13,7 +13,9 @@
'depends': ['sf_plan','jikimo_printing'],
'data': [
'security/ir.model.access.csv',
+ 'data/stock_route_group.xml',
'views/demand_plan.xml',
+ 'views/stock_route.xml',
'wizard/sf_demand_plan_print_wizard_view.xml',
],
'demo': [
diff --git a/sf_demand_plan/data/stock_route_group.xml b/sf_demand_plan/data/stock_route_group.xml
new file mode 100644
index 00000000..1b4a0b84
--- /dev/null
+++ b/sf_demand_plan/data/stock_route_group.xml
@@ -0,0 +1,21 @@
+
+
+
+
+ 自动化产线加工
+ automation
+
+
+ 人工线下加工
+ manual
+
+
+ 外购
+ purchase
+
+
+ 委外加工
+ outsourcing
+
+
+
\ No newline at end of file
diff --git a/sf_demand_plan/models/__init__.py b/sf_demand_plan/models/__init__.py
index a0554c11..70c1bbc8 100644
--- a/sf_demand_plan/models/__init__.py
+++ b/sf_demand_plan/models/__init__.py
@@ -2,3 +2,4 @@
from . import sf_production_demand_plan
from . import sale_order
+from . import stock_route
diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py
index 49cbe926..d43c2eb6 100644
--- a/sf_demand_plan/models/sf_production_demand_plan.py
+++ b/sf_demand_plan/models/sf_production_demand_plan.py
@@ -88,6 +88,9 @@ class SfProductionDemandPlan(models.Model):
string='订单状态',
related='sale_order_line_id.state')
route_id = fields.Many2one('stock.route', string='路线', related='sale_order_line_id.route_id', store=True)
+ route_ids = fields.Many2many('stock.route', 'stock_route_demand_plan', 'demand_plan_id', 'route_id', '路线',
+ domain=[('demand_plan_selectable', '=', True)], compute='_compute_route_ids',
+ store=True)
contract_date = fields.Date('合同日期', related='sale_order_id.contract_date')
date_order = fields.Datetime('下单日期', related='sale_order_id.date_order')
contract_code = fields.Char('合同号', related='sale_order_id.contract_code', store=True)
@@ -135,6 +138,18 @@ class SfProductionDemandPlan(models.Model):
outsourcing_purchase_request = fields.Char('委外采购申请单')
+ @api.depends('supply_method')
+ def _compute_route_ids(self):
+ for pdp in self:
+ if pdp.supply_method:
+ group_id = self.env['stock.route.group'].sudo().search([('code', '=', pdp.supply_method)])
+ route_ids = self.env['stock.route'].sudo().search(
+ [('demand_plan_selectable', '=', True), ('stock_route_group_ids', '=', group_id.id)])
+ if route_ids:
+ pdp.route_ids = route_ids.ids
+ break
+ pdp.route_ids = None
+
@api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line',
'sale_order_id.mrp_production_ids.state')
def _compute_status(self):
@@ -332,7 +347,6 @@ class SfProductionDemandPlan(models.Model):
for pro_plan in pro_plan_list:
pro_plan.do_production_schedule()
-
def button_action_print(self):
return {
'res_model': 'sf.demand.plan.print.wizard',
diff --git a/sf_demand_plan/models/stock_route.py b/sf_demand_plan/models/stock_route.py
new file mode 100644
index 00000000..20e4b3c9
--- /dev/null
+++ b/sf_demand_plan/models/stock_route.py
@@ -0,0 +1,49 @@
+from odoo import models, fields, api, _
+
+
+class SfStockRoute(models.Model):
+ _inherit = 'stock.route'
+
+ demand_plan_selectable = fields.Boolean("需求计划行")
+ stock_route_group_ids = fields.Many2many('stock.route.group', 'route_to_group', string='路线组')
+ demand_plan_ids = fields.Many2many('sf.production.demand.plan', 'stock_route_demand_plan', 'route_id',
+ 'demand_plan_id', '需求计划', copy=False, compute='_compute_demand_plan_ids',
+ store=True)
+
+ @api.depends('demand_plan_selectable', 'stock_route_group_ids')
+ def _compute_demand_plan_ids(self):
+ for sr in self:
+ if sr.demand_plan_selectable:
+ stock_route_group = [srg.code for srg in sr.stock_route_group_ids]
+ demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search(
+ [('supply_method', 'in', stock_route_group)])
+ if demand_plan_ids:
+ sr.demand_plan_ids = demand_plan_ids.ids
+ break
+ sr.demand_plan_ids = None
+
+ # def name_get(self):
+ # res = super().name_get()
+ # if self.env.context.get('demand_plan_search_stock_route_id'):
+ # demand_plan_id = self.env['sf.production.demand.plan'].sudo().browse(
+ # int(self.env.context.get('demand_plan_search_stock_route_id')))
+ # if demand_plan_id and demand_plan_id.supply_method:
+ # supply_method = self._set_supply_method(demand_plan_id.supply_method)
+ # res = [(item[0], f'{item[1]}-{supply_method}') for item in res if len(item) == 2]
+ # return res
+ #
+ # def _set_supply_method(self, supply_method):
+ # return {
+ # 'automation': "自动化产线加工",
+ # 'manual': "人工线下加工",
+ # 'purchase': "外购",
+ # 'outsourcing': "委外加工"
+ # }.get(supply_method)
+
+
+class SfStockRouteGroup(models.Model):
+ _name = 'stock.route.group'
+ _description = '路线组'
+
+ name = fields.Char('名称')
+ code = fields.Char('编码')
diff --git a/sf_demand_plan/security/ir.model.access.csv b/sf_demand_plan/security/ir.model.access.csv
index 56e8e247..a1bef90a 100644
--- a/sf_demand_plan/security/ir.model.access.csv
+++ b/sf_demand_plan/security/ir.model.access.csv
@@ -4,3 +4,6 @@ access_sf_production_demand_plan_for_dispatch,sf.production.demand.plan for disp
access_sf_demand_plan_print_wizard,sf.demand.plan.print.wizard,model_sf_demand_plan_print_wizard,base.group_user,1,0,0,0
access_sf_demand_plan_print_wizard_for_dispatch,sf.demand.plan.print.wizard for dispatch,model_sf_demand_plan_print_wizard,sf_base.group_plan_dispatch,1,1,0,0
+
+access_stock_route_group,stock.route.group,model_stock_route_group,base.group_user,1,0,0,0
+access_stock_route_group_dispatch,stock.route.group.dispatch,model_stock_route_group,sf_base.group_plan_dispatch,1,1,0,0
diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml
index 5b9c425a..a316df5a 100644
--- a/sf_demand_plan/views/demand_plan.xml
+++ b/sf_demand_plan/views/demand_plan.xml
@@ -38,7 +38,8 @@
-
+
diff --git a/sf_demand_plan/views/stock_route.xml b/sf_demand_plan/views/stock_route.xml
new file mode 100644
index 00000000..c4581acc
--- /dev/null
+++ b/sf_demand_plan/views/stock_route.xml
@@ -0,0 +1,21 @@
+
+
+
+ stock.route.form
+ stock.route
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sf_mrs_connect/models/mrp_production.py b/sf_mrs_connect/models/mrp_production.py
index ac3f6640..fe2682de 100644
--- a/sf_mrs_connect/models/mrp_production.py
+++ b/sf_mrs_connect/models/mrp_production.py
@@ -13,6 +13,8 @@ class MrpProduction(models.Model):
生成编程单
"""
productions = super().create(vals_list)
+ if not productions:
+ return self.browse()
# 定义变量存储编程单
grouped_product_programming_no = {}
# 定义产品拼接成的制造订单名称