~torbat-j/+junk/ncdierp

« back to all changes in this revision

Viewing changes to ierp_loan/wizard/loan_schedule_graph.py

  • Committer: erka
  • Date: 2014-10-21 08:43:45 UTC
  • Revision ID: erka-20141021084345-vb5veh7pk63zeys9
Зээл болон худалдан авалтын классын дагуу нэмэлт талбаруудыг нэмэв.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
import time
 
3
from datetime import datetime
 
4
from datetime import date
 
5
from dateutil.relativedelta import relativedelta
 
6
from osv import osv, fields
 
7
import netsvc
 
8
import calendar
 
9
import pooler
 
10
from tools.translate import _
 
11
import decimal_precision as dp
 
12
from osv.orm import browse_record, browse_null
 
13
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
 
14
 
 
15
class loan_schedule_graph(osv.osv_memory):
 
16
    _name = "loan.schedule.graph"
 
17
    
 
18
    def _payment_date(self, cr, uid, ids, context=None):
 
19
        if ids.has_key('active_id'):
 
20
            loan_data = self.pool.get('loan.schedule').browse(cr, uid, ids['active_id'])
 
21
            return loan_data.payment_date
 
22
 
 
23
    def _loan_payment(self, cr, uid, ids, context=None):
 
24
        if ids.has_key('active_id'):
 
25
            loan_data = self.pool.get('loan.schedule').browse(cr, uid, ids['active_id'])
 
26
            return loan_data.loan_payment
 
27
 
 
28
    _columns = {        
 
29
        'loan_payment':fields.float(u'Loan', digits=(16, 2), required=True),
 
30
        'payment_date': fields.date(u'Date', required=True),     
 
31
        'schedule_id': fields.many2one('loan.schedule', 'Schedule'),
 
32
    }
 
33
    
 
34
    _defaults = {
 
35
        'loan_payment':_loan_payment,
 
36
        'payment_date': _payment_date,
 
37
    }
 
38
    
 
39
    def edit_graphics(self, cr, uid, ids, context=None):
 
40
        loan_obj = self.pool.get('loan.schedule')
 
41
        print context
 
42
        load_id=False
 
43
        if context.has_key('active_id'):
 
44
          load_id = context.get('active_id')
 
45
        if load_id:
 
46
            loan_obj.write(cr, uid, [load_id], {'loan_payment':self.browse(cr, uid, ids)[0].loan_payment})
 
47
            loan_obj.edit_graphics(cr, uid, [load_id], context=context)
 
48
            contract_id= loan_obj.browse(cr, uid, load_id).contract_id.id
 
49
            print "Contract id: ",contract_id
 
50
            order_id = self.pool.get('loan.schedule').search(cr, uid, [('contract_id','=',contract_id)])
 
51
            print "Order id: ",order_id
 
52
            for line in self.pool.get('loan.schedule').browse(cr, uid, order_id):
 
53
                print "Line schedule: ",line.edit_schedule
 
54
                if line.edit_schedule:                    
 
55
                    self.pool.get('loan.schedule').write(cr, uid, line.id, {'edit_schedule': False}, context)
 
56
                    print "Edit schedule1::::::::::::::: ",line.edit_schedule
 
57
                else:
 
58
                    self.pool.get('loan.schedule').write(cr, uid, line.id, {'edit_schedule': True}, context)
 
59
                    print "Edit schedule2::::::::::::::: ",line.edit_schedule
 
60
        return True
 
61
#     def edit_graphics(self, cr, uid, ids, context=None):
 
62
#         self_data = self.browse(cr, uid, ids[0])
 
63
#         now = self.pool.get('loan.schedule').browse(cr, uid, context['active_ids'])[0]
 
64
#         now.write({'payment_date': self_data.payment_date, 'loan_payment': self_data.loan_payment})
 
65
#         con = now.contract_id
 
66
#         print '--writed------', con.interest, ids[0]
 
67
#         gtype = con.schedule_type
 
68
#         rate = con.interest
 
69
#         print 'GTYPE-', gtype
 
70
#         
 
71
#         if 0 <= now.loan_payment:
 
72
#             pre_balance = con.loan_balance 
 
73
#             if now.prior_id != 0:
 
74
#                 pre = self.pool.get('loan.schedule').browse(cr, uid, now.prior_id)
 
75
#                 pre_balance = pre.balance
 
76
 
77
#             balance = pre_balance - now.loan_payment
 
78
#             niit = now.loan_payment     + now.interest_payment
 
79
#             print "NOW: ID: ",now.id
 
80
#             print 'writed self', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
81
#                                                                     {'loan_payment':now.loan_payment,
 
82
#                                                                      'total_payment':niit,
 
83
#                                                                      'balance':balance}, context)
 
84
#             print 'gacha....', now.loan_payment, niit, balance
 
85
#             
 
86
#             nextid = self.pool.get('loan.schedule').search(cr, uid, [('prior_id', '=', now.id)])
 
87
#             print 'next', nextid
 
88
#             
 
89
#             last = 0
 
90
#             niit = 0.0
 
91
#             
 
92
#             while nextid != []:
 
93
#                 vz = 0.0
 
94
#                 balance = 0.0
 
95
#                 now = self.pool.get('loan.schedule').browse(cr, uid, nextid[0])
 
96
#                 pre = self.pool.get('loan.schedule').browse(cr, uid, now.prior_id)
 
97
#                 if last == 1:
 
98
#                     print 'deleted other', self.pool.get('loan.schedule').unlink(cr, uid, now.id, context) 
 
99
#                     break   
 
100
#                 else:
 
101
#                     c = rate / 100
 
102
#                     xvv = pre.balance * c / 30 * now.days    
 
103
#                     if gtype == 'type1':
 
104
#                         vz = now.total_payment - xvv
 
105
#                         balance = pre.balance - vz
 
106
#                         if balance <= 0 :
 
107
#                             niit = xvv + pre.balance
 
108
#                             vz = pre.balance
 
109
#                             balance = 0
 
110
#                             print gtype, '1vz', vz, 'xvv', xvv, 'niit', now.total_payment, 'balance', balance
 
111
#                             print gtype, '1writed  - Balance', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
112
#                                             {'loan_payment':vz,
 
113
#                                              'interest_payment':xvv,
 
114
#                                              'total_payment':niit,
 
115
#                                              'balance':balance}, context)    
 
116
#                             last = 1
 
117
#                         
 
118
#                         nextid = self.pool.get('loan.schedule').search(cr, uid, [('prior_id', '=', now.id)])
 
119
#                         if nextid == [] and balance > 0:
 
120
#                             vz += balance
 
121
#                             balance = 0
 
122
#                             niit = xvv + vz
 
123
#                             print gtype, '1writed other', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
124
#                                                         {'loan_payment':vz,
 
125
#                                                          'interest_payment':xvv,
 
126
#                                                          'total_payment':niit,
 
127
#                                                          'balance':balance}, context)
 
128
#                                                          
 
129
#                         print gtype, '1vz', vz, 'xvv', xvv, 'niit', now.total_payment, 'balance', balance
 
130
#                         print gtype, '1writed other', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
131
#                                                         {'loan_payment':vz,
 
132
#                                                          'interest_payment':xvv,
 
133
#                                                          'balance':balance}, context)
 
134
 
135
#                     if gtype == 'type3' or gtype == 'type5':                    
 
136
#                         niit = now.loan_payment + xvv
 
137
#                         balance = pre.balance - now.loan_payment
 
138
#                         if balance <= 0 :
 
139
#                             niit = xvv + pre.balance
 
140
#                             vz = pre.balance
 
141
#                             balance = 0
 
142
#                             print gtype, '2vz', now.loan_payment, 'xvv', xvv, 'niit', niit, 'balance', balance, "aaaaaaaaaaaaaaaaaaaaaadd"
 
143
#                             print gtype, '2writed  - Balance', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
144
#                                             {'loan_payment':vz,
 
145
#                                              'interest_payment':xvv,
 
146
#                                              'total_payment':niit,
 
147
#                                              'balance':balance}, context)    
 
148
#                             last = 1
 
149
#                 nextid = self.pool.get('loan.schedule').search(cr, uid, [('prior_id', '=', now.id)])
 
150
#                 if nextid == [] and balance > 0:
 
151
#                         niit = xvv + pre.balance
 
152
#                         vz = pre.balance
 
153
#                         balance = 0
 
154
#                         print now.total_payment, '2vz', vz, 'xvv', xvv, 'niit', now.total_payment, 'balance', balance, "last", last
 
155
#                         print gtype, '2writed other', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
156
#                                                     {'total_payment':niit,
 
157
#                                                      'loan_payment':vz,
 
158
#                                                      'interest_payment':xvv,
 
159
#                                                      'balance':balance}, context)
 
160
#                 else:
 
161
#                         print now.total_payment, '2vz', vz, 'xvv', xvv, 'niit', now.total_payment, 'balance', balance, "last", last
 
162
#                         print gtype, '2writed other', self.pool.get('loan.schedule').write(cr, uid, now.id,
 
163
#                             {'total_payment':niit,
 
164
#                              'interest_payment':xvv,
 
165
#                              'balance':balance}, context)
 
166
#                 # bichilt
 
167
#                 nextid = self.pool.get('loan.schedule').search(cr, uid, [('prior_id', '=', now.id)])
 
 
b'\\ No newline at end of file'