~openerp-commiter/openobject-addons/trunk-dev-addons3-vth2

« back to all changes in this revision

Viewing changes to account_followup/report/account_followup_report.py

[MERGE] merge from trunk-dev-addons-3

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from osv import fields, osv
23
23
import tools
24
24
 
25
 
def _code_get(self, cr, uid, context={}):
26
 
    acc_type_obj = self.pool.get('account.account.type')
27
 
    ids = acc_type_obj.search(cr, uid, [])
28
 
    res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
29
 
    return [(r['code'], r['name']) for r in res]
30
 
 
31
 
 
32
25
class account_followup_stat(osv.osv):
33
26
    _name = "account_followup.stat"
34
27
    _description = "Followup Statistics"
 
28
    _rec_name = 'partner_id'
35
29
    _auto = False
36
30
    _columns = {
37
 
        'name': fields.many2one('res.partner', 'Partner', readonly=True),
38
 
        'account_type': fields.selection(_code_get, 'Account Type', readonly=True),
 
31
        'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
39
32
        'date_move':fields.date('First move', readonly=True),
40
33
        'date_move_last':fields.date('Last move', readonly=True),
41
34
        'date_followup':fields.date('Latest followup', readonly=True),
58
51
                    current_year = self.pool.get('account.fiscalyear').find(cr, uid)
59
52
                    ids = self.pool.get('account.fiscalyear').read(cr, uid, [current_year], ['period_ids'])[0]['period_ids']
60
53
                    args.append(['period_id','in',ids])
61
 
            for a in [['period_id','in','current_year']]:
62
 
                temp_args = tuple(a)
63
 
                if temp_args in args:
64
 
                    args.remove(temp_args)
 
54
                    args.remove(arg)
65
55
            return super(account_followup_stat, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order,
66
56
                context=context, count=count)
67
57
 
72
62
                    current_year = self.pool.get('account.fiscalyear').find(cr, uid)
73
63
                    ids = self.pool.get('account.fiscalyear').read(cr, uid, [current_year], ['period_ids'])[0]['period_ids']
74
64
                    domain.append(['period_id','in',ids])
75
 
                    todel.append(arg)
76
 
            for a in [['period_id','in','current_year']]:
77
 
                temp_args = tuple(a)
78
 
                if temp_args in domain:
79
 
                    domain.remove(temp_args)
 
65
                    domain.remove(arg)
80
66
            return super(account_followup_stat, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context)
81
67
 
82
68
    def init(self, cr):
83
69
        tools.drop_view_if_exists(cr, 'account_followup_stat')
84
70
        cr.execute("""
85
71
            create or replace view account_followup_stat as (
86
 
             select
87
 
                    l.partner_id as id,
88
 
                    l.partner_id as name,
89
 
                    min(l.date) as date_move,
90
 
                    max(l.date) as date_move_last,
91
 
                    max(l.followup_date) as date_followup,
92
 
                    max(l.followup_line_id) as followup_id,
93
 
                    sum(l.debit) as debit,
94
 
                    sum(l.credit) as credit,
95
 
                    sum(l.debit - l.credit) as balance,
96
 
                    a.type as account_type,
97
 
                    l.company_id as company_id,
98
 
                    l.blocked,
99
 
                    am.period_id as period_id
100
 
                from
 
72
                SELECT
 
73
                    l.id AS id,
 
74
                    l.partner_id AS partner_id,
 
75
                    min(l.date) AS date_move,
 
76
                    max(l.date) AS date_move_last,
 
77
                    max(l.followup_date) AS date_followup,
 
78
                    max(l.followup_line_id) AS followup_id,
 
79
                    sum(l.debit) AS debit,
 
80
                    sum(l.credit) AS credit,
 
81
                    sum(l.debit - l.credit) AS balance,
 
82
                    l.company_id AS company_id,
 
83
                    l.blocked as blocked,
 
84
                    l.period_id AS period_id
 
85
                FROM
101
86
                    account_move_line l
102
 
                    LEFT JOIN account_account a ON (l.account_id=a.id)
103
 
                    LEFT JOIN res_company c ON (l.company_id=c.id)
104
 
                    LEFT JOIN account_move am ON (am.id=l.move_id)
105
 
                    LEFT JOIN account_period p ON (am.period_id=p.id)
106
 
                where
107
 
                    l.reconcile_id is NULL and
108
 
                    a.type = 'receivable'
109
 
                    and a.active and
110
 
                    l.partner_id is not NULL and
111
 
                    l.company_id is not NULL and
112
 
                    l.blocked is not NULL
113
 
                    group by
114
 
                    l.partner_id, a.type, l.company_id,l.blocked,am.period_id
 
87
                    LEFT JOIN account_account a ON (l.account_id = a.id)
 
88
                WHERE
 
89
                    a.active AND
 
90
                    a.type = 'receivable' AND
 
91
                    l.reconcile_id is NULL AND
 
92
                    l.partner_id IS NOT NULL
 
93
                GROUP BY
 
94
                    l.id, l.partner_id, l.company_id, l.blocked, l.period_id 
115
95
            )""")
116
96
account_followup_stat()
117
97
 
118
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'
 
98
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: