[IMP] Added old wizrad algo to computer prgoress of reconcilation process, costomer and supplier should display respective recivalbe and payable entry

bzr revid: rgaopenerp-20120823115523-44m8ydyc33az4tjc
This commit is contained in:
RGA(OpenERP) 2012-08-23 17:25:23 +05:30
parent b246b1955a
commit c1437ba1b4
5 changed files with 100 additions and 46 deletions

View File

@ -701,6 +701,8 @@ class account_move_line(osv.osv):
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
if context and context.get('account_type', False):
args.append(('account_id.type', '=', context.get('account_type', False)))
if context and context.get('next_partner_only', False):
if not context.get('partner_id', False):
partner = self.get_next_partner_only(cr, uid, offset, context)

View File

@ -23,18 +23,11 @@ import time
import tools
from osv import fields,osv
#4 remove get_unreconcile_entry method mange it with domain
class account_move_line(osv.osv):
_inherit = "account.move.line"
def get_unreconcile_entry(self, cr, uid, ids, context=None):
records = self.read(cr, uid, ids, ['reconcile_id'])
res = []
for record in records:
if not record.get('reconcile_id'):
res.append(record['id'])
return res
return self.search(cr, uid, [('id', 'in', ids), ('reconcile_id', '=', False)], context=context)
account_move_line();
@ -43,59 +36,101 @@ class account_move_reconciliation(osv.osv):
_name = "account.move.reconciliation"
_description = "All partner info related account move line"
_auto = False
def _get_to_reconcile(self, cr, uid, context=None):
query= ''
if context and context.get('account_type', False) == 'payable':
query = 'AND p.supplier = True'
cr.execute("""
SELECT p_id FROM (SELECT l.partner_id as p_id, SUM(l.debit) AS debit, SUM(l.credit) AS credit
FROM account_move_line AS l LEFT JOIN account_account a ON (l.account_id = a.id)
LEFT JOIN res_partner p ON (p.id = l.partner_id)
WHERE a.reconcile = 't'
AND l.reconcile_id IS NULL
AND (%s > to_char(p.last_reconciliation_date, 'YYYY-MM-DD') OR p.last_reconciliation_date IS NULL )
AND l.state <> 'draft' """ +query + """
GROUP BY l.partner_id) AS tmp
WHERE debit >= 0
AND credit >= 0
""",(time.strftime('%Y-%m-%d'),)
)
return len(map(lambda x: x[0], cr.fetchall())) - 1
def _get_today_reconciled(self, cr, uid, context=None):
query= ''
if context and context.get('account_type', False) == 'payable':
query = 'AND p.supplier = True'
cr.execute(
"""SELECT l.partner_id
FROM account_move_line AS l LEFT JOIN res_partner p ON (p.id = l.partner_id)
WHERE l.reconcile_id IS NULL
AND %s = to_char(p.last_reconciliation_date, 'YYYY-MM-DD')
AND l.state <> 'draft' """ +query + """
GROUP BY l.partner_id """,(time.strftime('%Y-%m-%d'),)
)
return len(map(lambda x: x[0], cr.fetchall())) + 1
def _rec_progress(self, cr, uid, ids, prop, unknow_none, context=None):
active_ids = context.get('active_ids', [])
res = 0
if active_ids:
total_records = self.search(cr, uid, [('id','in',active_ids)])
total_unreconcile = 0
for record in self.read(cr, uid, total_records, ['unreconcile_count'], context=context):
if record['unreconcile_count'] > 0:
total_unreconcile += 1
res = float(len(total_records) - total_unreconcile)/len(total_records) * 100
res_all = {}
res = {}
to_reconcile = self._get_to_reconcile(cr, uid, context)
today_reconcile = self._get_today_reconciled(cr, uid, context)
if to_reconcile < 0:
reconciliation_progress = 100
else:
reconciliation_progress = (100 / (float( to_reconcile + today_reconcile) or 1.0)) * today_reconcile
for id in ids:
res_all[id] = res
return res_all
res[id] = reconciliation_progress
return res
#
def get_partners(self, cr, uid, context=None):
query= ''
if context and context.get('account_type', False) == 'payable':
query = 'AND p.supplier = True'
cr.execute(
"""
SELECT p.id
FROM res_partner p
RIGHT JOIN (
SELECT l.partner_id AS partner_id, SUM(l.debit) AS debit, SUM(l.credit) AS credit
FROM account_move_line l
LEFT JOIN account_account a ON (a.id = l.account_id)
LEFT JOIN res_partner p ON (l.partner_id = p.id)
WHERE a.reconcile IS TRUE
AND l.reconcile_id IS NULL
AND (p.last_reconciliation_date IS NULL OR l.date > p.last_reconciliation_date)
AND l.state <> 'draft' """ +query + """
GROUP BY l.partner_id
) AS s ON (p.id = s.partner_id)
ORDER BY p.last_reconciliation_date""")
return cr.fetchall()
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
obj_move_line = self.pool.get('account.move.line')
ids = super(account_move_reconciliation, self).search(cr, uid, args, offset, limit, order, context, count)
res_ids = []
for id in ids:
last_reconciliation_date = self.browse(cr, uid, id, context=context).last_reconciliation_date
if not last_reconciliation_date:
res_ids.append(id)
else:
move_ids = obj_move_line.search(cr, uid, [('partner_id','=', id),('date','>', last_reconciliation_date)])
if move_ids:
res_ids.append(id)
return res_ids
res = self.get_partners(cr, uid, context=context)
return map(lambda x: x[0], res)
def skip_partner(self, cr, uid, ids, context):
res_partner = self.pool.get('res.partner')
for partner in self.browse(cr, uid, ids, context=context):
res_partner.write(cr, uid, [partner.id] ,{'last_reconciliation_date':time.strftime("%Y-%m-%d")})
self.pool.get('res.partner').write(cr, uid, ids ,{'last_reconciliation_date':time.strftime("%Y-%m-%d")}, context)
_columns = {
'partner_id':fields.many2one('res.partner', 'Partner'),
'last_reconciliation_date':fields.related('partner_id', 'last_reconciliation_date' ,type='datetime', relation='res.partner', string='Last Reconciliation'),
'latest_date' :fields.date('Latest Entry'),
'reconciliation_progress': fields.function(_rec_progress, string='Progress (%)', type='float'),
'unreconcile_count':fields.integer('Unreconcile Count'),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'account_move_reconciliation')
cr.execute("""
CREATE or REPLACE VIEW account_move_reconciliation as (
SELECT move_line.partner_id as id, move_line.partner_id,
MAX(move_line.date) as latest_date,
(select count(unreconcile.id) from account_move_line as unreconcile where unreconcile.reconcile_id is null and unreconcile.partner_id = move_line.partner_id) as unreconcile_count
MAX(move_line.date) as latest_date
FROM account_move_line as move_line where move_line.state <> 'draft'
GROUP by move_line.partner_id
)
""")
account_move_reconciliation()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -17,7 +17,7 @@
</h3>
<div>
<label for="last_reconciliation_date"/>
<field name="last_reconciliation_date" />
<field name="last_reconciliation_date" widget="date"/>
<label for="latest_date"/>
<field name="latest_date"/>
</div>

View File

@ -1544,8 +1544,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<field name="domain">[('partner_id.customer','=',True)]</field>
<field name="context" eval="{'view_mode':True,'extended_form_view_id': ref('view_account_move_reconciliation_form_view'), 'search_default_unreconciled': 1}"></field>
<field name="context" eval="{'account_type':'receivable','view_mode':True,'extended_form_view_id': ref('view_account_move_reconciliation_form_view'), 'search_default_unreconciled': 1}"></field>
</record>
<record id="action_account_payable_manual_reconcile" model="ir.actions.act_window">
@ -1554,8 +1553,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<field name="domain">[('partner_id.supplier','=',True)]</field>
<field name="context" eval="{'view_mode':True,'extended_form_view_id': ref('view_account_move_reconciliation_form_view'), 'search_default_unreconciled': 1}"></field>
<field name="context" eval="{'account_type':'payable','view_mode':True,'extended_form_view_id': ref('view_account_move_reconciliation_form_view'), 'search_default_unreconciled': 1}"></field>
</record>
<menuitem

View File

@ -1,3 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
import tools
@ -12,12 +32,11 @@ class account_move_reconciliation(osv.osv):
def init(self, cr):
tools.drop_view_if_exists(cr, 'account_move_reconciliation')
cr.execute("""
CREATE or REPLACE VIEW account_move_reconciliation as (
CREATE or REPLACE VIEW account_move_reconciliation as (
SELECT move_line.partner_id as id, move_line.partner_id,
MAX(move_line.date) as latest_date,
MAX(move_line.followup_date) as followup_date,
MAX(move_line.followup_line_id) as max_followup_id,
(select count(unreconcile.id) from account_move_line as unreconcile where unreconcile.reconcile_id is null and unreconcile.partner_id = move_line.partner_id) as unreconcile_count
MAX(move_line.date) as latest_date
FROM account_move_line as move_line where move_line.state <> 'draft'
GROUP by move_line.partner_id
)