diff --git a/account_check_deposit/__init__.py b/account_check_deposit/__init__.py
index d4de023a5..d0334331b 100644
--- a/account_check_deposit/__init__.py
+++ b/account_check_deposit/__init__.py
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
###############################################################################
# #
# account_check_deposit for OpenERP #
diff --git a/account_check_deposit/__openerp__.py b/account_check_deposit/__openerp__.py
index 4ed1f644e..ffbee2c21 100644
--- a/account_check_deposit/__openerp__.py
+++ b/account_check_deposit/__openerp__.py
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
###############################################################################
# #
# account_check_deposit for OpenERP #
@@ -23,7 +23,7 @@
{
'name': 'account_check_deposit',
- 'version': '7.1',
+ 'version': '7.0',
'category': 'Generic Modules/Others',
'license': 'AGPL-3',
'description': """This module allows you to use check deposits.
@@ -32,7 +32,7 @@
You may have to create an account for recieved checks and a journal for payment by checks.""",
'author': 'Akretion',
'website': 'http://www.akretion.com/',
- 'depends': ['account'],
+ 'depends': ['account_accountant'],
'init_xml': [],
'update_xml': [
'account_deposit_view.xml',
diff --git a/account_check_deposit/account_deposit.py b/account_check_deposit/account_deposit.py
index bd8828e52..9643a2a6e 100644
--- a/account_check_deposit/account_deposit.py
+++ b/account_check_deposit/account_deposit.py
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
###############################################################################
# #
# account_check_deposit for OpenERP #
@@ -19,45 +19,52 @@
# #
###############################################################################
-from openerp.osv import fields
+from openerp.osv import fields, osv
from openerp.osv.orm import Model
+from openerp.tools.translate import _
class account_check_deposit(Model):
_name = "account.check.deposit"
_description = "Account Check Deposit"
_columns = {
- 'name': fields.char('Name', size=64, required=True),
- 'check_payment_ids': fields.one2many('account.move.line', 'check_deposit_id', 'Check Payments'),
- 'deposit_date': fields.date('Deposit Date'),
- 'journal_id': fields.many2one('account.journal', 'Journal', required=True),
+ 'name': fields.char('Name', size=64, required=True, readonly=True, states={'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)]}),
+ '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)]}),
}
_defaults = {
'name': lambda self, cr, uid, context: '/',
'deposit_date': fields.date.context_today,
+ 'state':'draft',
}
+ 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.'))
+ for line in deposit.check_payment_ids:
+ line.reconcile_id.unlink()
+ deposit.move_id.button_cancel()
+ deposit.move_id.unlink()
+ 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)
- def _get_check_payment_ids(self, cr, uid, ids, context=None):
- model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, "account_check_deposit",
- "data_account_type_received_check")
- account_ids = self.pool.get('account.account').search(cr, uid, [('user_type', '=', type_id)], context=context)
- check_payment_ids = self.pool.get('account.move.line').search(cr, uid, [('account_id', 'in', account_ids),
- ('reconcile_id', '=', False)],
- context=context)
- return check_payment_ids
-
- def get_check_payments(self, cr, uid, ids, context=None):
- move_line_obj = self.pool.get('account.move.line')
- check_payment_ids = self._get_check_payment_ids(cr, uid, ids, context=context)
- move_line_obj.write(cr, uid, check_payment_ids, {'check_deposit_id': ids[0]}, context=context)
- return True
-
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)]]
@@ -79,8 +86,9 @@ class account_check_deposit(Model):
'name': line.ref, #name ?
'credit': line.debit,
'account_id': line.account_id.id,
+ 'partner_id': line.partner_id.id,
+ 'ref': line.ref,
})
- move_lines_vals.append(move_line_vals)
return move_line_vals
def _prepare_sum_move_line_vals(self, cr, uid, deposit, move_vals, context=None):
@@ -95,11 +103,12 @@ class account_check_deposit(Model):
move_line_vals.update({
'name': deposit.name,
'debit': debit,
+ 'ref': deposit.name,
})
return move_line_vals
- def _reconcile_checks(cr, uid, deposit, move_id, context=None):
+ 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),
@@ -110,6 +119,7 @@ class account_check_deposit(Model):
return True
def validate_deposit(self, cr, uid, ids, context=None):
+ move_obj = self.pool.get('account.move')
if context is None:
context = {}
for deposit in self.browse(cr, uid, ids, context=context):
@@ -117,14 +127,16 @@ class account_check_deposit(Model):
move_vals = self._prepare_account_move_vals(cr, uid, deposit, context=context)
print "move_vals ====>", move_vals
import pdb; pdb.set_trace()
- move_id = self.pool.get('account.move').create(cr, uid, move_vals, context=context)
- self.post(cr, uid, [move_id], 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})
return True
class account_move_line(Model):
_inherit = "account.move.line"
_columns = {
- 'check_deposit_id': fields.many2one('account.check.deposit', 'Check Deposit', ondelete="restrict"),
+ 'check_deposit_id': fields.many2many('account.check.deposit', 'account_move_line_deposit_rel',
+ 'check_deposit_id', 'move_line_id', 'Check Deposit'),
}
diff --git a/account_check_deposit/account_deposit_view.xml b/account_check_deposit/account_deposit_view.xml
index eb0945c07..10cc6cdd4 100644
--- a/account_check_deposit/account_deposit_view.xml
+++ b/account_check_deposit/account_deposit_view.xml
@@ -17,15 +17,40 @@
@@ -39,6 +64,8 @@
+
+
@@ -50,6 +77,8 @@
+
+