diff --git a/addons/account_followup/followup_report.py b/addons/account_followup/followup_report.py new file mode 100644 index 00000000000..228b12fc797 --- /dev/null +++ b/addons/account_followup/followup_report.py @@ -0,0 +1,83 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +from osv import fields, osv + +def _code_get(self, cr, uid, context={}): + acc_type_obj = self.pool.get('account.account.type') + ids = acc_type_obj.search(cr, uid, []) + res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context) + return [(r['code'], r['name']) for r in res] + + +class account_followup_stat(osv.osv): + _name = "account_followup.stat" + _description = "Followup statistics" + _auto = False + _columns = { + 'name': fields.many2one('res.partner', 'Partner', readonly=True), + 'account_type': fields.selection(_code_get, 'Account Type', required=True), + 'date_move':fields.date('First move', readonly=True), + 'date_move_last':fields.date('Last move', readonly=True), + 'date_followup':fields.date('Latest followup', readonly=True), + 'followup_id': fields.many2one('account_followup.followup.line', 'Follow Ups', required=True, ondelete="cascade"), + 'balance':fields.float('Balance', readonly=True), + 'debit':fields.float('Debit', readonly=True), + 'credit':fields.float('Credit', readonly=True), + } + _order = 'date_move' + def init(self, cr): + cr.execute(""" + create or replace view account_followup_stat as ( + select + l.partner_id as id, + l.partner_id as name, + min(l.date) as date_move, + max(l.date) as date_move_last, + max(l.followup_date) as date_followup, + max(l.followup_line_id) as followup_id, + sum(l.debit) as debit, + sum(l.credit) as credit, + sum(l.debit - l.credit) as balance, + a.type as account_type + from + account_move_line l + left join + account_account a on (l.account_id=a.id) + where + l.reconcile_id is NULL and + a.type in ('receivable', 'payable') + group by + l.partner_id, a.type + )""") +account_followup_stat() + + + diff --git a/addons/account_followup/followup_report_view.xml b/addons/account_followup/followup_report_view.xml new file mode 100644 index 00000000000..511a46a02c1 --- /dev/null +++ b/addons/account_followup/followup_report_view.xml @@ -0,0 +1,56 @@ + + + + + + account_followup.stat.form + account_followup.stat + form + +
+ + + + + + + + + + + +
+ + + + account_followup.stat.tree + account_followup.stat + tree + + + + + + + + + + + + + + + + + Follow-Ups + account_followup.stat + form + + + + +
+
diff --git a/addons/account_followup/report/report_followup_print.py b/addons/account_followup/report/report_followup_print.py index 31d6914fb38..3f46646895a 100644 --- a/addons/account_followup/report/report_followup_print.py +++ b/addons/account_followup/report/report_followup_print.py @@ -54,11 +54,8 @@ class report_rappel(report_sxw.rml_parse): return res_partner_address.read(self.cr, self.uid, [adr])[0] def _lines_get(self, partner): - acc = partner.property_account_receivable[0] moveline_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - movelines = moveline_obj.search(self.cr, self.uid, [('partner_id','=',partner.id), ('account_id','=',acc), ('state','=','valid')]) + movelines = moveline_obj.search(self.cr, self.uid, [('partner_id','=',partner.id), ('account_id','=','type:receivable'), ('reconcile_id','=',False),('state','<>','draft')]) movelines = moveline_obj.read(self.cr, self.uid, movelines) return movelines - report_sxw.report_sxw('report.account_followup.followup.print', 'res.partner', 'addons/account_followup/report/rappel.rml',parser=report_rappel) - diff --git a/addons/account_followup/wizard/wizard_followup_print.py b/addons/account_followup/wizard/wizard_followup_print.py index a0f6c00321e..bd71c9b5691 100644 --- a/addons/account_followup/wizard/wizard_followup_print.py +++ b/addons/account_followup/wizard/wizard_followup_print.py @@ -70,11 +70,6 @@ class followup_all_print(wizard.interface): 'You must define at least one follow up for your company !') fup_id = fup_ids[0] - # fups = { - # previous fup line id: (limit date for current fup line, - # current fup line id), - # ... - # } current_date = datetime.date.today() cr.execute( "SELECT * "\ @@ -82,36 +77,20 @@ class followup_all_print(wizard.interface): "WHERE followup_id=%d "\ "ORDER BY sequence", (fup_id,)) for result in cr.dictfetchall(): - # compute date from when move lines entered earlier than it need - # a follow up delay = datetime.timedelta(days=result['delay']) fups[old] = (current_date - delay, result['id']) if result['start'] == 'end_of_month': - #CHECKME: I have a bad feeling about this... - # but it depends on the semantic of the field, which I don't - # know fups[old][0].replace(day=1) - # old = id of previous fup line old = result['id'] - # we don't want any followup after the last one fups[old] = (datetime.date(datetime.MAXYEAR, 12, 31), old) partner_list = [] for partner_id, followup_line_id, date, id in move_lines: if (partner_id in partner_list) or (not partner_id): continue - - # if the move line has already a followup line but it is invalid, - # we just skip the move line. - # Note that having no follow-up line *is* valid because of the way - # fups is constructed (fups[None] = ...) if followup_line_id not in fups: continue - - # if the move_line happened before the limit date for this level - # of followup, we mark the partner as needing a follow up, and - # mark the line has having had this level of follow up if date <= fups[followup_line_id][0].strftime('%Y-%m-%d'): partner_list.append(partner_id) cr.execute( @@ -121,7 +100,6 @@ class followup_all_print(wizard.interface): (fups[followup_line_id][1], current_date.strftime('%Y-%m-%d'), id,)) return {'partner_id': partner_list} - states = { 'init' : { 'actions': [_get_partners], @@ -135,7 +113,6 @@ class followup_all_print(wizard.interface): 'actions': [_update_partners], 'result': {'type':'print', 'report':'account_followup.followup.print', 'state':'end'}, }, - } followup_all_print('account_followup.followup.print.all')