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