diff --git a/addons/account_coda/wizard/account_coda_import.py b/addons/account_coda/wizard/account_coda_import.py index 8861c79e80e..4bfddb70608 100644 --- a/addons/account_coda/wizard/account_coda_import.py +++ b/addons/account_coda/wizard/account_coda_import.py @@ -61,7 +61,6 @@ class account_coda_import(osv.osv_memory): bank_statement_obj = self.pool.get('account.bank.statement') move_line_obj = self.pool.get('account.move.line') bank_statement_line_obj = self.pool.get('account.bank.statement.line') -# statement_reconcile_obj = self.pool.get('account.bank.statement.reconcile') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') account_coda_obj = self.pool.get('account.coda') diff --git a/addons/account_payment/__openerp__.py b/addons/account_payment/__openerp__.py index 5114a576512..ff84c893d1e 100644 --- a/addons/account_payment/__openerp__.py +++ b/addons/account_payment/__openerp__.py @@ -33,7 +33,7 @@ * a basic mechanism to easily plug various automated payment. """, 'author': 'OpenERP SA', - 'depends': ['account'], + 'depends': ['account_voucher'], 'init_xml': [], 'update_xml': [ 'security/account_payment_security.xml', diff --git a/addons/account_payment/wizard/account_payment_populate_statement.py b/addons/account_payment/wizard/account_payment_populate_statement.py index 38d742119ad..0e7ea32e8d3 100644 --- a/addons/account_payment/wizard/account_payment_populate_statement.py +++ b/addons/account_payment/wizard/account_payment_populate_statement.py @@ -19,6 +19,7 @@ # ############################################################################## +import time from lxml import etree from osv import osv, fields @@ -53,7 +54,9 @@ class account_payment_populate_statement(osv.osv_memory): statement_obj = self.pool.get('account.bank.statement') statement_line_obj = self.pool.get('account.bank.statement.line') currency_obj = self.pool.get('res.currency') - statement_reconcile_obj = self.pool.get('account.bank.statement.reconcile') + voucher_obj = self.pool.get('account.voucher') + voucher_line_obj = self.pool.get('account.voucher.line') + if context is None: context = {} data = self.read(cr, uid, ids, [])[0] @@ -68,11 +71,37 @@ class account_payment_populate_statement(osv.osv_memory): ctx['date'] = line.ml_maturity_date # was value_date earlier,but this field exists no more now amount = currency_obj.compute(cr, uid, line.currency.id, statement.currency.id, line.amount_currency, context=ctx) + if line.partner_id: +# line['partner_id'] = mv.partner_id.id + if amount < 0 : + account = line.partner_id.property_account_payable.id + else : + account = line.partner_id.property_account_receivable.id if line.move_line_id: - reconcile_id = statement_reconcile_obj.create(cr, uid, { - 'line_ids': [(6, 0, [line.move_line_id.id])] - }, context=context) + 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) + 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') + 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) + st_line_id = statement_line_obj.create(cr, uid, { 'name': line.order_id.reference or '?', 'amount': - amount, @@ -81,8 +110,9 @@ class account_payment_populate_statement(osv.osv_memory): 'account_id': line.move_line_id.account_id.id, 'statement_id': statement.id, 'ref': line.communication, - 'reconcile_id': reconcile_id, + 'voucher_id': voucher_id, }, context=context) + line_obj.write(cr, uid, [line.id], {'bank_statement_line_id': st_line_id}) return {'type': 'ir.actions.act_window_close'} diff --git a/addons/l10n_ch/__openerp__.py b/addons/l10n_ch/__openerp__.py index 1af2e70ca59..a9315abdf55 100644 --- a/addons/l10n_ch/__openerp__.py +++ b/addons/l10n_ch/__openerp__.py @@ -75,6 +75,7 @@ TODO : "base_vat", "base_iban", "account_payment", + "account_voucher", ], "init_xml" : [ "dta_data.xml", diff --git a/addons/l10n_ch/wizard/bvr_import.py b/addons/l10n_ch/wizard/bvr_import.py index 50eb6864381..611b5720a96 100644 --- a/addons/l10n_ch/wizard/bvr_import.py +++ b/addons/l10n_ch/wizard/bvr_import.py @@ -73,7 +73,9 @@ def _import(obj, cursor, user, data, context=None): pool = pooler.get_pool(cursor.dbname) statement_line_obj = pool.get('account.bank.statement.line') - statement_reconcile_obj = pool.get('account.bank.statement.reconcile') +# 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') move_line_obj = pool.get('account.move.line') property_obj = pool.get('ir.property') model_fields_obj = pool.get('ir.model.fields') @@ -200,9 +202,32 @@ def _import(obj, cursor, user, data, context=None): values['partner_id'] = partner_id if line2reconcile: - values['reconcile_id'] = statement_reconcile_obj.create(cursor, user, { - 'line_ids': [(6, 0, [line2reconcile])], - }, context=context) + 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) + 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') + 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) statement_line_obj.create(cursor, user, values, context=context) attachment_obj.create(cursor, user, {