[REF] account: sql view of manual reconcilation move line

bzr revid: hmo@tinyerp.com-20120829063732-2yn3sj0lshnx4n35
This commit is contained in:
Harry (OpenERP) 2012-08-29 12:07:32 +05:30
parent 03dd0da485
commit d55eaccb23
6 changed files with 85 additions and 120 deletions

View File

@ -34,48 +34,26 @@ account_move_line();
class account_move_reconciliation(osv.osv):
_name = "account.move.reconciliation"
_description = "All partner info related account move line"
_description = "partner info related account move line"
_auto = False
_order = 'last_reconciliation_date'
def _get_to_reconcile(self, cr, uid, context=None):
query= ''
if context and context.get('account_type', False) == 'payable':
query = 'AND p.supplier = True'
def search(self, cr, uid, args, offset=0, limit=None, order=None,
context=None, count=False):
if context is None:
context = {}
account_type = context.get('account_type', False)
if account_type == "receivable":
args += [('customer','=', True)]
if account_type == "payable":
args += [('supplier','=', True)]
return super(account_move_reconciliation, self).search(cr, uid, args, offset, limit,
order, context=context, count=count)
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):
res = {}
to_reconcile = self._get_to_reconcile(cr, uid, context)
today_reconcile = self._get_today_reconciled(cr, uid, context)
to_reconcile = self.search(cr, uid, [], context=context)
today_reconcile = self.search(cr, uid, [('last_reconciliation_date','=',time.strftime('%Y-%m-%d'))], context=context)
if to_reconcile < 0:
reconciliation_progress = 100
else:
@ -83,34 +61,8 @@ class account_move_reconciliation(osv.osv):
for id in ids:
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):
ids = super(account_move_reconciliation, self).search(cr, uid, args, offset, limit, order, context, count)
res = self.get_partners(cr, uid, context=context)
return map(lambda x: x[0], res)
def skip_partner(self, cr, uid, ids, context):
self.pool.get('res.partner').write(cr, uid, ids ,{'last_reconciliation_date':time.strftime("%Y-%m-%d")}, context)
@ -118,6 +70,8 @@ class account_move_reconciliation(osv.osv):
'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'),
'supplier': fields.related('partner_id', 'supplier' ,type='boolean', string='Supplier'),
'customer': fields.related('partner_id', 'customer' ,type='boolean', string='Customer'),
'reconciliation_progress': fields.function(_rec_progress, string='Progress (%)', type='float'),
}
@ -125,12 +79,17 @@ class account_move_reconciliation(osv.osv):
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
FROM account_move_line as move_line where move_line.state <> 'draft'
GROUP by move_line.partner_id
)
SELECT move_line.partner_id AS partner_id, SUM(move_line.debit) AS debit, SUM(move_line.credit) AS credit, MAX(move_line.date) AS latest_date
FROM account_move_line move_line
LEFT JOIN account_account a ON (a.id = move_line.account_id)
RIGHT JOIN res_partner partner ON (move_line.partner_id = partner.id)
WHERE a.reconcile IS TRUE
AND move_line.reconcile_id IS NULL
AND (partner.last_reconciliation_date IS NULL OR move_line.date > partner.last_reconciliation_date)
AND move_line.state <> 'draft'
GROUP BY move_line.partner_id
)
""")
account_move_reconciliation()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Extended View of Reconciliation Entry -->
<record id="view_account_move_reconciliation_form_view" model="ir.ui.view">
<field name="name">account.move.reconciliation.form</field>
<field name="model">account.move.reconciliation</field>
@ -32,5 +33,38 @@
</form>
</field>
</record>
<!-- Menu and Action -->
<record id="action_account_receivable_manual_reconcile" model="ir.actions.act_window">
<field name="name">Entries To Reconcile</field>
<field name="res_model">account.move.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<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">
<field name="name">Entries To Reconcile</field>
<field name="res_model">account.move.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<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
name="Manual Reconciliation" icon="STOCK_EXECUTE"
id="menu_manual_reconcile"
parent="account.periodical_processing_reconciliation"/>
<menuitem id="receivable_manual_reconcile" name="Reconcile Customer Entries"
action="action_account_receivable_manual_reconcile"
parent="account.menu_manual_reconcile"/>
<menuitem id="payable_manual_reconcile" name="Reconcile Supplier Entries"
action="action_account_payable_manual_reconcile"
parent="account.menu_manual_reconcile"/>
</data>
</openerp>

View File

@ -1538,38 +1538,6 @@
<field name="act_window_id" ref="action_move_line_search"/>
</record>
<record id="action_account_receivable_manual_reconcile" model="ir.actions.act_window">
<field name="name">Entries To Reconcile</field>
<field name="res_model">account.move.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<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">
<field name="name">Entries To Reconcile</field>
<field name="res_model">account.move.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="auto_search"/>
<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
name="Manual Reconciliation" icon="STOCK_EXECUTE"
id="menu_manual_reconcile"
parent="account.periodical_processing_reconciliation"/>
<menuitem id="receivable_manual_reconcile" name="Reconcile Customer Entries"
action="action_account_receivable_manual_reconcile"
parent="account.menu_manual_reconcile"/>
<menuitem id="payable_manual_reconcile" name="Reconcile Supplier Entries"
action="action_account_payable_manual_reconcile"
parent="account.menu_manual_reconcile"/>
<act_window
id="act_account_acount_move_line_open"
name="Entries"

View File

@ -19,7 +19,7 @@ instance.account.extend_viewmanager = instance.web.ViewManagerAction.include({
this.dataset_loaded = this.dataset_form.read_slice()
obj_from_view = new from_view(self, this.dataset_form, view_id, options={});
obj_from_view.template = 'ExtendedFormView'
view_promise = obj_from_view.appendTo(this.$element.find('.oe_extended_form_view'))
view_promise = obj_from_view.appendTo(this.$el.find('.oe_extended_form_view'))
$.when(view_promise, this.dataset_loaded).then(function() {
self.action.context.active_ids = self.dataset_form.ids;
if (!_.isEmpty(self.dataset_form.ids)) {
@ -37,9 +37,9 @@ instance.account.extend_form_view = instance.web.FormView.extend({
on_loaded: function(data) {
this._super.apply(this,arguments);
var self = this
this.$element.find(".oe_reconcile").on('click', this.do_reconcilation)
this.$element.find(".oe_nothing_to_reconcile").on('click', this.do_nothing_to_reconcile)
this.$element.on('click','a[data-pager-action]',function() {
this.$el.find(".oe_reconcile").on('click', this.do_reconcilation)
this.$el.find(".oe_nothing_to_reconcile").on('click', this.do_nothing_to_reconcile)
this.$el.on('click','a[data-pager-action]',function() {
var action = $(this).data('pager-action');
self.on_pager_action(action);
});
@ -87,7 +87,7 @@ instance.account.extend_form_view = instance.web.FormView.extend({
do_update_pager: function(hide_index) {
var index = hide_index ? '-' : this.dataset.index + 1;
this.$element.find('span.oe_pager_index_extend').html(index).end()
this.$el.find('span.oe_pager_index_extend').html(index).end()
.find('span.oe_pager_count_extend').html(this.dataset.ids.length);
},

View File

@ -25,20 +25,24 @@ class account_move_reconciliation(osv.osv):
_inherit = 'account.move.reconciliation'
_columns = {
'followup_date': fields.date('Latest Follow-up'),
'max_followup_id':fields.many2one('account_followup.followup.line',
'Max Follow Up Level' )
#'followup_id':fields.many2one('account_followup.followup.line',
# 'Max Follow Up Level' )
}
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.followup_date) as followup_date,
MAX(move_line.followup_line_id) as max_followup_id,
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
)
SELECT move_line.partner_id AS partner_id, SUM(move_line.debit) AS debit, SUM(move_line.credit) AS credit, MAX(move_line.date) AS latest_date,
MAX(move_line.followup_date) as followup_date
FROM account_move_line move_line
LEFT JOIN account_account a ON (a.id = move_line.account_id)
RIGHT JOIN res_partner partner ON (move_line.partner_id = partner.id)
WHERE a.reconcile IS TRUE
AND move_line.reconcile_id IS NULL
AND (partner.last_reconciliation_date IS NULL OR move_line.date > partner.last_reconciliation_date)
AND move_line.state <> 'draft'
GROUP BY move_line.partner_id
)
""")
account_move_reconciliation()
account_move_reconciliation()

View File

@ -9,8 +9,8 @@
<xpath expr="//div[@name='div4']" position="inside">
<label for="followup_date"/>
<field name="followup_date"/>
<field name="max_followup_id"/>
</xpath>
<!-- <field name="followup_id"/> -->
</xpath>
</field>
</record>
</data>