diff --git a/addons/account_coda/wizard/account_coda_import.py b/addons/account_coda/wizard/account_coda_import.py index a577e47be74..badd7ca77c6 100644 --- a/addons/account_coda/wizard/account_coda_import.py +++ b/addons/account_coda/wizard/account_coda_import.py @@ -206,42 +206,47 @@ class account_coda_import(osv.osv_memory): lines = statement.get('bank_statement_line',False) if lines: for value in lines: + journal = journal_obj.browse(cr, uid, statement['journal_id'], context=context) line = lines[value] + if not line['partner_id']: + line['partner_id'] = journal.company_id.partner_id.id voucher_id = False + rec_id = False if line.get('toreconcile',False): # Fix me name = line['name'][:3] + '/' + line['name'][3:7] + '/' + line['name'][7:] rec_id = self.pool.get('account.move.line').search(cr, uid, [('name', '=', name), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)]) if rec_id: + result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line['partner_id'], journal_id=statement['journal_id'], price=abs(line['amount']), currency_id = journal.company_id.currency_id.id, ttype=(line['amount'] < 0 and 'payment' or 'receipt'), context=context) voucher_res = { 'type':(line['amount'] < 0 and 'payment' or 'receipt') , 'name': line['name'],#line.name, 'partner_id': line['partner_id'] ,#line.partner_id.id, 'journal_id': statement['journal_id'], #statement.journal_id.id, - 'account_id': line['account_id'],#line.account_id.id, - 'company_id': statement['company_id'],#statement.company_id.id, - 'currency_id': statement['currency'],#statement.currency.id, + 'account_id': result.get('account_id', journal.default_credit_account_id.id),#line.account_id.id, + 'company_id': journal.company_id.id,#statement.company_id.id, + 'currency_id': journal.company_id.currency_id.id,#statement.currency.id, 'date': line['date'], #line.date, 'amount':abs(line['amount']), 'period_id':statement.get('period_id',False) or period,# statement.period_id.id } voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context) context.update({'move_line_ids': rec_id}) - result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype=(amount < 0 and 'payment' or 'receipt'), context=context) + voucher_line_dict = False if result['value']['line_ids']: for line_dict in result['value']['line_ids']: move_line = line_obj.browse(cr, uid, line_dict['move_line_id'], context) if line.move_id.id == move_line.move_id.id: voucher_line_dict = line_dict - + if voucher_line_dict: voucher_line_dict.update({'voucher_id':voucher_id}) voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) - - # reconcile_id = statement_reconcile_obj.create(cr, uid, { - # 'line_ids': [(6, 0, rec_id)] - # }, context=context) - # - + + # reconcile_id = statement_reconcile_obj.create(cr, uid, { + # 'line_ids': [(6, 0, rec_id)] + # }, context=context) + # + mv = self.pool.get('account.move.line').browse(cr, uid, rec_id[0], context=context) if mv.partner_id: line['partner_id'] = mv.partner_id.id @@ -249,20 +254,20 @@ class account_coda_import(osv.osv_memory): line['account_id'] = mv.partner_id.property_account_payable.id else : line['account_id'] = mv.partner_id.property_account_receivable.id - str_not1 = '' - if line.has_key('contry_name') and line.has_key('cntry_number'): - str_not1="Partner name:%s \n Partner Account Number:%s \n Communication:%s \n Value Date:%s \n Entry Date:%s \n"%(line["contry_name"], line["cntry_number"], line["free_comm"]+line['extra_note'], line["val_date"][0], line["entry_date"][0]) - id = bank_statement_line_obj.create(cr, uid, { - 'name':line['name'], - 'date': line['date'], - 'amount': line['amount'], - 'partner_id':line['partner_id'] or 0, - 'account_id':line['account_id'], - 'statement_id': bk_st_id, - 'voucher_id': voucher_id, - 'note':str_not1, - 'ref':line['ref'], - }) + str_not1 = '' + if line.has_key('contry_name') and line.has_key('cntry_number'): + str_not1="Partner name:%s \n Partner Account Number:%s \n Communication:%s \n Value Date:%s \n Entry Date:%s \n"%(line["contry_name"], line["cntry_number"], line["free_comm"]+line['extra_note'], line["val_date"][0], line["entry_date"][0]) + id = bank_statement_line_obj.create(cr, uid, { + 'name':line['name'], + 'date': line['date'], + 'amount': line['amount'], + 'partner_id':line['partner_id'], + 'account_id':line['account_id'], + 'statement_id': bk_st_id, + 'voucher_id': voucher_id, + 'note':str_not1, + 'ref':line['ref'], + }) str_not = "\n \n Account Number: %s \n Account Holder Name: %s " %(statement["acc_number"], statement["acc_holder"]) std_log += "\nStatement : %s , Date : %s, Starting Balance : %.2f , Ending Balance : %.2f \n"\ diff --git a/addons/l10n_ch/wizard/bvr_import.py b/addons/l10n_ch/wizard/bvr_import.py index 9d055bcfb5f..d15b66b92ce 100644 --- a/addons/l10n_ch/wizard/bvr_import.py +++ b/addons/l10n_ch/wizard/bvr_import.py @@ -72,10 +72,11 @@ def _reconstruct_invoice_ref(cursor, user, reference, context=None): def _import(obj, cursor, user, data, context=None): pool = pooler.get_pool(cursor.dbname) + statement_obj = pool.get('account.bank.statement') statement_line_obj = pool.get('account.bank.statement.line') # statement_reconcile_obj = pool.get('account.bank.statement.reconcile') - voucher_obj = self.pool.get('account.voucher') - voucher_line_obj = self.pool.get('account.voucher.line') + voucher_obj = pool.get('account.voucher') + voucher_line_obj = pool.get('account.voucher.line') move_line_obj = pool.get('account.move.line') property_obj = pool.get('ir.property') model_fields_obj = pool.get('ir.model.fields') @@ -137,23 +138,18 @@ def _import(obj, cursor, user, data, context=None): total_cost += record['cost'] records.append(record) - model_fields_ids = model_fields_obj.search(cursor, user, [ - ('name', 'in', ['property_account_receivable', 'property_account_payable']), - ('model', '=', 'res.partner'), - ], context=context) - property_ids = property_obj.search(cursor, user, [ - ('fields_id', 'in', model_fields_ids), - ('res_id', '=', False), - ], context=context) - +# model_fields_ids = model_fields_obj.search(cursor, user, [ +# ('name', 'in', ['property_account_receivable', 'property_account_payable']), +# ('model', '=', 'res.partner'), +# ], context=context) +# property_ids = property_obj.search(cursor, user, [ +# ('fields_id', 'in', model_fields_ids), +# ('res_id', '=', False), +# ], context=context) account_receivable = False account_payable = False - for property in property_obj.browse(cursor, user, property_ids, context=context): - if property.fields_id.name == 'property_account_receivable': - account_receivable = int(property.value.split(',')[1]) - elif property.fields_id.name == 'property_account_payable': - account_payable = int(property.value.split(',')[1]) - + statement = statement_obj.browse(cursor, user, statement_id, context=context) + for record in records: # Remove the 11 first char because it can be adherent number # TODO check if 11 is the right number @@ -166,6 +162,7 @@ def _import(obj, cursor, user, data, context=None): 'type': (record['amount'] >= 0 and 'customer') or 'supplier', 'statement_id': statement_id, } + line_ids = move_line_obj.search(cursor, user, [ ('ref', 'like', reference), ('reconcile_id', '=', False), @@ -178,8 +175,10 @@ def _import(obj, cursor, user, data, context=None): partner_id = False account_id = False for line in move_line_obj.browse(cursor, user, line_ids, context=context): - if line.partner_id.id: - partner_id = line.partner_id.id + account_receivable = line.partner_id.property_account_receivable.id + account_payable = line.partner_id.property_account_payable.id + partner_id = line.partner_id.id + move_id = line.move_id.id if record['amount'] >= 0: if round(record['amount'] - line.debit, 2) < 0.01: line2reconcile = line.id @@ -190,6 +189,32 @@ def _import(obj, cursor, user, data, context=None): line2reconcile = line.id account_id = line.account_id.id break + result = voucher_obj.onchange_partner_id(cursor, user, [], partner_id=partner_id, journal_id=statement.journal_id.id, price=abs(record['amount']), currency_id= statement.currency.id, ttype='payment', context=context) + + voucher_res = { 'type': 'payment' , + 'name': values['name'], + 'partner_id': partner_id, + 'journal_id': statement.journal_id.id, + 'account_id': result.get('account_id', statement.journal_id.default_credit_account_id.id), + 'company_id': statement.company_id.id, + 'currency_id': statement.currency.id, + 'date': record['date'] or time.strftime('%Y-%m-%d'), + 'amount': abs(record['amount']), + 'period_id': statement.period_id.id + } + voucher_id = voucher_obj.create(cursor, user, voucher_res, context=context) + context.update({'move_line_ids': line_ids}) + values['voucher_id'] = voucher_id + voucher_line_dict = False + if result['value']['line_ids']: + for line_dict in result['value']['line_ids']: + move_line = move_line_obj.browse(cursor, user, line_dict['move_line_id'], context) + if move_id == move_line.move_id.id: + voucher_line_dict = line_dict + if voucher_line_dict: + voucher_line_dict.update({'voucher_id':voucher_id}) + voucher_line_obj.create(cursor, user, voucher_line_dict, context=context) + if not account_id: if record['amount'] >= 0: account_id = account_receivable @@ -201,31 +226,6 @@ def _import(obj, cursor, user, data, context=None): values['account_id'] = account_id values['partner_id'] = partner_id - if line2reconcile: - voucher_res = { 'type': 'payment' , - 'name': line.name, - 'partner_id': line.partner_id.id, - 'journal_id': statement.journal_id.id, - 'account_id': account, - 'company_id': statement.company_id.id, - 'currency_id': statement.currency.id, - 'date': line.date or time.strftime('%Y-%m-%d'), - 'amount': abs(amount), - 'period_id': statement.period_id.id - } - voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context) - context.update({'move_line_ids': line_ids}) - result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment', context=context) - voucher_line_dict = False - if result['value']['line_ids']: - for line_dict in result['value']['line_ids']: - move_line = self.pool.get('account.move.line').browse(cr, uid, line_dict['move_line_id'], context) - if line.move_line_id.move_id.id == move_line.move_id.id: - voucher_line_dict = line_dict - if voucher_line_dict: - voucher_line_dict.update({'voucher_id':voucher_id}) - voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) - values['voucher_id'] = voucher_id # values['reconcile_id'] = statement_reconcile_obj.create(cursor, user, { # 'line_ids': [(6, 0, [line2reconcile])], # }, context=context)