跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    Trades
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    获取演示
  • 定价
  • 技术支持

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

  • 客户关系管理
  • e-Commerce
  • 会计
  • 库存
  • PoS
  • 项目
  • MRP
All apps
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

generate xls or csv file

订阅

此帖文有活动时,接收通知

此问题已终结
csvxlsodoo8.0
1 回复
9842 查看
形象
Abderrahmen

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

0
形象
丢弃
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

形象
Rihene
最佳答案

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
形象
丢弃
Abderrahmen
编写者

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 ;)

喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
customization on base export functionality
export csv xls
形象
0
9月 18
4569
TypeError: error.data.arguments is undefined
csv typeerror odoo8.0 importing data from excel file
形象
0
1月 17
5872
Custom Import method - how to ?
import csv order.lines odoo8.0
形象
形象
2
2月 16
8695
how to implement joint piece in odoo 8 in one view
odoo8.0
形象
0
4月 24
2582
what is the reason behind extra move? in stock
odoo8.0
形象
形象
形象
形象
4
11月 23
6732
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • Github
  • Runbot
  • 翻译
服务
  • Odoo.sh 托管
  • 支持
  • 升级
  • 自定义开发服务
  • 教育
  • 查找会计服务
  • 寻找合作伙伴
  • 成为合作伙伴
关于我们
  • 我们的公司
  • 品牌资产
  • 联系我们
  • 招聘
  • 近期活动
  • 播客
  • 博客
  • 客户
  • 法律 • 隐私
  • 安全
الْعَرَبيّة 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致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

Odoo独特的价值在于是一款非常容易使用又完全集成的应用。

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