Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
1335 Lượt xem

Hello everyone,

I'm facing an issue in Odoo 16 development. In my wizard window, when I click the OK button, the action_submit method executes correctly, and the browser downloads the file. However, the temporary window does not close automatically.

I would like to implement the functionality to close the window automatically after clicking OK. Has anyone encountered a similar issue or knows how to resolve it?


import shutil
import time

from ..utils.g_led_location import generate_led_table
from odoo import models, fields, http


class InputDataWizard(models.TransientModel):
_name = 'input.data.wizard'
_description = 'Input Data Wizard'

field1 = fields.Char(string='A面规格')
field2 = fields.Char(string='B面规格')

def action_submit(self):
import os
current_path = os.path.abspath(os.path.dirname(__file__))
filename = f'{str(time.time() * 1000)}.xlsx'
out_file = os.path.join(
os.path.split(current_path)[0], 'static/files', filename
).replace('\\', '/')

target_folder = os.path.dirname(out_file)
try:
shutil.rmtree(target_folder)
os.makedirs(target_folder)
except Exception as e:
print(f"Error clearing folder {target_folder}: {e}")

a, b, c = map(int, self.field1.split(','))
d, e, f = map(int, self.field2.split(','))

spec_A = (c, b, a)
spec_B = (f, e, d)
current_domain = http.request.httprequest.host_url
generate_led_table(spec_A, spec_B, out_file)

return {
'type': 'ir.actions.act_url',
'url': f'{current_domain}shelving_test_system/static/files/{filename}'
}

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I made your changes to the code base on your suggestion,restarted the program,and upgraded the module, but the problem is still there.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi

You can add a "close" key to your return statement, as shown below:

return {

    'type': 'ir.actions.act_url',

    'url': f'{current_domain}shelving_test_system/static/files/{filename}',

    'close': True,

}

Hope this helps!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Can use tag reload or type  ir.actions.act_window_close please check below sample code:-


    def reset_template(self):

        if not self.template_ids:

            return False

        self.template_ids.reset_template()

        if self.env.context.get('params', {}).get('view_type') == 'list':

            next_action = {'type': 'ir.actions.client', 'tag': 'reload'}

        else:

            next_action = {'type': 'ir.actions.act_window_close'}

        return {

            'type': 'ir.actions.client',

            'tag': 'display_notification',

            'params': {

                'type': 'success',

                'message': _('SMS Templates have been reset'),

                'next': next_action,

            }

        }

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 24
1398
2
thg 7 24
2026
1
thg 5 25
571
1
thg 8 25
190
4
thg 6 25
2070