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

12 by Jeff Wang
Change account move form
1
# -*- encoding: utf-8 -*-
2
# __author__ = jeff@openerp.cn
3
from osv import osv, fields
4
from tools.translate import _
5
6
class account_move(osv.osv):
7
    _inherit = 'account.move'
8
    """
9
    添加制单、审核、附件数三个字段
10
    """
11
    _columns = {
12
        'write_uid':fields.many2one('res.users', '审核', readonly=True),
13
        'create_uid':fields.many2one('res.users', '制单', readonly=True, select=True),      
14
        'proof':fields.integer('附件数', required=True, help='该记账凭证对应的原始凭证数量'),
15
    }
16
    """
17
    附件数默认为1张
18
    凭证业务类型默认为总帐     
19
    """
20
    _defaults = {
21
        'proof': lambda *args: 1,
22
        'journal_id': lambda self, cr, uid, context:self.pool.get('account.journal').search(cr, uid, [('type', '=', 'general')], limit=1)[0]
23
    }
24
25
account_move()
26
13 by Jeff Wang
add detail ledger wizard and move print action
27
class account_account(osv.osv):
28
    _inherit = 'account.account'
29
    """
30
    Replace metheod accoun.account.name_get(), show full name of account on many2one field
31
    Sample “100902 其他货币资金/银行本票”
32
    """ 
33
    def name_get(self, cr, uid, ids, context={}):
34
        if not len(ids):
35
            return []
36
        reads = self.read(cr, uid, ids, ['name', 'code','parent_id'], context)
37
        res = []
38
        for record in reads:
39
            name = record['name']
40
            if record['code']:
41
                
42
                if record['parent_id']:
43
                    account_parent_id = record['parent_id'][0]
44
                    while account_parent_id:
45
                            parent_obj = self.read(cr, uid, account_parent_id, ['name', 'parent_id'], context)
46
                            name = parent_obj['name'] + '/'+name
47
                            if  parent_obj['parent_id']:
48
                                account_parent_id = parent_obj['parent_id'][0]
49
                            else:
50
                                account_parent_id = False
51
52
            name = record['code'] + ' '+name
53
            res.append((record['id'], name))
54
        return res
50 by JoshuaJan
修改报表的模版
55
        
56
    def get_balance(self, cr, uid, ids, date_start=False, date_stop=False, product=False, partner=False ):
57
        '''
58
        Get the balance from date_start to date_stop,fielter by product or partner 
59
        '''
60
        result = {
61
            'debit':0.0,
62
            'debit_quantity':0.0,
63
            'debit_amount_currency':0.0,
64
            'credit':0.0,
65
            'credit_quantity':0.0,
66
            'credit_amount_currency':0.0,
67
            'balance':0.0,
68
            'amount_currency':0.0,
69
            'quantity':0.0,
70
        }
71
        account_move_line_obj = self.pool.get('account.move.line')
72
        account_obj = self.pool.get('account.account')
73
        account_ids = account_obj.search(cr, uid, [('parent_id', 'child_of', ids)])
74
        search_condition = [('account_id','in',account_ids),('state','=','valid')]
75
        if date_start:
76
            search_condition.append(('date', '>=', date_start))
77
        if date_stop:
78
            search_condition.append(('date', '<=', date_stop))
79
        if product: 
80
            search_condition.append(('product_id', '=', product))
81
        if partner:
82
            search_condition.append(('partner_id', '=', partner))
83
        line_ids = account_move_line_obj.search(cr, uid, search_condition)
84
        lines = account_move_line_obj.browse(cr, uid, line_ids)
85
        for line in lines:
86
            if line.debit > 0:
87
                result['debit_quantity'] += line.quantity or 0
88
                result['debit_amount_currency'] += line.amount_currency or 0
89
            else:
90
                result['credit_quantity'] += line.quantity or 0
91
                result['credit_amount_currency'] += abs(line.amount_currency) or 0
92
            result['balance'] += line.debit-line.credit
93
            result['quantity'] =  result['debit_quantity'] - result['credit_quantity']
94
            result['amount_currency'] =  result['debit_amount_currency'] - result['credit_amount_currency']
95
            result['debit'] += line.debit or 0
96
            result['credit'] += line.credit or 0
97
        return result
13 by Jeff Wang
add detail ledger wizard and move print action
98
99
account_account()
100