21
21
from osv import osv, fields
22
22
from tools.translate import _
25
#Product for stock ledger, partner for three columns ledger
27
_DETAIL_FORM = '''<?xml version="1.0"?>
28
<form string="Select Product or Partner for grouping">
29
<field name="product" />
31
<field name="partner" />
37
'product': {'string':'Products','type':'many2one','relation':'product.product'},
38
'partner': {'string':'Partners','type':'many2one','relation':'res.partner'},
41
def _get_defaults(self, cr, uid, data, context={}):
42
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
44
company_id = user.company_id.id
46
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
47
data['form']['company_id'] = company_id
48
data['form']['report_type'] = 'threecolumns_ledger'
49
#Default start period = first period in system
50
#Default end period = last period in same year
51
ids = pooler.get_pool(cr.dbname).get('account.period').find(cr, uid, context=context)
52
fiscalyear_id = pooler.get_pool(cr.dbname).get('account.period').browse(cr, uid, ids[0]).fiscalyear_id
53
cr.execute(("SELECT date_start ,fiscalyear_id,id "\
25
class detail_ledger(osv.osv_memory):
27
Cash journal,Foreign currency journal,Stock ledger,Three columns ledger
29
_name = 'detail.ledger'
30
_descript = 'Detail Ledger(Cash journal, Foreign Currency journal, Stock Ledger, Three columns ledger)'
32
'account_id':fields.many2one('account.account', 'Account', required=True),
33
'company_id':fields.many2one('res.company', 'Company', required=True),
34
'period_from':fields.many2one('account.period', 'Period Form', required=True),
35
'period_to':fields.many2one('account.period', 'Period To', required=True),
36
'partner':fields.many2one('res.partner', 'Partner'),
37
'product':fields.many2one('product.product','Product'),
40
def _get_period_from(self, cr, uid, data, context=None):
41
ids = self.pool.get('account.period').find(cr, uid, context=context)
43
fiscalyear_id = self.pool.get('account.period').browse(cr, uid, ids[0]).fiscalyear_id
44
cr.execute(("SELECT date_start ,fiscalyear_id,id "\
54
45
"FROM account_period "\
55
46
"WHERE fiscalyear_id='%s' "\
56
47
"ORDER BY date_start asc ")% (int(fiscalyear_id)))
57
res = cr.dictfetchall()
58
data['form']['period_to'] = ids[0]
59
data['form']['period_form'] = res[0]['id']
60
data['form']['context'] = context
64
class detail_ledger(wizard.interface):
67
def _check_format(self, cr, uid, data, context={}):
48
res = cr.dictfetchall()
52
'company_id':lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.account', context=c),
53
'period_to':lambda s, cr, uid, c:s.pool.get('account.period').find(cr, uid, context=c)[0],
54
'period_from':_get_period_from
57
def print_report(self, cr, uid, ids, context=None):
69
59
Check account type to know which format should be print
70
60
1. Account code start with '1001' or '1002', with currency, print currency cash journal
72
62
3. If user input product, print stock ledger
73
63
4. If user didn't input product, print three columns ledger
75
new_ids = data['form']['account']
76
account = pooler.get_pool(cr.dbname).get('account.account').browse(cr, uid, new_ids, context=context)
65
datas = self.read(cr, uid, ids[0], ['account_id','period_from','period_to','product','partner','company_id'], context=context)
66
datas['ids'] = [datas['account_id'][0]]
67
print 'context:',context
69
account = self.pool.get('account.account').browse(cr, uid, datas['account_id'][0], context=context)
77
70
if(account.code[0:4] == '1001' or account.code[0:4] == '1002'):
78
71
if(account.currency_id):
79
return 'currency_cash_journal'
72
report_name = 'account.currency_cash_journal'
85
def _check_product(self, cr, uid, data, context={}):
87
if data['form'].get('product',''):
90
return 'threecolumns_ledger'
94
'actions': [_get_defaults],
96
'result': {'type':'form', 'arch':_GENERAL_FORM,'fields':_GENERAL_FIELDS,
97
'state':[('end','Cancel','gtk-cancel'),('checkreport','Next','gtk-go-forward')]}
102
# select the right detail ledger format for current account
103
'result': {'type':'choice','next_state':_check_format}
108
# input product or partner
109
'result': {'type':'form', 'arch':_DETAIL_FORM, 'fields':_DETAIL_FIELDS,
110
'state':[('end','Cancel','gtk-cancel'),('checkproduct','Next','gtk-go-forward')]}
115
# select the right detail ledger format for current account
116
'result': {'type':'choice','next_state':_check_product}
122
'result': {'type':'print', 'report':'account.cash_journal', 'state':'end'}
125
'currency_cash_journal': {
127
'result': {'type':'print', 'report':'account.currency_cash_journal', 'state':'end'}
130
'threecolumns_ledger': {
132
'result': {'type':'print', 'report':'account.threecolumns_ledger', 'state':'end'}
136
'result': {'type':'print', 'report':'account.stock_ledger', 'state':'end'}
140
detail_ledger('oecn_account_print.detail_ledger')
74
report_name = 'account.cash_journal'
75
elif datas.get('product',''):
76
report_name = 'account.stock_ledger'
78
report_name = 'account.threecolumns_ledger'
79
datas['report_name'] = report_name
81
'type':'ir.actions.report.xml',
82
'report_name':report_name,
143
89
class general_ledger(osv.osv_memory):