Hi, I have developed a code to generate a zip folder contain some files one is xml and the one is csv file, my code work normally in my localhost the zip folder is passed directly to my Downloads but when i copied my code on the server to work on production mode , the folder passed directly to the home of server and not to the user system laptop,
HERE IS MY CODE python related to the behaviour of generating a zip folder
class PrintFinTable(Wizard):
__name__ = 'account.fin.export.wizard'
start = StateView(
'account.fin.export.start',
'account_fin_export.print_fin_table_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Generate', 'generate_zip', 'tryton-print', default=True),
]
)
generate_zip = StateTransition()
download = StateView(
'account.fin.export.start',
'account_fin_export.print_fin_table_start_view_form', [
Button('Download ZIP', 'end', 'tryton-ok'),
]
)
def transition_generate_zip(self):
'''
Generates the ZIP file
'''
record = self.start
if not record:
raise ValueError("No valid Folder to export Start record found.")
record.generate_files_and_zip()
return 'end'
class FinExportStart(ModelSQL, ModelView):
'Fin Export Start'
__name__ = 'account.fin.export.start'
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year', required=True)
company = fields.Many2One('company.company', 'Company', required=True)
zip_filename = fields.Function(fields.Char('Zip Filename'), 'get_zip_filename')
download_url = fields.Function(fields.Char('Download URL'), 'get_download_url')
@classmethod
def default_company(cls):
return Transaction().context.get('company')
def get_zip_filename(self, name):
return f'Fin_export_{self.id}.zip'
def get_download_url(self, name):
return f'/fin_export/download/{self.id}'
def generate_files_and_zip(self):
'''
Generates index.xml and finnance.csv, then zips them.
Stores the ZIP in the system’s default Downloads folder.
'''
if not self.company or not self.fiscalyear:
raise ValueError("Company or Fiscal Year is missing.")
company_name = self.company.party.name if self.company.party else "Unknown Company"
company_city = self.company.party.addresses[0].city
fiscal_year_end = self.fiscalyear.end_date if self.fiscalyear.end_date else " "
fiscal_year_name = self.fiscalyear.name if self.fiscalyear else " "
fiscal_year_start = self.fiscalyear.start_date if self.fiscalyear.start_date else " "
downloads_folder = self.get_downloads_folder()
custom_folder = os.path.join(downloads_folder, "_Fin_Exports")
# Ensure the Downloads folder exists
os.makedirs(custom_folder, exist_ok=True)
xml_path = os.path.join(downloads_folder, 'index.xml')
finnance_path = os.path.join(downloads_folder, 'finnance.csv')
xml_content = self.generate_xml(company_name, company_city, fiscal_year_end, fiscal_year_start)
finnance_content = self.generate_finnance()
# Write files
with open(xml_path, 'w', encoding='utf-8') as xml_file:
xml_file.write(xml_content)
with open(finnance_path, 'w', encoding='utf-8') as finnance_file:
finnance_file.write(finnance_content)
zip_filename = f'Fin_export_{fiscal_year_name}.zip'
zip_path = os.path.join(custom_folder, zip_filename)
# Create ZIP and add files
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipf.write(xml_path, 'index.xml')
zipf.write(finnance_path, 'finnance.csv')
# Remove original files after zipping
os.remove(xml_path)
os.remove(finnance_path)
return zip_path
and this the XML code
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<!-- Report Action -->
<record model="ir.ui.view" id="print_fin_table_start_view_form">
<field name="model">account.fin.export.start</field>
<field name="type">form</field>
<field name="name">export_start_view</field>
</record>
<record model="ir.action.wizard" id="wizard_print_fin_table">
<field name="name">Download zip Folder</field>
<field name="wiz_name">account.fin.export.wizard</field>
</record>
<menuitem name="Download ZIP folder" id="menu_account_fin_exportt"
sequence="60" action="wizard_print_fin_table"/>
<!-- End -->
</data>
</tryton>
I am stuck on is there something to add in the xml code or in my python code to let the zip folder normally be downloaded on the user system not on the home server.
any help will be appreciated