Browse Source

[IMP]encode output file

pull/1047/head
aheficent 8 years ago
parent
commit
5d80520314
  1. 8
      sql_export/models/sql_export.py
  2. 1
      sql_export/views/sql_export_view.xml
  3. 3
      sql_export/wizard/wizard_file.py

8
sql_export/models/sql_export.py

@ -45,6 +45,14 @@ class SqlExport(models.Model):
'Parameters', 'Parameters',
domain=[('model', '=', 'sql.file.wizard')]) domain=[('model', '=', 'sql.file.wizard')])
encoding = fields.Selection(
[('utf-8', 'utf-8'), ('utf-16', 'utf-16'),
('windows-1252', 'windows-1252'), ('latin1', 'latin1'),
('latin2', 'latin2'), ('big5', 'big5'), ('gb18030', 'gb18030'),
('shift_jis', 'shift_jis'), ('windows-1251', 'windows-1251'),
('koir8_r', 'koir8_r')], string='Encoding', required=True,
default='utf-8')
@api.multi @api.multi
def export_sql_query(self): def export_sql_query(self):
self.ensure_one() self.ensure_one()

1
sql_export/views/sql_export_view.xml

@ -25,6 +25,7 @@
</group> </group>
<group name="option" groups="sql_request_abstract.group_sql_request_user"> <group name="option" groups="sql_request_abstract.group_sql_request_user">
<field name="copy_options"/> <field name="copy_options"/>
<field name="encoding"/>
</group> </group>
<group name="request" string="SQL Request" groups="sql_request_abstract.group_sql_request_user"> <group name="request" string="SQL Request" groups="sql_request_abstract.group_sql_request_user">
<field name="query" nolabel="1" placeholder="select * from res_partner"/> <field name="query" nolabel="1" placeholder="select * from res_partner"/>

3
sql_export/wizard/wizard_file.py

@ -89,7 +89,8 @@ class SqlFileWizard(models.TransientModel):
res = sql_export._execute_sql_request( res = sql_export._execute_sql_request(
params=variable_dict, mode='stdout', params=variable_dict, mode='stdout',
copy_options=sql_export.copy_options) copy_options=sql_export.copy_options)
if self.sql_export_id.encoding:
res = res.encode(self.sql_export_id.encoding)
self.write({ self.write({
'binary_file': res, 'binary_file': res,
'file_name': sql_export.name + '_' + date + '.csv' 'file_name': sql_export.name + '_' + date + '.csv'

Loading…
Cancel
Save