Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odgovori
1338 Prikazi

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}'
}

Avatar
Opusti
Avtor Best Answer

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

Avatar
Opusti
Best Answer

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!

Avatar
Opusti
Best Answer

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,

            }

        }

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
sep. 24
1400
2
jul. 24
2030
1
maj 25
571
1
avg. 25
190
4
jun. 25
2071