1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# -*- encoding: utf-8 -*-
# __author__ = jeff@openerp.cn;joshua@openerp.cn
# __thanks__ = [oldrev@gmail.com]
##############################################################################
#
# 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
from tools.translate import _
class detail_ledger(osv.osv_memory):
'''
Cash journal,Foreign currency journal,Stock ledger,Three columns ledger
'''
_name = 'detail.ledger'
_descript = 'Detail Ledger(Cash journal, Foreign Currency journal, Stock Ledger, Three columns ledger)'
_columns = {
'account_id':fields.many2one('account.account', 'Account', required=True),
'company_id':fields.many2one('res.company', 'Company', required=True),
'period_from':fields.many2one('account.period', 'Period Form', required=True),
'period_to':fields.many2one('account.period', 'Period To', required=True),
'partner':fields.many2one('res.partner', 'Partner'),
'product':fields.many2one('product.product','Product'),
}
def _get_period_from(self, cr, uid, data, context=None):
ids = self.pool.get('account.period').find(cr, uid, context=context)
print 'ids:',ids
fiscalyear_id = self.pool.get('account.period').browse(cr, uid, ids[0]).fiscalyear_id
cr.execute(("SELECT date_start ,fiscalyear_id,id "\
"FROM account_period "\
"WHERE fiscalyear_id='%s' "\
"ORDER BY date_start asc ")% (int(fiscalyear_id)))
res = cr.dictfetchall()
return res[0]['id']
_defaults = {
'company_id':lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.account', context=c),
'period_to':lambda s, cr, uid, c:s.pool.get('account.period').find(cr, uid, context=c)[0],
'period_from':_get_period_from
}
def print_report(self, cr, uid, ids, context=None):
"""
Check account type to know which format should be print
1. Account code start with '1001' or '1002', with currency, print currency cash journal
2. Account code start with '1001' or '1002', without currency, print cash journal
3. If user input product, print stock ledger
4. If user didn't input product, print three columns ledger
"""
datas = self.read(cr, uid, ids[0], ['account_id','period_from','period_to','product','partner','company_id'], context=context)
datas['ids'] = [datas['account_id'][0]]
print 'context:',context
print 'datas:',datas
account = self.pool.get('account.account').browse(cr, uid, datas['account_id'][0], context=context)
if(account.code[0:4] == '1001' or account.code[0:4] == '1002'):
if(account.currency_id):
report_name = 'account.currency_cash_journal'
else:
report_name = 'account.cash_journal'
elif datas.get('product',''):
report_name = 'account.stock_ledger'
else:
report_name = 'account.threecolumns_ledger'
datas['report_name'] = report_name
return {
'type':'ir.actions.report.xml',
'report_name':report_name,
'datas':datas
}
detail_ledger()
class general_ledger(osv.osv_memory):
'''
General Ledger
'''
_name = 'general.ledger'
_description = 'General Ledger'
_columns = {
'account_ids':fields.many2many('account.account', 'general_ledger_account_account_rel','general_ledger_id','account_id', 'Account', required=True),
'company_id':fields.many2one('res.company', 'Company', required=True),
'period_from':fields.many2one('account.period', 'Period From', required=True),
'period_to':fields.many2one('account.period', 'Period To', required=True),
}
def print_report(self, cr, uid, ids, context=None):
res = self.read(cr, uid, ids[0], ['account_ids','company_id','period_from','period_to'])
print 'res:%s,ids:%s'%(res,ids)
datas = {'ids':res['account_ids'],'company_id':res['company_id'][0],'period_from':res['period_from'][0],'period_to':res['period_to'][0]}
print 'datas:',datas
return {
'type':'ir.actions.report.xml',
'report_name':'account.general_ledger',
'datas':datas,
}
general_ledger()
# vim:expandtab:smartindent:tabstop=4;softtabstop=4;shiftwidth=4;
|