~openerp-chinese-team/openerp-china/openerp-china

« back to all changes in this revision

Viewing changes to oecn_account_print/wizard/oecn_account_print_wizard.py

  • Committer: JoshuaJan
  • Date: 2012-02-21 03:21:40 UTC
  • Revision ID: joshua@openerp.cn-20120221032140-4wwk95ftpf9x24ec
change the shipped date for report MM

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from  osv import osv, fields
22
22
from tools.translate import _
23
23
 
24
 
#General Parameters
25
 
#Product for stock ledger, partner for three columns ledger
26
 
 
27
 
_DETAIL_FORM = '''<?xml version="1.0"?>
28
 
<form string="Select Product or Partner for grouping">
29
 
    <field name="product" />
30
 
    <newline/>
31
 
    <field name="partner" />
32
 
    <newline/>
33
 
</form>'''
34
 
 
35
 
'''
36
 
_DETAIL_FIELDS = {
37
 
    'product': {'string':'Products','type':'many2one','relation':'product.product'},
38
 
    'partner': {'string':'Partners','type':'many2one','relation':'res.partner'},
39
 
}
40
 
 
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)
43
 
    if user.company_id:
44
 
        company_id = user.company_id.id
45
 
    else:
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 "\
 
24
 
 
25
class detail_ledger(osv.osv_memory):
 
26
    '''
 
27
    Cash journal,Foreign currency journal,Stock ledger,Three columns ledger
 
28
    '''
 
29
    _name = 'detail.ledger'
 
30
    _descript = 'Detail Ledger(Cash journal, Foreign Currency journal, Stock Ledger, Three columns ledger)'
 
31
    _columns = {
 
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'),
 
38
    }
 
39
    
 
40
    def _get_period_from(self, cr, uid, data, context=None):
 
41
        ids = self.pool.get('account.period').find(cr, uid, context=context)
 
42
        print 'ids:',ids
 
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
61
 
    return data['form']
62
 
 
63
 
 
64
 
class detail_ledger(wizard.interface):
65
 
 
66
 
 
67
 
    def _check_format(self, cr, uid, data, context={}):
 
48
        res = cr.dictfetchall()
 
49
        return res[0]['id']
 
50
    
 
51
    _defaults = {
 
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
 
55
    }
 
56
 
 
57
    def print_report(self, cr, uid, ids, context=None):
68
58
        """
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 
74
64
        """
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
 
68
        print 'datas:',datas
 
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'
80
73
            else:
81
 
                return 'cash_journal'
82
 
        else:
83
 
            return 'detail'
84
 
 
85
 
    def _check_product(self, cr, uid, data, context={}):
86
 
        
87
 
        if data['form'].get('product',''):
88
 
            return 'stock_ledger'
89
 
        else:
90
 
            return 'threecolumns_ledger'
91
 
 
92
 
    states = {
93
 
        'init': {
94
 
            'actions': [_get_defaults],
95
 
            # Select account
96
 
            'result': {'type':'form', 'arch':_GENERAL_FORM,'fields':_GENERAL_FIELDS, 
97
 
                'state':[('end','Cancel','gtk-cancel'),('checkreport','Next','gtk-go-forward')]}
98
 
        },
99
 
 
100
 
        'checkreport': {
101
 
            'actions': [],
102
 
            # select the right detail ledger format for current account 
103
 
            'result': {'type':'choice','next_state':_check_format}
104
 
        },
105
 
 
106
 
        'detail': {
107
 
            'actions': [],
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')]}
111
 
        },
112
 
 
113
 
        'checkproduct': {
114
 
            'actions': [],
115
 
            # select the right detail ledger format for current account
116
 
            'result': {'type':'choice','next_state':_check_product}
117
 
        },
118
 
 
119
 
 
120
 
        'cash_journal': {
121
 
            'actions': [],
122
 
            'result': {'type':'print', 'report':'account.cash_journal', 'state':'end'}
123
 
        },
124
 
 
125
 
        'currency_cash_journal': {
126
 
            'actions': [],
127
 
            'result': {'type':'print', 'report':'account.currency_cash_journal', 'state':'end'}
128
 
        },
129
 
 
130
 
        'threecolumns_ledger': {
131
 
            'actions': [],
132
 
            'result': {'type':'print', 'report':'account.threecolumns_ledger', 'state':'end'}
133
 
        },
134
 
        'stock_ledger': {
135
 
            'actions': [],
136
 
            'result': {'type':'print', 'report':'account.stock_ledger', 'state':'end'}
137
 
        },
138
 
    }
139
 
 
140
 
detail_ledger('oecn_account_print.detail_ledger')
141
 
 
142
 
'''
 
74
                report_name = 'account.cash_journal'
 
75
        elif datas.get('product',''):
 
76
            report_name =  'account.stock_ledger'
 
77
        else:
 
78
            report_name = 'account.threecolumns_ledger'
 
79
        datas['report_name'] = report_name
 
80
        return {
 
81
                'type':'ir.actions.report.xml',
 
82
                'report_name':report_name,
 
83
                'datas':datas
 
84
        }
 
85
 
 
86
 
 
87
detail_ledger()
 
88
 
143
89
class general_ledger(osv.osv_memory):
144
90
    '''
145
91
    General Ledger