Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
1337 Vizualizări

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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!

Imagine profil
Abandonează
Cel mai bun răspuns

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,

            }

        }

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
sept. 24
1400
2
iul. 24
2030
1
mai 25
571
1
aug. 25
190
4
iun. 25
2071