From f9d82dd54ba1e5cbbe88e7126a8c37600aadf9ad Mon Sep 17 00:00:00 2001 From: "Vir (Open ERP)" Date: Wed, 28 Apr 2010 10:32:51 +0530 Subject: [PATCH 1/5] [ADD,MOD] account : wizard account_reconcile converted to osv memory wizard bzr revid: vir@tinyerp.com-20100428050251-n8ovgsu92caqt3yi --- addons/account/__openerp__.py | 1 + addons/account/account_wizard.xml | 2 +- addons/account/wizard/__init__.py | 2 +- addons/account/wizard/account_reconcile.py | 207 ++++++++++++++++++ .../account/wizard/account_reconcile_view.xml | 108 +++++++++ addons/account/wizard/wizard_reconcile.py | 150 ------------- 6 files changed, 318 insertions(+), 152 deletions(-) create mode 100644 addons/account/wizard/account_reconcile.py create mode 100644 addons/account/wizard/account_reconcile_view.xml delete mode 100644 addons/account/wizard/wizard_reconcile.py diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index ee9430a7334..fb4ad1f3d3b 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -80,6 +80,7 @@ module named account_voucherss 'wizard/account_aged_trial_balance_view.xml', 'wizard/account_compare_account_balance_report_view.xml', 'wizard/account_third_party_ledger.xml', + 'wizard/account_reconcile_view.xml', 'wizard/account_automatic_reconcile_view.xml', 'project/wizard/project_account_analytic_line_view.xml', 'account_end_fy.xml', diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml index b80269ab6f1..8b093fb2310 100644 --- a/addons/account/account_wizard.xml +++ b/addons/account/account_wizard.xml @@ -47,7 +47,7 @@ - + diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index f42750f685d..39971f5c11a 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -22,7 +22,7 @@ import account_automatic_reconcile import account_move_line_reconcile_select import account_move_line_unreconcile_select -import wizard_reconcile +import account_reconcile import account_unreconcile import account_invoice_refund import account_pay_invoice diff --git a/addons/account/wizard/account_reconcile.py b/addons/account/wizard/account_reconcile.py new file mode 100644 index 00000000000..1f745419c5a --- /dev/null +++ b/addons/account/wizard/account_reconcile.py @@ -0,0 +1,207 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import time +import datetime + +from osv import fields, osv +from tools.translate import _ + +class account_move_line_reconcile_prompt(osv.osv_memory): + """ + Asks user he wants to reconcile entries or not. + """ + _name = 'account.move.line.reconcile.prompt' + _description = 'Account move line reconcile' + _columns = { + } + + def ask_reconcilation(self, cr, uid, ids, context): + return self.pool.get('account.move.line.reconcile').partial_check(cr, uid, ids, context) + +account_move_line_reconcile_prompt() + +class account_move_line_reconcile(osv.osv_memory): + """ + Account move line reconcile wizard, it checks for the write off the reconcile entry or directly reconcile. + """ + _name = 'account.move.line.reconcile' + _description = 'Account move line reconcile' + _columns = { + 'trans_nbr': fields.integer('# of Transaction', readonly=True), + 'credit': fields.float('Credit amount',readonly=True), + 'debit': fields.float('Debit amount',readonly=True), + 'writeoff': fields.float('Write-Off amount',readonly=True), + } + + def default_get(self, cr, uid, fields, context=None): + res = super(account_move_line_reconcile, self).default_get(cr, uid, fields, context=context) + data = self.trans_rec_get(cr, uid, context['active_ids'], context) + if 'trans_nbr' in fields: + res.update({'trans_nbr':data['trans_nbr']}) + if 'credit' in fields: + res.update({'trans_nbr':data['credit']}) + if 'debit' in fields: + res.update({'trans_nbr':data['debit']}) + if 'writeoff' in fields: + res.update({'trans_nbr':data['writeoff']}) + return res + + def partial_check(self, cr, uid, ids, context=None): + mod_obj = self.pool.get('ir.model.data') + data = self.trans_rec_get(cr, uid, ids, context) + if context is None: + context = {} + if data['writeoff'] == 0: + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_move_line_reconcile_full')], context=context) + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + return { + 'name': _('Reconcile'), + 'context': context, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'account.move.line.reconcile', + 'views': [(resource_id,'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + } + else : + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_move_line_reconcile_partial')], context=context) + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + return { + 'name': _('Reconcile'), + 'context': context, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'account.move.line.reconcile', + 'views': [(resource_id,'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + } + + def trans_rec_get(self, cr, uid, ids, context=None): + account_move_line_obj = self.pool.get('account.move.line') + if context is None: + context = {} + credit = debit = 0 + account_id = False + count = 0 + for line in account_move_line_obj.browse(cr, uid, context['active_ids'], context=context): + if not line.reconcile_id and not line.reconcile_id.id: + count += 1 + credit += line.credit + debit += line.debit + account_id = line.account_id.id + return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit} + + def trans_rec_addendum_writeoff(self, cr, uid, ids, context=None): + return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_addendum(cr, uid, ids, context) + + def trans_rec_reconcile_partial_reconcile(self, cr, uid, ids, context=None): + return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_reconcile_partial(cr, uid, ids, context) + + def trans_rec_reconcile_full(self, cr, uid, ids, context=None): + account_move_line_obj = self.pool.get('account.move.line') + date = False + period_id = False + journal_id= False + account_id = False + + if context is None: + context = {} + + data = self.read(cr, uid, ids, context=context) + date = time.strftime('%Y-%m-%d') + ids = self.pool.get('account.period').find(cr, uid, dt=date, context=context) + if len(ids): + period_id = ids[0] + account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id, + period_id, journal_id, context=context) + return {} + +account_move_line_reconcile() + +class account_move_line_reconcile_writeoff(osv.osv_memory): + """ + It opens the write off wizard form, in that user can define the journal, account, analytic account for reconcile + """ + _name = 'account.move.line.reconcile.writeoff' + _description = 'Account move line reconcile' + _columns = { + 'journal_id': fields.many2one('account.journal','Write-Off Journal', required=True), + 'writeoff_acc_id': fields.many2one('account.account','Write-Off account', required=True), + 'date_p': fields.date('Date'), + 'comment': fields.char('Comment', size= 64, required=True), + 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'), + } + _defaults = { + 'date_p': time.strftime('%Y-%m-%d'), + 'comment': 'Write-off', + } + + def trans_rec_addendum(self, cr, uid, ids, context=None): + mod_obj = self.pool.get('ir.model.data') + if context is None: + context = {} + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','account_move_line_reconcile_writeoff')], context=context) + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + return { + 'name': _('Reconcile Writeoff'), + 'context': context, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'account.move.line.reconcile.writeoff', + 'views': [(resource_id,'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + } + + def trans_rec_reconcile_partial(self, cr, uid, ids, context=None): + account_move_line_obj = self.pool.get('account.move.line') + if context is None: + context = {} + account_move_line_obj.reconcile_partial(cr, uid, context['active_ids'], 'manual', context=context) + return {} + + def trans_rec_reconcile(self, cr, uid, ids, context=None): + account_move_line_obj = self.pool.get('account.move.line') + if context is None: + context = {} + data = self.read(cr, uid, ids,context=context)[0] + account_id = data['writeoff_acc_id'] + context['date_p'] = data['date_p'] + journal_id = data['journal_id'] + context['comment'] = data['comment'] + if data['analytic_id']: + context['analytic_id'] = data['analytic_id'] + if context['date_p']: + date = context['date_p'] + + ids = self.pool.get('account.period').find(cr, uid, dt=date, context=context) + if len(ids): + period_id = ids[0] + + account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id, + period_id, journal_id, context=context) + return {} + +account_move_line_reconcile_writeoff() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_reconcile_view.xml b/addons/account/wizard/account_reconcile_view.xml new file mode 100644 index 00000000000..0f92376e045 --- /dev/null +++ b/addons/account/wizard/account_reconcile_view.xml @@ -0,0 +1,108 @@ + + + + + + account.move.line.reconcile.prompt.form + account.move.line.reconcile.prompt + form + +
+ + +