Community mailing list archives

community@mail.odoo.com

Re: how to save file * .txt ?

by
Dr Obx
- 02/11/2016 11:00:39
This is actually working example ;)

On 11 February 2016 at 15:41, Robert Amberwich <robert.amberwitch@gmail.com> wrote:
I think you can add a python code to save your file into a specified folder or create a wizard which will let you choose the location.
import os
import sys
should let you to it :)

[code example]
def csv_creator(self):
body = """No,Customer name,Customer surname\n"""
for order in self:
product = self.env['model_name'].browse([('id','=',self.id)])
order_line = """%s,%s,%s\n"""%(a, product.customer_name, product.customer_surname)
body += """%s""" %(order_line)
a = a + 1
#Creating and saving csv
filecontent = body
print('Creating CSV ...')
os.chdir('/your_folder_or_location/')
name = ('orders_'+subnow+'.csv')
print '== name ======================================================================================='
print '   ', name
try:
file = open(name,'w+')
print 'file ',name,' opened ;)'
file.write(filecontent)
file.close()
print '== file created ==============================================================================='
except:
print('Something went wrong! Empty file?')
[/code]
It's just an example but it may give you some ideas :)

On 11 February 2016 at 15:11, omar frikha <omarfrikha59@gmail.com> wrote:
how to create function save as??

2016-02-11 15:42 GMT+01:00 Robert Amberwich <robert.amberwitch@gmail.com>:
So if you were developed that module how's it possible that you don't know how to save it ?
I don't understand, or maybe there is another Omar Frikha who don't know how to ?


On 11 February 2016 at 13:57, omar frikha <omarfrikha59@gmail.com> wrote:

I've developed a new module that allows to generate a txt file I can save this file in my pc and not in the server

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe