1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
25
from datetime import datetime
28
username = 'openerp_user'
30
server_url = 'http://localhost:8069'
31
csv_path = 'hr_expense_accountedge.tsv'
33
pwd = getpass.getpass(prompt="Please enter the password of %s: " % username)
36
sock_common = xmlrpclib.ServerProxy('%s/xmlrpc/common' % server_url)
37
uid = sock_common.login(dbname, username, pwd)
40
print "Connection error. Please check the username, password and server url."
41
goodbye = raw_input("Type 'enter' to quit...")
44
# Replace localhost with the address of the server
45
sock = xmlrpclib.ServerProxy('%s/xmlrpc/object' % server_url)
47
# Search for exported expense notes
48
args = [('state', '=', 'exported')]
49
expense_ids = sock.execute(dbname, uid, pwd, 'hr.expense.expense', 'search', args)
51
print "There are %d expense sheets to import" % len(expense_ids)
54
goodbye = raw_input("Type 'enter' to quit...")
57
# Outpout file for AccountEdge
58
final_csv = open(csv_path, 'w')
62
# For each exported expense note, search for the tsv attachment
63
for expense_id in expense_ids:
65
args = [('res_model','=','hr.expense.expense'),('res_id', '=', expense_id)]
66
csv_ids = sock.execute(dbname, uid, pwd, 'ir.attachment', 'search', args)
68
fields = ['name', 'datas']
69
csv_obj = sock.execute(dbname, uid, pwd, 'ir.attachment', 'read', csv_ids, fields)
72
latest_date = datetime(2000, 1, 1, 0, 0, 0)
77
format = 'export_%Y%m%d_%H%M%S.tsv'
78
date_created = datetime.strptime(csv["name"], format)
80
if date_created > latest_date:
81
latest_date = date_created
84
# Copy the lines to the new summary file
86
content = base64.b64decode(csv['datas'])
87
content = content.split("\r\n")
90
for num_line in range(len(content)):
91
if (num_line == 1 and num_expense == 0) or num_line > 1:
92
final_csv.write(content[num_line])
93
final_csv.write("\r\n")
96
num_expense = num_expense + 1
99
# Mark the expenses as imported
100
values = {'state': 'exported'}
101
result = sock.execute(dbname, uid, pwd, 'hr.expense.expense', 'write', expense_ids, values)
105
goodbye = raw_input("Type 'enter' to quit...")
107
if __name__ == "__main__":