~openerp-mongolian/openerp-mongolization/7.0

« back to all changes in this revision

Viewing changes to l10n_mn_account/.svn/text-base/account_bank_statement.py.svn-base

  • Committer: Unurjartal Ts
  • Date: 2013-06-17 09:33:42 UTC
  • mfrom: (1.1.2 openerp-mongolization)
  • Revision ID: unuruu25@gmail.com-20130617093342-w2o2hbtz5qg8ioli
ShineERP custom modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    ShineERP, Enterprise Management Solution    
 
5
#    Copyright (C) 2007-2012 ShineERP Co.,ltd (<http://www.erp.mn>). All Rights Reserved
 
6
#
 
7
#    Address : Suhkbaatar District, National ITPark, ShineERP LLC
 
8
#    Email : info@erp.mn
 
9
#    Phone : 976 + 11-318043
 
10
#
 
11
##############################################################################
 
12
 
 
13
from osv import osv,fields,orm
 
14
from tools.translate import _
 
15
import time
 
16
 
 
17
class account_bank_statement_line(osv.osv):
 
18
    _inherit = 'account.bank.statement.line'
 
19
    
 
20
    _columns = {
 
21
        'cash_move_type': fields.many2one('account.cash.move.type', 'Cash Move Type')
 
22
    }
 
23
    def print_cash_order(self, cr, uid, ids, context={}):
 
24
        ''' Кассын орлогын баримт, зарлагын баримт хэвлэх
 
25
        '''
 
26
        datas = {
 
27
            'ids': ids
 
28
        }
 
29
        
 
30
        line = self.browse(cr, uid, ids[0], context=context)
 
31
        context.update({'active_ids':ids,'active_id':ids[0]})
 
32
        
 
33
        if line.amount > 0 : # Орлогын баримт
 
34
            return {
 
35
                'type':         'ir.actions.report.xml',
 
36
                'report_name':  'cash.statement.line.income',
 
37
                'datas':        datas,
 
38
                'context':      context,
 
39
                'nodestroy': True
 
40
            }
 
41
        else : # Зарлагын баримт
 
42
            return {
 
43
                'type':         'ir.actions.report.xml',
 
44
                'report_name':  'cash.statement.line.expense',
 
45
                'datas':        datas,
 
46
                'context':      context,
 
47
                'nodestroy': True
 
48
            }
 
49
            
 
50
account_bank_statement_line()
 
51
 
 
52
class account_bank_statement(osv.osv):
 
53
    _inherit = 'account.bank.statement'
 
54
    
 
55
    def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None):
 
56
 
 
57
        if context is None:
 
58
            context = {}
 
59
        res_currency_obj = self.pool.get('res.currency')
 
60
        account_move_obj = self.pool.get('account.move')
 
61
        account_move_line_obj = self.pool.get('account.move.line')
 
62
        account_bank_statement_line_obj = self.pool.get('account.bank.statement.line')
 
63
        st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context)
 
64
        st = st_line.statement_id
 
65
 
 
66
        context.update({'date': st_line.date})
 
67
 
 
68
        move_id = account_move_obj.create(cr, uid, {
 
69
            'journal_id': st.journal_id.id,
 
70
            'period_id': st.period_id.id,
 
71
            'date': st_line.date,
 
72
            'name': st_line_number,
 
73
            'ref': st_line.ref,
 
74
        }, context=context)
 
75
        account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
 
76
            'move_ids': [(4, move_id, False)]
 
77
        })
 
78
 
 
79
        torec = []
 
80
        if st_line.amount >= 0:
 
81
            account_id = st.journal_id.default_credit_account_id.id
 
82
        else:
 
83
            account_id = st.journal_id.default_debit_account_id.id
 
84
 
 
85
        acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id
 
86
        context.update({
 
87
                'res.currency.compute.account': acc_cur,
 
88
            })
 
89
        amount = res_currency_obj.compute(cr, uid, st.currency.id,
 
90
                company_currency_id, st_line.amount, context=context)
 
91
        
 
92
        val = {
 
93
            'name': st_line.name,
 
94
            'date': st_line.date,
 
95
            'ref': st_line.ref,
 
96
            'move_id': move_id,
 
97
            'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False,
 
98
            'account_id': (st_line.account_id) and st_line.account_id.id,
 
99
            'credit': ((amount>0) and amount) or 0.0,
 
100
            'debit': ((amount<0) and -amount) or 0.0,
 
101
            'statement_id': st.id,
 
102
            'journal_id': st.journal_id.id,
 
103
            'period_id': st.period_id.id,
 
104
          #  'currency_id': st.currency.id,
 
105
            'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False
 
106
        }
 
107
 
 
108
        if st.currency.id <> company_currency_id:
 
109
            amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
 
110
                        st.currency.id, amount, context=context)
 
111
            val['amount_currency'] = -amount_cur
 
112
 
 
113
        if st_line.account_id and st_line.account_id.currency_id and st_line.account_id.currency_id.id <> company_currency_id:
 
114
            val['currency_id'] = st_line.account_id.currency_id.id
 
115
            amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
 
116
                    st_line.account_id.currency_id.id, amount, context=context)
 
117
            val['amount_currency'] = -amount_cur
 
118
 
 
119
        move_line_id = account_move_line_obj.create(cr, uid, val, context=context)
 
120
 
 
121
        torec.append(move_line_id)
 
122
 
 
123
        # Fill the secondary amount/currency
 
124
        # if currency is not the same than the company
 
125
        amount_currency = False
 
126
        currency_id = False
 
127
        if st.currency.id <> company_currency_id:
 
128
            amount_currency = st_line.amount
 
129
            currency_id = st.currency.id
 
130
        account_move_line_obj.create(cr, uid, {
 
131
            'name': st_line.name,
 
132
            'date': st_line.date,
 
133
            'ref': st_line.ref,
 
134
            'move_id': move_id,
 
135
            'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False,
 
136
            'account_id': account_id,
 
137
            'credit': ((amount < 0) and -amount) or 0.0,
 
138
            'debit': ((amount > 0) and amount) or 0.0,
 
139
            'statement_id': st.id,
 
140
            'journal_id': st.journal_id.id,
 
141
            'period_id': st.period_id.id,
 
142
            'amount_currency': amount_currency,
 
143
            #'currency_id': currency_id,
 
144
            'cash_move_type': st_line.cash_move_type.id # Мөнгөн гүйлгээний төрөл
 
145
            }, context=context)
 
146
        # Мөнгөн гүйлгээний зөв төрөл сонгосон эсэхийг шалгана
 
147
        if st_line.cash_move_type and st_line.cash_move_type.group <> 'dummy':
 
148
            if amount > 0 and st_line.cash_move_type.group not in ('activities_income','investing_income','financing_income'):
 
149
                raise osv.except_osv(_('Integrity Error!'), _('You have selected wrong cash move type. Please to point in transaction amount sign!'))
 
150
            elif amount < 0 and st_line.cash_move_type.group not in ('activities_expense','investing_expense','financing_expense'):
 
151
                raise osv.except_osv(_('Integrity Error!'), _('You have selected wrong cash move type. Please to point in transaction amount sign!'))
 
152
 
 
153
        for line in account_move_line_obj.browse(cr, uid, [x.id for x in
 
154
                account_move_obj.browse(cr, uid, move_id,
 
155
                    context=context).line_id],
 
156
                context=context):
 
157
            if line.state <> 'valid':
 
158
                raise osv.except_osv(_('Error !'),
 
159
                        _('Journal item "%s" is not valid.') % line.name)
 
160
 
 
161
        # Bank statements will not consider boolean on journal entry_posted
 
162
        account_move_obj.post(cr, uid, [move_id], context=context)
 
163
        return move_id
 
164
 
 
165
account_bank_statement()
 
166
 
 
167
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'