From 94df139110226ae8466d930f46ebb23ddbc5745d Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Mon, 11 Dec 2023 14:41:31 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=AE=89=E8=A3=85=E6=97=B6?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=B7=B2=E6=9C=89=E6=9C=BA=E5=BA=8A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=AD=98=E5=9C=A8=E7=9A=84=E5=88=80=E4=BD=8D=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=9C=BA=E5=8F=B0=E6=8D=A2=E5=88=80=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/__init__.py | 31 +++++++++++++++--------------- sf_tool_management/__manifest__.py | 1 + sf_tool_management/models/base.py | 12 +++++++++++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/sf_tool_management/__init__.py b/sf_tool_management/__init__.py index bb4c0be1..ed3fccb9 100644 --- a/sf_tool_management/__init__.py +++ b/sf_tool_management/__init__.py @@ -2,19 +2,18 @@ from . import models from . import wizard -# from odoo import api, SUPERUSER_ID -# import logging -# _logger = logging.getLogger(__name__) -# -# -# def _sf_tool_management_post_install(cr, registry): -# # 这里执行你想要在安装模块时执行的操作,包括调用和执行模型的方法 -# env = api.Environment(cr, SUPERUSER_ID, {}) -# -# # 获取需要执行方法的模型 -# model_obj = env['sf.machine.table.tool.changing.apply'] -# logging.info('post_install方法执行了') -# print('post_install方法执行了') -# -# # 调用模型方法 -# model_obj.create_tool_change_application() +from odoo import api, SUPERUSER_ID +import logging + +_logger = logging.getLogger(__name__) + + +def _post_install(cr, registry): + # 这里执行你想要在安装模块时执行的操作,包括调用和执行模型的方法 + env = api.Environment(cr, SUPERUSER_ID, {}) + + # 获取需要执行方法的模型 + model_obj = env['sf.machine.table.tool.changing.apply'] + + # 调用模型方法 + model_obj.create_tool_change_application() diff --git a/sf_tool_management/__manifest__.py b/sf_tool_management/__manifest__.py index a3350a58..c3bb2e19 100644 --- a/sf_tool_management/__manifest__.py +++ b/sf_tool_management/__manifest__.py @@ -21,6 +21,7 @@ ], 'demo': [ ], + 'post_init_hook': '_post_install', 'assets': { 'web.assets_qweb': [ diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 71cb41f5..54834390 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -477,7 +477,17 @@ class MachineTableToolChangingApply(models.Model): [('name', '=', self.name.id)]).write({'status': '0'}) def create_tool_change_application(self): - print("调用了create_tool_change_application()") + maintenance_equipment_ids = self.env['maintenance.equipment'].sudo().search( + [('product_template_ids', '!=', False)]) + tool_changing_apply = self.env['sf.machine.table.tool.changing.apply'] + if maintenance_equipment_ids: + for maintenance_equipment_id in maintenance_equipment_ids: + if maintenance_equipment_id.product_template_ids: + for product_template_id in maintenance_equipment_id.product_template_ids: + tool_changing_apply.sudo().create({ + 'maintenance_equipment_id': product_template_id.equipment_id.id, + 'cutter_spacing_code_id': product_template_id.id + }) class CAMWorkOrderProgramKnifePlan(models.Model):