[IMP] improve module and fix bugs

This commit is contained in:
Benoit Guillot
2012-12-21 16:52:25 +01:00
committed by Sebastien Beau
parent 193a592357
commit f2eec48063
4 changed files with 77 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
###############################################################################
# #
# account_check_deposit for OpenERP #

View File

@@ -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',

View File

@@ -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'),
}

View File

@@ -17,15 +17,40 @@
<field name="arch" type="xml">
<form string="Check Deposit" version="7.0">
<header>
<button name="get_check_payments" string="Select check payments" type="object" class="oe_highlight"/>
<button name="validate_deposit" string="Validate Deposit" type="object" class="oe_highlight"/>
<button name="validate_deposit" states="draft" string="Validate Deposit"
type="object" class="oe_highlight"/>
<button name="cancel" states="done" string="Cancel" type="object" />
<field name="state" widget="statusbar" statusbar_visible="draft,done"
statusbar_colors='{"draft":"blue"}'/>
</header>
<sheet>
<field name="name"/>
<field name="deposit_date"/>
<field name="journal_id" />
<h1>
<label string="Deposit " />
<field name="name" class="oe_inline" />
</h1>
<group name="deposit_fields">
<field name="deposit_date" />
<field name="journal_id" />
<field name="move_id" />
</group>
<separator string="Check Payments"/>
<field name="check_payment_ids" nolabel="1" colspan="4"/>
<field name="check_payment_ids" nolabel="1" colspan="4" widget="many2many"
domain="[('reconcile_id','=',False),
('account_id.user_type.code','=','recieved_check')]">
<tree string="Check Payments">
<field name="journal_id" />
<field name="period_id" />
<field name="date"/>
<field name="name"/>
<field name="ref"/>
<field name="partner_id" />
<field name="account_id" />
<field name="move_id" />
<field name="debit" sum="Total Debit"/>
<field name="credit" sum="Total Credit"/>
<field name="reconcile"/>
</tree>
</field>
</sheet>
</form>
</field>
@@ -39,6 +64,8 @@
<tree string="Check Deposit">
<field name="name"/>
<field name="deposit_date"/>
<field name="state"/>
<field name="move_id"/>
</tree>
</field>
</record>
@@ -50,6 +77,8 @@
<search string="Search Check deposits">
<field name="name" string="Check Deposit"/>
<field name="deposit_date" string="Date"/>
<field name="state"/>
<field name="move_id"/>
<group expand="0" string="Group By...">
</group>
</search>