Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

generate xls or csv file

Subscribe

Get notified when there's activity on this post

This question has been flagged
csvxlsodoo8.0
1 Reply
9856 Views
Avatar
Abderrahmen

Plz i need to know how can i generate xls or csv file filled with data for exemple an array. Thank you.

0
Avatar
Discard
OdooBot
Thank you friend,
the thing is, creating a file is not a problem but my probleme that i want to generate a file after click event in a button to show the save file window. 

2015-11-19 19:45 GMT+01:00 Drees Far <far.drees@gmail.com>:

A new answer for generate xls or csv file has been posted. Click here to access the post.

--
Drees Far
Sent by Odoo S.A. using Odoo about Forum Post generate xls or csv file



--

 

Abderrahmen KHALLEDI
Développeur Odoo/OpenERP
Villa n°5, rue Haroun El Rachid Mutuelle ville
Tél. : +216 55 521 232
Mail : abderrahmen@techcare.tn
Linkedin : tn.linkedin.com/in/abderrahmenkhalledi/
Site : http://www.techcare-group.tn

Avatar
Rihene
Best Answer

Hello my friend;

here is some useful links that can help you a lot:

http://stackoverflow.com/questions/2084069/create-a-csv-file-with-values-from-a-python-list

http://stackoverflow.com/questions/14037540/writing-a-python-list-of-lists-to-a-csv-file

http://gis.stackexchange.com/questions/72458/export-list-of-values-into-csv-or-txt-file

https://docs.python.org/2/library/csv.html

You can use the ir.attachment module. I fact, you will create a .csv file in your pc and then a button which will call a function that you define in you python.And here is an example:

def print_declaration(self, cr, uid, ids, id, context=None):

print ids

dec = self.pool.get('declaration.cnss')

obj = dec.search(cr, uid, [('id','in', ids)])

cns = dec.read(cr, uid, obj, ['id', 'year','trimester','company_id'], context=False)

year = cns[0]['year']

company = cns[0]['company_id'][0]

print company

trimester = cns[0]['trimester']

filename="/opt/file.txt"

lines = open(filename).readlines()  

open(filename, 'w').writelines(lines[-1:-1])

writepath = '/opt/file.txt'

mode = 'a' if os.path.exists(writepath) else 'w' 

var = 0

i = 0

j = 0

page =1

res_list=[]

payslip_line = self.pool.get('hr.payslip')

obj_ids = payslip_line.search(cr, uid, [('company_id','=', company)]) 

for res in payslip_line.read(cr, uid, obj_ids, ['id', 'employee_id','date_from'], context=False):

date = res['date_from']

var = var + 1

if var == 12:

var = 1

obj = {}

obj['matricule'] = res['employee_id'][0]

a = str(obj['matricule'])

obj['numero'] = var

matricule = res['employee_id'][0]

obj['name'] = res['employee_id'][1]

payslip_lines = self.pool.get('hr.employee')

obj_ids2 = payslip_lines.search(cr, uid, [('id', '=', matricule)])

for res in payslip_lines.read(cr, uid, obj_ids2, ['id', 'n_cnss', 'momo_category','address_id','name_employee','surname_emloyee','name_fother','marital','gender','nic_id'], context=False):

marital = res['marital']

gender = res['gender']

nom_employe = res['name_employee']

prenom_employe = res['surname_emloyee']

nom_pere = res['name_fother']

if nom_employe== False:

My_error_Msg = 'Please, enter the name of your employee'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

if prenom_employe== False:

My_error_Msg = 'Please, enter the surname of your employee'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

if nom_pere== False:

My_error_Msg = 'Please, enter the surname of your Employee Fother'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

nom = prenom_employe+''+nom_employe

if gender=='male':

nom = prenom_employe+' B '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='single':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='married':

nom = prenom_employe+ ' ' +nom_employe

if gender=='female' and marital=='widower':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='divorced':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

company = self.pool.get('res.partner')

company_ids = company.search(cr, uid, [('id','=',res['address_id'][0])]) 

for test in company.read(cr, uid, company_ids, ['id', 'company_id'], context=False):

companys = self.pool.get('res.company')

companys_ids = companys.search(cr, uid, [('id','=',test['company_id'][0])])

for tests in companys.read(cr, uid, company_ids, ['id', 'cnss'], context=False):

j = j + 1

if j %12==0:

page = page +1

c = str(0)

d = str(page)

pages = c+c+d

var1 = map(int, str(tests['cnss']))

var2 = var1[-1]

var3 = var1[-2]

var4 = int(str(var3) + str(var2))

var5 = var1.remove(var2)

var6 = var1.remove(var3)

s = map(str, var1)

s = ''.join(s)

s = int(s)

obj['matricule_employeur'] = s

obj['cle_employeur'] = var4

test = str(var4)

test2 = str(s)

test2 = '00'+test2

if len (test2) <> 8:

My_error_Msg = 'Taille de la matricule CNSS non compatible'

raise osv.except_osv(_("Erreur!"), _(My_error_Msg))

return False

taux_cotisation = str(0000)

variable1 = map(int, str(res['n_cnss']))

variable2 = variable1[-1]

variable3 = variable1[-2]

variable4 = int(str(variable3) + str(variable2))

cle_assure = variable4

variable5 = variable1.remove(variable2)

variable6 = variable1.remove(variable3)

matricule_assure = map(str, variable1)

matricule_assure = ''.join(matricule_assure)

if len (matricule_assure) <> 8:

My_error_Msg = 'Taille du numero Assure social non compatible'

raise osv.except_osv(_("Erreur!"), _(My_error_Msg))

return False

matricules_assure = str(matricule_assure)

cles_assure = str(cle_assure)

print ('---------------------------en test--------------------------------')

marital = res['marital']

gender = res['gender']

nom_employe = res['name_employee']

prenom_employe = res['surname_emloyee']

nom_pere = res['name_fother']

if nom_employe== False:

My_error_Msg = 'Please, enter the name of your employee'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

if prenom_employe== False:

My_error_Msg = 'Please, enter the surname of your employee'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

if nom_pere== False:

My_error_Msg = 'Please, enter the surname of your Employee Fother'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

nom = prenom_employe+''+nom_employe

if gender=='male':

nom = prenom_employe+' B '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='single':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='married':

nom = prenom_employe+ ' ' +nom_employe

if gender=='female' and marital=='widower':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

if gender=='female' and marital=='divorced':

nom = prenom_employe+' BT '+nom_pere+ ' ' +nom_employe

if len(nom) > 60:

My_error_Msg = 'Please, The size of your employee name is incorrect'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

num_cin = res['nic_id']

cin = str(num_cin)

if num_cin ==False:

My_error_Msg = 'Please, enter the CIN of your employee'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

if len(cin) > 8:

My_error_Msg = 'Please, the size of the CIN of your employee is incorrect'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return False

taille_nom = len(nom)

nbr_espace = 60 - taille_nom

for i in range (nbr_espace):

nom = nom+' '

if taille_nom < 60:

nom = nom+''

brut_line = self.pool.get('declaration.cnss.line')

brut_ids= brut_line.search(cr, uid, [])

somme_brut1 = 0

somme_brut2 = 0

somme_brut3 = 0

for res in brut_line.read(cr, uid, brut_ids, ['id', 'brut','brut2','brut3'], context=False):

obj['brut'] = res['brut']

obj['brut2'] = res['brut2']

obj['brut3'] = res['brut3']

somme_brut1 = somme_brut1 + res['brut']

somme_brut2 = somme_brut2 + res['brut2']

somme_brut3 = somme_brut3 + res['brut3']

somme = res['brut'] + res['brut2'] + res['brut3']

somme_brut = somme_brut1 + somme_brut2 + somme_brut3

sommes = 1000*somme

obj['somme_brut1'] = somme_brut1

obj['somme_brut2'] = somme_brut2

obj['somme_brut3'] = somme_brut3

obj['somme_brut'] = somme_brut

obj['somme'] = sommes

salaire = str(int(sommes))

nbr_espace2 = 10 - len (salaire)

j = 0

for j in range (nbr_espace2):

salaire = '0'+salaire

a = str(var)

b = str(0)

ligne = b+a

print len (test2+test+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+trimester+year+pages+ligne+matricules_assure+cles_assure+nom+cin+salaire+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation)

with open(writepath, mode) as f:

f.write(test2+test+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+trimester+year+pages+ligne+matricules_assure+cles_assure+nom+cin+salaire+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+taux_cotisation+'\n')

res_list.append(obj)

filename="/opt/file.txt"

files = open(filename,'rb').read()

point = "."

nom_fichier = "DS"+test2+test+taux_cotisation+taux_cotisation+taux_cotisation+str(6)+point+trimester+year

files = open(filename,'rb').read().encode('base64')

ir_values={

'name': nom_fichier,

'datas_fname': nom_fichier,

'type': 'binary',

'datas': files,

'create_uid': uid,

# 'partner_id': ids[0],

'res_model': 'declaration.cnss',

'res_id': ids[0],

} 

self.pool.get('ir.attachment').create(cr,uid,ir_values,context=context)

here is an example that i have wirked with but a text file and i am certain that it will work with the csv

Best Regards.

1
Avatar
Discard
Abderrahmen
Author

Thank you my friend, the thing is, creating a file is not a problem but my probleme that i want to generate a file after click event in a button to show the save file window.

Rihene

its an example of a file that i have created and it works perfectly :) plz vote and upvote ;)

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
customization on base export functionality
export csv xls
Avatar
0
Sep 18
4582
TypeError: error.data.arguments is undefined
csv typeerror odoo8.0 importing data from excel file
Avatar
0
Jan 17
5876
Custom Import method - how to ?
import csv order.lines odoo8.0
Avatar
Avatar
2
Feb 16
8703
how to implement joint piece in odoo 8 in one view
odoo8.0
Avatar
0
Apr 24
2593
what is the reason behind extra move? in stock
odoo8.0
Avatar
Avatar
Avatar
Avatar
4
Nov 23
6750
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now