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

14 by Jeff Wang
add report and wizard
1
# -*- encoding: utf-8 -*-
2
# __author__ = jeff@openerp.cn
3
# __thanks__ = [oldrev@gmail.com, popkar77@gmail.com]
4
##############################################################################
5
#
6
#    This program is free software: you can redistribute it and/or modify
7
#    it under the terms of the GNU General Public License as published by
8
#    the Free Software Foundation, either version 3 of the License, or
9
#    (at your option) any later version.
10
#
11
#    This program is distributed in the hope that it will be useful,
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#    GNU General Public License for more details.
15
#
16
#    You should have received a copy of the GNU General Public License
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
#
19
##############################################################################
20
21
import time
22
import rml_parse
23
from report import report_sxw
24
from tools.translate import _
25
26
class AccountMoveParser(rml_parse.rml_parse):
27
    '''
28
    Parser for account move report
29
    '''
30
    def __init__(self, cr, uid, name, context):
31
        super(AccountMoveReportParser, self).__init__(cr, uid, name, context)
32
        self.localcontext.update({
33
            'time': time,
34
            'rate': self._get_exchange_rate,
35
            'price':self._get_unit_price,
36
        })
37
    
38
    def _get_exchange_rate(self, line):
39
        '''
40
        Exchange rate: Debit or Credit / currency ammount
41
        Why not get it from currency code + date ?
42
        '''
43
        exchange_rate = False 
44
        if line.amount_currency: 
45
             if line.debit > 0: 
46
                 exchange_rate = line.debit/line.amount_currency 
47
             if line.credit > 0: 
48
                 exchange_rate = line.credit/line.amount_currency 
49
        return exchange_rate 
50
51
    def _get_unit_price(self, line):
52
        '''
53
        Unit priceļ¼šDebit or Credit / Quantity
54
        '''
55
        unit_price = False
56
        if line.quantity:
57
            if line.debit > 0:
58
                unit_price = line.debit/line.quantity
59
            if line.credit > 0:
60
                unit_price = line.credit/line.quantity
61
        return unit_price
62
63
#Register report parser
64
report_sxw.report_sxw('report.account.move', 'account.move',               \
65
                      'addons/oecn_account_print/report/account_move.sxw', \
66
                      parser=AccountMoveParser)