diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index 63371dfd..bd181937 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -3,6 +3,7 @@ from odoo import models, fields, api, _ from odoo.tools import float_compare from odoo.exceptions import ValidationError +import re class SfDemandPlan(models.Model): @@ -10,8 +11,7 @@ class SfDemandPlan(models.Model): _description = 'sf_demand_plan' state = fields.Selection([ - ('10', '需求确认'), - ('20', '待工艺设计'), + ('10', '待工艺设计'), ('30', '部分下达'), ('40', '已下达'), ('50', '取消'), @@ -83,6 +83,8 @@ class SfDemandPlan(models.Model): compute='_compute_readonly_custom_made_type', default=False ) + demand_plan_number = fields.Char('需求计划号', compute='_compute_demand_plan_number', readonly=True, store=True) + origin = fields.Char('来源', related='sale_order_id.name', readonly=True, store=True) @api.depends('product_id.part_number', 'product_id.model_name') def _compute_part_number(self): @@ -210,3 +212,17 @@ class SfDemandPlan(models.Model): else: for demand_plan_line_id in line_ids: demand_plan_line_id.action_confirm() + #需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位,所以这里也直接截取product_id.name + @api.depends('product_id.name') + def _compute_demand_plan_number(self): + for line in self: + product_name = line.product_id.name or '' + plan_no = None + if line.product_id: + # 使用正则表达式匹配P-后面的所有字符 + match = re.search(r'P-(.*)', product_name) + if match: + plan_no = match.group(1) + line.demand_plan_number = plan_no + else: + line.demand_plan_number = None \ No newline at end of file diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml index 74d9f213..80344940 100644 --- a/sf_demand_plan/views/demand_plan_info.xml +++ b/sf_demand_plan/views/demand_plan_info.xml @@ -14,6 +14,7 @@ + @@ -35,6 +36,7 @@ +