From 6b6856ddb6d306a0acc24fc45c56f2c658ed0ab3 Mon Sep 17 00:00:00 2001 From: vra Date: Wed, 22 Sep 2010 17:58:48 +0530 Subject: [PATCH] [ADD][IMP] account: create a payment or receipt voucher from bank statement with some improvement. bzr revid: vra@tinyerp.com-20100922122848-4eh1tk79x9qpiiyh --- addons/account_voucher/voucher.py | 16 ++++++++-- .../wizard/account_statement_from_invoice.py | 31 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index d90954f9e5b..e5b251a7d1a 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -529,7 +529,7 @@ class account_voucher(osv.osv): return {'value':res} def action_move_line_create(self, cr, uid, ids, context=None): - + def _get_payment_term_lines(term_id, amount): term_pool = self.pool.get('account.payment.term') if term_id and amount: @@ -648,7 +648,7 @@ class account_voucher(osv.osv): if line.move_line_id.id: rec_ids = [master_line, line.move_line_id.id] rec_list_ids.append(rec_ids) - + if not self.pool.get('res.currency').is_zero(cr, uid, inv.currency_id, line_total): diff = line_total move_line = { @@ -819,7 +819,9 @@ class account_bank_statement(osv.osv): def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, next_number, context=None): st_line = self.pool.get('account.bank.statement.line').browse(cr, uid, st_line_id, context=context) if st_line.voucher_id: - self.pool.get('account.voucher').proforma_voucher(cr, uid, [st_line.voucher_id.id], context={'force_name': next_number}) + #self.pool.get('account.voucher').proforma_voucher(cr, uid, [st_line.voucher_id.id], context={'force_name': next_number}) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', st_line.voucher_id.id, 'proforma_voucher', cr) return self.pool.get('account.move.line').write(cr, uid, [x.id for x in st_line.voucher_id.move_ids], {'statement_id': st_line.statement_id.id}, context=context) return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line, company_currency_id, next_number, context=context) @@ -853,4 +855,12 @@ class account_bank_statement_line(osv.osv): } + def unlink(self, cr, uid, ids, context=None): + statement_line = self.browse(cr, uid, ids, context) + unlink_ids = [] + for st_line in statement_line: + unlink_ids.append(st_line.voucher_id.id) + self.pool.get('account.voucher').unlink(cr, uid, unlink_ids, context=context) + return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context) + account_bank_statement_line() diff --git a/addons/account_voucher/wizard/account_statement_from_invoice.py b/addons/account_voucher/wizard/account_statement_from_invoice.py index a26e5b9607e..eb88ae5222c 100644 --- a/addons/account_voucher/wizard/account_statement_from_invoice.py +++ b/addons/account_voucher/wizard/account_statement_from_invoice.py @@ -47,12 +47,14 @@ class account_statement_from_invoice_lines(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') line_date = time.strftime('%Y-%m-%d') statement = statement_obj.browse(cr, uid, statement_id, context=context) # for each selected move lines for line in line_obj.browse(cr, uid, line_ids, context=context): + voucher_res = {} ctx = context.copy() # take the date for computation of currency => use payment date ctx['date'] = line_date @@ -69,10 +71,29 @@ class account_statement_from_invoice_lines(osv.osv_memory): elif (line.invoice and line.invoice.currency_id.id <> statement.currency.id): amount = currency_obj.compute(cr, uid, line.invoice.currency_id.id, statement.currency.id, amount, context=ctx) + + voucher_res = { 'type':(amount < 0 and 'payment' or 'receipt') , + 'name': line.name, + 'partner_id': line.partner_id.id, + 'journal_id': statement.journal_id.id, + 'account_id': line.account_id.id, + 'company_id':statement.company_id.id, + 'currency_id':statement.currency.id, + 'date':line.date, + '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=(amount < 0 and 'payment' or 'receipt')) + 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 -# reconcile_id = statement_reconcile_obj.create(cr, uid, { -# 'line_ids': [(6, 0, [line.id])] -# }, context=context) + if voucher_line_dict: + voucher_line_dict.update({'voucher_id':voucher_id}) + voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) if line.journal_id.type == 'sale': type = 'customer' elif line.journal_id.type == 'purchase': @@ -87,7 +108,7 @@ class account_statement_from_invoice_lines(osv.osv_memory): 'account_id': line.account_id.id, 'statement_id': statement_id, 'ref': line.ref, -# 'reconcile_id': reconcile_id, + 'voucher_id': voucher_id, 'date': time.strftime('%Y-%m-%d'), #time.strftime('%Y-%m-%d'), #line.date_maturity or, }, context=context) return {}