From 1f93ba3b42626896d4e053cd02e543374f628478 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Thu, 10 Jul 2025 14:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AA=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AE=A1=E5=88=92=E5=88=A0=E9=99=A4=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=A1=8C=E9=97=AE=E9=A2=98,=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sale_order.py | 4 +- sf_demand_plan/models/sf_demand_plan.py | 10 +++- .../models/sf_production_demand_plan.py | 18 ++++---- sf_demand_plan/views/demand_plan_info.xml | 40 ++++++++++++++-- .../wizard/sf_demand_plan_print_wizard.py | 46 ++++++++----------- 5 files changed, 76 insertions(+), 42 deletions(-) diff --git a/sf_demand_plan/models/sale_order.py b/sf_demand_plan/models/sale_order.py index fe8966a6..149fadfe 100644 --- a/sf_demand_plan/models/sale_order.py +++ b/sf_demand_plan/models/sale_order.py @@ -11,7 +11,7 @@ class ReSaleOrder(models.Model): groups='mrp.group_mrp_user', store=True) demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan", - string="需求计划", readonly=True) + string="需求计划", readonly=True) demand_plan_count = fields.Integer( string="需求计划生成计数", @@ -47,9 +47,9 @@ class ReSaleOrder(models.Model): if demand_plan.product_id.machining_drawings_name: filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0] wizard_vals = { - 'demand_plan_id': demand_plan.id, 'model_id': demand_plan.model_id, 'filename_url': filename_url, + 'machining_drawings': product.machining_drawings, 'type': '1', } self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals) diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index c873dd7b..7707eec3 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -167,7 +167,9 @@ class SfDemandPlan(models.Model): def _compute_state(self): for line in self: status_line = line.line_ids.filtered(lambda p: p.status == '60') - if line.sale_order_id.state == 'cancel': + if not line.line_ids: + line.state = '10' + elif line.sale_order_id.state == 'cancel': line.state = '50' line.line_ids.status = '100' elif len(line.line_ids) == len(status_line): @@ -184,6 +186,12 @@ 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) + @api.constrains('line_ids') + def check_line_ids(self): + for item in self: + if not item.line_ids: + raise ValidationError('计划不能为空!') + def write(self, vals): res = super(SfDemandPlan, self).write(vals) if 'line_ids' in vals: diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 4428acce..9f5d17f4 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -56,7 +56,7 @@ class SfProductionDemandPlan(models.Model): custom_made_type = fields.Selection([ ('automation', "自动化产线加工"), ('manual', "人工线下加工"), - ], string='自制类型', compute='_compute_custom_made_type', store=True) + ], string='产线类型', compute='_compute_custom_made_type', store=True) supply_method = fields.Selection([ ('automation', "自动化产线加工"), @@ -360,11 +360,12 @@ class SfProductionDemandPlan(models.Model): return action def button_action_print(self): + model_id = self.mapped('model_id') return { 'res_model': 'sf.demand.plan.print.wizard', 'type': 'ir.actions.act_window', 'name': _("打印"), - 'domain': [('demand_plan_id', 'in', self.ids)], + 'domain': [('model_id', 'in', model_id)], 'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']], 'target': 'new', } @@ -577,12 +578,13 @@ class SfProductionDemandPlan(models.Model): # programming_no = list(set(programming_mrp_production_ids)) # numbers_str = "、".join(programming_no) # raise ValidationError(f"编程单号:{numbers_str},请去云平台处理") - - def button_delete(self): - self.ensure_one() - if len(self.demand_plan_id.line_ids) == 1: - raise ValidationError(f"最后一条计划,不能删除!") - self.unlink() + @api.model + def unlink(self): + for item in self: + if item.status not in ('10', '20', '30'): + raise ValidationError(u'只能删除状态为【草稿,待确认,需求确认】的需求计划。') + else: + super(SfProductionDemandPlan, item).unlink() def button_batch_release_plan(self): filtered_plan = self.filtered(lambda mo: mo.status == '30') diff --git a/sf_demand_plan/views/demand_plan_info.xml b/sf_demand_plan/views/demand_plan_info.xml index 74d9f213..13718b51 100644 --- a/sf_demand_plan/views/demand_plan_info.xml +++ b/sf_demand_plan/views/demand_plan_info.xml @@ -39,8 +39,8 @@ - - + + @@ -51,6 +51,7 @@ + @@ -69,10 +70,39 @@ class="btn-primary" attrs="{'invisible': [('hide_release_production_order', '=', False)]}" /> -