From dfc71970c3ea911b3b6fe5d72e804c23e966cbc2 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Mon, 3 Feb 2014 08:22:31 +0100 Subject: [PATCH] [FIX+REF+IMP] account_check_deposit: * [FIX] fix datamodel structure, indeed check_payment_ids should be a m2o. In the view we still keep the widget * [REF] remove useless state cancel, only draft/done is sufficent for now, forbid to delete a done deposit, fix move_line name need to be the equal to the line.ref for the reconciliation * [IMP] improve reconciliation between the check and the check deposit * [FIX] set correctly the date on the move line generated * [FIX] fix reconciliation of check * [IMP] check deposit improve view and add tab for move line generated * [IMP] add total amount and flag to know if the deposit have been reconcile, the best will be to add a workflow * [FIX] fix error when replaying commit * [REF] remove dependency on sale_quick_payment as check can be registred in various way like native voucher * [CLEAN] pep8 cleanup no code change * [REF] clean remove useless code, default value are called during the create * [FIX] fix wrong spelling * [REF] V7 clean up --- account_check_deposit/__openerp__.py | 26 +- account_check_deposit/account_deposit.py | 262 ++++++++++-------- .../account_deposit_view.xml | 46 +-- account_check_deposit/account_type_data.xml | 4 +- .../report/report_webkit_html.py | 11 +- .../security/ir.model.access.csv | 3 +- 6 files changed, 202 insertions(+), 150 deletions(-) diff --git a/account_check_deposit/__openerp__.py b/account_check_deposit/__openerp__.py index c63a46b29..230c2e0b0 100644 --- a/account_check_deposit/__openerp__.py +++ b/account_check_deposit/__openerp__.py @@ -20,8 +20,6 @@ # # ############################################################################### - - { 'name': 'account_check_deposit', 'version': '0.1', @@ -30,21 +28,21 @@ 'description': """This module allows you to use check deposits. With a new model : account_check_deposit you can select all the checks payments and create a global deposit for the selected checks. - You may have to create an account for recieved checks and a journal for payment by checks.""", + You may have to create an account for "received checks" and a + journal for payment by checks.""", 'author': 'Akretion', 'website': 'http://www.akretion.com/', - 'depends': ['account_accountant', - 'report_webkit', - 'sale_quick_payment' - ], - 'init_xml': [], - 'update_xml': [ - 'account_deposit_view.xml', - 'account_deposit_sequence.xml', - 'account_type_data.xml', - 'security/ir.model.access.csv', + 'depends': [ + 'account_accountant', + 'report_webkit', + ], + 'data': [ + 'account_deposit_view.xml', + 'account_deposit_sequence.xml', + 'account_type_data.xml', + 'security/ir.model.access.csv', ], - 'demo_xml': [], 'installable': True, + 'application': True, 'active': False, } diff --git a/account_check_deposit/account_deposit.py b/account_check_deposit/account_deposit.py index ac8b5c2ea..49f95fdb1 100644 --- a/account_check_deposit/account_deposit.py +++ b/account_check_deposit/account_deposit.py @@ -30,148 +30,193 @@ class account_check_deposit(orm.Model): def sum_amount(self, cr, uid, ids, name, args, context=None): res = {} - total = 0 for deposit in self.browse(cr, uid, ids, context=context): + total = 0 for line in deposit.check_payment_ids: total += line.debit - res[deposit.id]= total - return res + res[deposit.id] = total + return res + def _is_reconcile(self, cr, uid, ids, name, args, context=None): + res = {} + for deposit in self.browse(cr, uid, ids, context=context): + res[deposit.id] = False + if deposit.move_id: + for line in deposit.move_id.line_id: + if line.debit > 0 and line.reconcile_id: + res[deposit.id] = True + return res _columns = { - 'name': fields.char('Name', size=64, required=True, readonly=True, - tates={'draft':[('readonly',False)]}), - 'check_payment_ids': fields.many2many('account.move.line', - 'account_move_line_deposit_rel', - 'check_deposit_id', - 'move_line_id', - 'Check Payments', - readonly=True, - states={'draft':[('readonly',False)]}), - 'deposit_date': fields.date('Deposit Date', readonly=True, - states={'draft':[('readonly',False)]}), - 'journal_id': fields.many2one('account.journal', 'Journal', - required=True, readonly=True, - states={'draft':[('readonly',False)]}), + 'name': fields.char( + 'Name', + size=64, + required=True, + readonly=True, + states={'draft': [('readonly', '=', False)]}), + 'check_payment_ids': fields.one2many( + 'account.move.line', + 'check_deposit_id', + 'Check Payments', + readonly=True, + states={'draft': [('readonly', '=', False)]}), + 'deposit_date': fields.date( + 'Deposit Date', + readonly=True, + states={'draft': [('readonly', '=', False)]}), + 'journal_id': fields.many2one( + 'account.journal', + 'Journal', + required=True, + readonly=True, + states={'draft': [('readonly', '=', False)]}), 'state': fields.selection([ - ('draft','Draft'), - ('done','Done'), - ('cancel','Cancelled') - ],'Status', readonly=True), - 'move_id': fields.many2one('account.move', 'Journal Entry', - readonly=True, - states={'draft':[('readonly',False)]}), - 'bank_id': fields.many2one('res.partner.bank', 'Bank', required=True, - readonly=True, - domain="[('partner_id', '=', partner_id)]", - states={'draft':[('readonly',False)]}), - 'partner_id':fields.related('company_id', 'partner_id', type="many2one", - relation="res.partner", string="Partner", - readonly=True), - 'company_id': fields.many2one('res.company', 'Company', required=True, - change_default=True, readonly=True, - states={'draft':[('readonly',False)]}), - 'total_amount': fields.function(sum_amount, string ="total amount"), + ('draft', 'Draft'), + ('done', 'Done'), + ], 'Status', + readonly=True), + 'move_id': fields.many2one( + 'account.move', + 'Journal Entry', + readonly=True, + states={'draft': [('readonly', '=', False)]}), + 'bank_id': fields.many2one( + 'res.partner.bank', + 'Bank', + required=True, + readonly=True, + domain="[('partner_id', '=', partner_id)]", + states={'draft': [('readonly', '=', False)]}), + 'line_ids': fields.related( + 'move_id', + 'line_id', + relation='account.move.line', + type='one2many', + string='Lines', + readonly=True), + 'partner_id': fields.related( + 'company_id', + 'partner_id', + type="many2one", + relation="res.partner", + string="Partner", + readonly=True), + 'company_id': fields.many2one( + 'res.company', + 'Company', + required=True, + change_default=True, + readonly=True, + states={'draft': [('readonly', '=', False)]}), + 'total_amount': fields.function( + sum_amount, + string="total amount", + type="float"), + 'is_reconcile': fields.function( + _is_reconcile, + string="Reconcile", + type="boolean"), } _defaults = { 'name': lambda self, cr, uid, context: '/', 'deposit_date': fields.date.context_today, - 'state':'draft', - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.check.deposit', context=c), + 'state': 'draft', + 'company_id': lambda self, cr, uid, c: self.pool.get('res.company').\ + _company_default_get(cr, uid, 'account.check.deposit', context=c), } - + def unlink(self, cr, uid, ids, context=None): + for deposit in self.browse(cr, uid, ids, context=context): + if deposit.state == 'done': + raise osv.except_osv(_('User Error!'), + _('You cannot delete a validad deposit, cancel it before')) + return super(account_check_deposit, self).unlink(cr, uid, ids, context=context) def cancel(self, cr, uid, ids, context=None): for deposit in self.browse(cr, uid, ids, context=context): if not deposit.journal_id.update_posted: - raise osv.except_osv(_('Error!'), _('You cannot modify a posted entry of this journal.\nFirst you should set the journal to allow cancelling entries.')) + raise osv.except_osv( + _('Error!'), + _('You cannot modify a posted entry of this journal.\n' + 'First you should set the journal to allow cancelling ' + 'entries.')) for line in deposit.check_payment_ids: - line.reconcile_id.unlink() - deposit.move_id.button_cancel() - deposit.move_id.unlink() + if line.reconcile_id: + line.reconcile_id.unlink() + if deposit.move_id: + deposit.move_id.button_cancel() + deposit.move_id.unlink() + deposit.write({'state': 'draft'}) return True def create(self, cr, uid, vals, context=None): - if vals.get('name','/')=='/': - vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'account.check.deposit') or '/' - return super(account_check_deposit, self).create(cr, uid, vals, context=context) + if vals.get('name', '/') == '/': + vals['name'] = self.pool.get('ir.sequence').\ + get(cr, uid, 'account.check.deposit') + return super(account_check_deposit, self).\ + create(cr, uid, vals, context=context) def _prepare_account_move_vals(self, cr, uid, deposit, context=None): - move_vals = {} - move_lines = [[0, 0, self._prepare_sum_move_line_vals(cr, uid, - deposit, move_vals, - context=context)]] - for line in deposit.check_payment_ids: - move_lines.append([0, 0, self._prepare_move_line_vals(cr, uid, line, - move_vals, - context=context)]) - move_vals.update({ + date = deposit.deposit_date + move_vals = { 'journal_id': deposit.journal_id.id, - 'line_id': move_lines, - }) + 'date': date, + } + period_obj = self.pool['account.period'] + period_ids = period_obj.find(cr, uid, dt=date, context=context) + if period_ids: + move_vals['period_id'] = period_ids[0] + sum_move_line = self._prepare_sum_move_line_vals( + cr, uid, deposit, move_vals, context=context) + move_lines = [[0, 0, sum_move_line]] + + for line in deposit.check_payment_ids: + move_line = self._prepare_move_line_vals( + cr, uid, line, move_vals, context=context) + move_lines.append([0, 0, move_line]) + + move_vals.update({'line_id': move_lines}) return move_vals def _prepare_move_line_vals(self, cr, uid, line, move_vals, context=None): - move_line_vals = self.pool.get('account.move.line').default_get( - cr, uid, - ['centralisation', 'date','date_created', 'currency_id', - 'journal_id', 'amount_currency', 'account_id', 'period_id', - 'company_id'], - context=context) - move_line_vals.update({ - 'name': line.name, + return { + 'name': line.ref, 'credit': line.debit, 'account_id': line.account_id.id, 'partner_id': line.partner_id.id, - 'ref': line.ref, - }) - return move_line_vals + 'check_line_id': line.id, + } def _prepare_sum_move_line_vals(self, cr, uid, deposit, move_vals, context=None): - move_line_vals = self.pool.get('account.move.line').default_get( - cr, uid, - ['centralisation', 'date','date_created', 'currency_id', - 'journal_id', 'amount_currency', 'account_id', 'period_id', - 'company_id', 'state'], - context=context) - debit = 0.0 for line in deposit.check_payment_ids: debit += line.debit - move_line_vals.update({ - 'name': deposit.name, - 'debit': debit, - 'ref': deposit.name, - }) + return { + 'name': deposit.name, + 'debit': debit, + 'ref': deposit.name, + } - return move_line_vals - - def _reconcile_checks(self, cr, uid, deposit, move_id, context=None): - move_line_obj = self.pool.get('account.move.line') - for line in deposit.check_payment_ids: - move_line_ids = move_line_obj.search(cr, uid, - [('move_id', '=', move_id), - ('credit', '=', line.debit), - ('name', '=', line.ref)], - context=context) - if move_line_ids: - move_line_obj.reconcile(cr, uid, - [line.id, move_line_ids[0]], - context=context) + def _reconcile_checks(self, cr, uid, move_id, context=None): + move_line_obj = self.pool['account.move.line'] + move_obj = self.pool['account.move'] + move = move_obj.browse(cr, uid, move_id, context=context) + for line in move.line_id: + if line.check_line_id: + move_line_obj.reconcile(cr, uid, [ + line.id, + line.check_line_id.id, + ], context=context) return True - - def onchange_company_id(self, cr, uid, ids, company_id, context=None): - vals={} + vals = {} if company_id: - company=self.pool.get('res.company').browse(cr, uid, company_id, context=context) - vals['partner_id']=company.partner_id.id - return {'value':vals} - - + company = self.pool.get('res.company').\ + browse(cr, uid, company_id, context=context) + vals['partner_id'] = company.partner_id.id + return {'value': vals} def validate_deposit(self, cr, uid, ids, context=None): move_obj = self.pool.get('account.move') @@ -182,8 +227,8 @@ class account_check_deposit(orm.Model): move_vals = self._prepare_account_move_vals(cr, uid, deposit, context=context) move_id = move_obj.create(cr, uid, move_vals, context=context) move_obj.post(cr, uid, [move_id], context=context) - self._reconcile_checks(cr, uid, deposit, move_id, context=context) - deposit.write({'state':'done', 'move_id': move_id}) + self._reconcile_checks(cr, uid, move_id, context=context) + deposit.write({'state': 'done', 'move_id': move_id}) return True @@ -191,9 +236,10 @@ class account_move_line(orm.Model): _inherit = "account.move.line" _columns = { - 'check_deposit_id': fields.many2many('account.check.deposit', - 'account_move_line_deposit_rel', - 'check_deposit_id', - 'move_line_id', - 'Check Deposit'), + 'check_deposit_id': fields.many2one( + 'account.check.deposit', + 'Check Deposit'), + 'check_line_id': fields.many2one( + 'account.move.line', + 'Check Receive Move line'), } diff --git a/account_check_deposit/account_deposit_view.xml b/account_check_deposit/account_deposit_view.xml index 2a74daef0..59f6eb90f 100644 --- a/account_check_deposit/account_deposit_view.xml +++ b/account_check_deposit/account_deposit_view.xml @@ -49,25 +49,31 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -83,6 +89,8 @@ + + diff --git a/account_check_deposit/account_type_data.xml b/account_check_deposit/account_type_data.xml index 1d34fc717..fd47d8a45 100644 --- a/account_check_deposit/account_type_data.xml +++ b/account_check_deposit/account_type_data.xml @@ -11,8 +11,8 @@ - Recieved Checks - recieved_check + Received Checks + received_check none diff --git a/account_check_deposit/report/report_webkit_html.py b/account_check_deposit/report/report_webkit_html.py index 459915868..63fba5ef0 100644 --- a/account_check_deposit/report/report_webkit_html.py +++ b/account_check_deposit/report/report_webkit_html.py @@ -23,18 +23,19 @@ import time from report import report_sxw -from osv import osv + class report_webkit_html(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): super(report_webkit_html, self).__init__(cr, uid, name, context=context) self.localcontext.update({ 'time': time, - 'cr':cr, + 'cr': cr, 'uid': uid, }) report_sxw.report_sxw('report.account.check.deposit', - 'account.check.deposit', - 'addons/account_check_deposit/report/check_deposit.mako', - parser=report_webkit_html) + 'account.check.deposit', + 'addons/account_check_deposit/report/check_deposit.mako', + parser=report_webkit_html) diff --git a/account_check_deposit/security/ir.model.access.csv b/account_check_deposit/security/ir.model.access.csv index 8f26e463a..3e679366f 100644 --- a/account_check_deposit/security/ir.model.access.csv +++ b/account_check_deposit/security/ir.model.access.csv @@ -1,3 +1,2 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_account_check_deposit_account_check_deposit_group_manager","account_check_deposit_account_check_deposit_group_manager","model_account_check_deposit","base.group_system",1,1,1,1 -"access_account_check_deposit_account_check_deposit_group_user","account_check_deposit_account_check_deposit_group_user","model_account_check_deposit","base.group_user",1,0,0,0 +"access_account_check_deposit_account_check_deposit_group_manager","account_check_deposit_account_check_deposit_group_manager","model_account_check_deposit","account.group_account_user",1,1,1,1