Created
March 12, 2017 14:32
-
-
Save kerbrose/e7840d55186f81afdbd9b15b14d1ff3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import odoorpc | |
odoo = odoorpc.ODOO('localhost', port=8070) | |
odoo.login('progate_07032017', 'admin', 'admin') | |
move_obj = odoo.env['account.move'] | |
with open('my_cs.csv', newline='') as csvfile: | |
odoo = odoorpc.ODOO('localhost', port=8070) | |
odoo.login('progate_07032017', 'admin', 'admin') | |
move_obj = odoo.env['account.move'] | |
move = {} | |
line_ids= [] | |
partner = None | |
debit = 0 | |
credit = 0 | |
my_reader=csv.reader(csvfile, delimiter=',') | |
for index, row in enumerate(my_reader): | |
if index == 0: | |
print('escaping header') | |
continue | |
if partner != row[1]: | |
if partner: | |
final_line = [] | |
final_line.append(0) | |
final_line.append(False) | |
fl_dict = {} | |
fl_dict['account_id'] = odoo.env.ref('progate.account_account_112002').id | |
fl_dict['partner_id'] = odoo.env.ref(partner).id | |
fl_dict['name'] = 'Opening 2017' | |
fl_dict['analytic_account_id'] = '' | |
fl_balance = debit - credit | |
if fl_balance > 0: | |
fl_dict['debit'] = 0 | |
fl_dict['credit'] = fl_balance | |
if fl_balance < 0: | |
fl_dict['debit'] = abs(fl_balance) | |
fl_dict['credit'] = 0 | |
final_line.append(fl_dict) | |
line_ids.append(final_line) | |
move['journal_id'] = 1 | |
move['date'] = '2017-01-01' | |
move['ref'] = 'Opening 2017' | |
move['narration'] = False | |
move['line_ids'] = line_ids | |
checker = move_obj.create(move) | |
print(partner, "******** ") | |
print("move created", checker) | |
move.clear() | |
debit = 0 | |
credit = 0 | |
line_ids = [] | |
partner = row[1] | |
if partner == row[1]: | |
my_line = [] | |
my_line.append(0) | |
my_line.append(False) | |
line_dict = {} | |
target_account_id = row[0] | |
line_dict['account_id'] = odoo.env.ref(target_account_id).id | |
line_dict['partner_id'] = odoo.env.ref(partner).id | |
line_dict['name'] = row[2] | |
target_analytic_account_id = row[3] | |
if len(target_analytic_account_id)>0: | |
line_dict['analytic_account_id'] = odoo.env.ref(target_analytic_account_id).id | |
debit += float(row[5]) | |
line_dict['debit'] = float(row[5]) | |
credit += float(row[6]) | |
line_dict['credit'] = float(row[6]) | |
my_line.append(line_dict) | |
line_ids.append(my_line) | |
else: | |
final_line = [] | |
final_line.append(0) | |
final_line.append(False) | |
fl_dict = {} | |
fl_dict['account_id'] = odoo.env.ref('progate.account_account_112002').id | |
fl_dict['partner_id'] = odoo.env.ref(partner).id | |
fl_dict['name'] = 'Opening 2017' | |
fl_dict['analytic_account_id'] = '' | |
fl_balance = debit - credit | |
if fl_balance > 0: | |
fl_dict['debit'] = 0 | |
fl_dict['credit'] = fl_balance | |
if fl_balance < 0: | |
fl_dict['debit'] = abs(fl_balance) | |
fl_dict['credit'] = 0 | |
final_line.append(fl_dict) | |
line_ids.append(final_line) | |
move['journal_id'] = 1 | |
move['date'] = '2017-01-01' | |
move['ref'] = 'Opening 2017' | |
move['narration'] = False | |
move['line_ids'] = line_ids | |
checker = move_obj.create(move) | |
print(partner, "******** ",) | |
print("move created", checker) | |
move.clear() | |
line_ids = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment