1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from osv import fields,osv
24 import decimal_precision as dp
26 class account_entries_report(osv.osv):
27 _name = "account.entries.report"
28 _description = "Journal Items Analysis"
32 'date': fields.date('Effective Date', readonly=True),
33 'date_created': fields.date('Date Created', readonly=True),
34 'date_maturity': fields.date('Date Maturity', readonly=True),
35 'ref': fields.char('Reference', size=64, readonly=True),
36 'nbr': fields.integer('# of Items', readonly=True),
37 'debit': fields.float('Debit', readonly=True),
38 'credit': fields.float('Credit', readonly=True),
39 'balance': fields.float('Balance', readonly=True),
40 'day': fields.char('Day', size=128, readonly=True),
41 'year': fields.char('Year', size=4, readonly=True),
42 'date': fields.date('Date', size=128, readonly=True),
43 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True),
44 'amount_currency': fields.float('Amount Currency', digits_compute=dp.get_precision('Account'), readonly=True),
45 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
46 ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
47 ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True),
48 'period_id': fields.many2one('account.period', 'Period', readonly=True),
49 'account_id': fields.many2one('account.account', 'Account', readonly=True),
50 'journal_id': fields.many2one('account.journal', 'Journal', readonly=True),
51 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', readonly=True),
52 'product_id': fields.many2one('product.product', 'Product', readonly=True),
53 'product_uom_id': fields.many2one('product.uom', 'Product Unit of Measure', readonly=True),
54 'move_state': fields.selection([('draft','Unposted'), ('posted','Posted')], 'Status', readonly=True),
55 'move_line_state': fields.selection([('draft','Unbalanced'), ('valid','Valid')], 'State of Move Line', readonly=True),
56 'reconcile_id': fields.many2one('account.move.reconcile', readonly=True),
57 'partner_id': fields.many2one('res.partner','Partner', readonly=True),
58 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
59 'quantity': fields.float('Products Quantity', digits=(16,2), readonly=True),
60 'user_type': fields.many2one('account.account.type', 'Account Type', readonly=True),
61 'type': fields.selection([
62 ('receivable', 'Receivable'),
63 ('payable', 'Payable'),
66 ('consolidation', 'Consolidation'),
69 ], 'Internal Type', readonly=True, help="This type is used to differentiate types with "\
70 "special effects in OpenERP: view can not have entries, consolidation are accounts that "\
71 "can have children accounts for multi-company consolidations, payable/receivable are for "\
72 "partners accounts (for debit/credit computations), closed for depreciated accounts."),
73 'company_id': fields.many2one('res.company', 'Company', readonly=True),
78 def search(self, cr, uid, args, offset=0, limit=None, order=None,
79 context=None, count=False):
80 fiscalyear_obj = self.pool.get('account.fiscalyear')
81 period_obj = self.pool.get('account.period')
83 if arg[0] == 'period_id' and arg[2] == 'current_period':
84 current_period = period_obj.find(cr, uid)[0]
85 args.append(['period_id','in',[current_period]])
87 elif arg[0] == 'period_id' and arg[2] == 'current_year':
88 current_year = fiscalyear_obj.find(cr, uid)
89 ids = fiscalyear_obj.read(cr, uid, [current_year], ['period_ids'])[0]['period_ids']
90 args.append(['period_id','in',ids])
91 for a in [['period_id','in','current_year'], ['period_id','in','current_period']]:
94 return super(account_entries_report, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order,
95 context=context, count=count)
97 def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
100 fiscalyear_obj = self.pool.get('account.fiscalyear')
101 period_obj = self.pool.get('account.period')
102 if context.get('period', False) == 'current_period':
103 current_period = period_obj.find(cr, uid)[0]
104 domain.append(['period_id','in',[current_period]])
105 elif context.get('year', False) == 'current_year':
106 current_year = fiscalyear_obj.find(cr, uid)
107 ids = fiscalyear_obj.read(cr, uid, [current_year], ['period_ids'])[0]['period_ids']
108 domain.append(['period_id','in',ids])
111 return super(account_entries_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby)
114 tools.drop_view_if_exists(cr, 'account_entries_report')
116 create or replace view account_entries_report as (
120 l.date_maturity as date_maturity,
121 l.date_created as date_created,
123 am.state as move_state,
124 l.state as move_line_state,
125 l.reconcile_id as reconcile_id,
126 to_char(am.date, 'YYYY') as year,
127 to_char(am.date, 'MM') as month,
128 to_char(am.date, 'YYYY-MM-DD') as day,
129 l.partner_id as partner_id,
130 l.product_id as product_id,
131 l.product_uom_id as product_uom_id,
132 am.company_id as company_id,
133 am.journal_id as journal_id,
134 p.fiscalyear_id as fiscalyear_id,
135 am.period_id as period_id,
136 l.account_id as account_id,
137 l.analytic_account_id as analytic_account_id,
139 a.user_type as user_type,
141 l.quantity as quantity,
142 l.currency_id as currency_id,
143 l.amount_currency as amount_currency,
146 l.debit-l.credit as balance
149 left join account_account a on (l.account_id = a.id)
150 left join account_move am on (am.id=l.move_id)
151 left join account_period p on (am.period_id=p.id)
152 where l.state != 'draft'
155 account_entries_report()
157 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: