From 96c22a5d4649faf54eb6a184a8a95e330cbf9ca4 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 24 Jul 2024 17:30:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E6=9C=8D=E5=8A=A1=E4=BA=A7=E5=93=81=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_bf_connect/models/process_status.py | 53 +++++++++++++++----------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/sf_bf_connect/models/process_status.py b/sf_bf_connect/models/process_status.py index 735bc531..5ef558f0 100644 --- a/sf_bf_connect/models/process_status.py +++ b/sf_bf_connect/models/process_status.py @@ -14,25 +14,34 @@ class StatusChange(models.Model): def action_confirm(self): # 在原有方法执行前记录日志和执行其他操作 logging.info('函数已经执行=============') + server_product_none = [] for order in self.order_lines: for item in order.product_template_id.model_process_parameters_ids: - server_product = self.env['product.template'].search( - [('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id), - ('detailed_type', '=', 'service')]) - logging.info('server_product:%s' % server_product.name) - if server_product: - order_line_ids.append((0, 0, { - 'product_id': server_product.product_variant_id.id, - 'product_qty': 1, - 'product_uom': server_product.uom_id.id - })) - self.env['purchase.order'].sudo().create({ - 'partner_id': server_product.seller_ids.partner_id.id, - 'origin': record.production_id.name, - 'state': 'draft', - 'order_line': order_line_ids, - }) + server_product = self.env['product.template'].search( + [('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id), + ('detailed_type', '=', 'service')]) + if not server_product: + server_product_none.append(item.surface_technics_parameters_id.name) + if server_product_none: + raise UserError(_("请先至产品中创建表面工艺为%s的服务产品", ", ".join(server_product_none))) + # if not server_product_none: + # for st_item in order.product_template_id.model_process_parameters_ids: + # server_product = self.env['product.template'].search( + # [('server_product_process_parameters_id', '=', st_item.surface_technics_parameters_id.id), + # ('detailed_type', '=', 'service')]) + # if server_product: + # order_line_ids.append((0, 0, { + # 'product_id': server_product.product_variant_id.id, + # 'product_qty': 1, + # 'product_uom': server_product.uom_id.id + # })) + # self.env['purchase.order'].sudo().create({ + # 'partner_id': server_product.seller_ids.partner_id.id, + # 'origin': record.production_id.name, + # 'state': 'draft', + # 'order_line': order_line_ids, + # }) # 使用super()来调用原始方法(在本例中为'sale.order'模型的'action_confirm'方法) res = super(StatusChange, self).action_confirm() @@ -221,12 +230,12 @@ class FinishStatusChange(models.Model): [('id', 'child_of', self.picking_type_id.warehouse_id.view_location_id.id), ('usage', '!=', 'supplier')]) if self.env['stock.move'].search([ - ('state', 'in', ['confirmed', 'partially_available', 'waiting', 'assigned']), - ('product_qty', '>', 0), - ('location_id', 'in', wh_location_ids), - ('move_orig_ids', '=', False), - ('picking_id', 'not in', self.ids), - ('product_id', 'in', lines.product_id.ids)], limit=1): + ('state', 'in', ['confirmed', 'partially_available', 'waiting', 'assigned']), + ('product_qty', '>', 0), + ('location_id', 'in', wh_location_ids), + ('move_orig_ids', '=', False), + ('picking_id', 'not in', self.ids), + ('product_id', 'in', lines.product_id.ids)], limit=1): action = self.action_view_reception_report() action['context'] = {'default_picking_ids': self.ids} return action