19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
#
21
21
##############################################################################
22
- from openerp .osv import fields
23
- from openerp .osv .orm import TransientModel
22
+ from openerp import api , fields , models
24
23
from openerp .tools .translate import _
25
24
from datetime import datetime
26
25
from staff_utils import staff_utils
27
26
28
- class staff_pay_push (TransientModel ):
27
+ class staff_pay_push (models . TransientModel ):
29
28
_name = "staff.pay.push"
30
29
31
30
user_id = fields .Many2one ('res.users' , 'User' , relate = True )
@@ -40,37 +39,37 @@ class staff_pay_push(TransientModel):
40
39
date = fields .Date ('Date' )
41
40
state = fields .Selection ([('init' , 'init' ),('defineAmount' , 'defineAmount' )])
42
41
43
-
44
-
45
- def getDif (self , cr , uid , user_id ):
46
- account_lines = self .pool .get ('account.analytic.line' )
47
- user_lines = account_lines .search (cr , uid , [('user_id' , '=' , user_id )])
42
+ @api .model
43
+ def getDif (self , user_id ):
44
+ account_lines = self .env ['account.analytic.line' ]
45
+ user_lines = account_lines .search ([('user_id' , '=' , user_id )])
48
46
#Excecute SQL for optimization! "For" loop will take too long on future.
49
- cr .execute ('Select sum(amount) from account_analytic_line where user_id = ' + str (user_id ))
47
+ cr .execute ('Select sum(amount) from account_analytic_line where user_id = %s' , ( str (user_id ), ))
50
48
ammount = cr .fetchone ()
51
49
return ammount [0 ]
52
50
53
- def getDifMonth (self , cr , uid , user_id , date ):
51
+ @api .model
52
+ def getDifMonth (self , user_id , date ):
54
53
utils = staff_utils ()
55
- account_lines = self .pool . get ( 'account.analytic.line' )
56
- user_lines = account_lines .search (cr , uid , [('user_id' , '=' , user_id )])
54
+ account_lines = self .env [ 'account.analytic.line' ]
55
+ user_lines = account_lines .search ([('user_id' , '=' , user_id )])
57
56
#Excecute SQL for optimization! "For" loop will take too long on future.
58
57
first = utils .get_first_day_month (date .strftime ("%Y-%m-%d" ))
59
58
last = utils .get_last_day_month (date .strftime ("%Y-%m-%d" ))
60
- cr .execute ('Select sum(amount) from account_analytic_line where user_id = ' + str ( user_id ) + ' and date::date <= \' ' + last + ' \' and date::date >= \' ' + first + ' \' ' )
59
+ cr .execute ('Select sum(amount) from account_analytic_line where user_id = %s and date::date <= %s and date::date >= %s' , ( str ( user_id ), last , first , ) )
61
60
ammount = cr .fetchone ()
62
61
return ammount [0 ]
63
62
64
-
65
- def get_form_context (self , cr , uid , user_id , date_str ):
63
+ @ api . model
64
+ def get_form_context (self , user_id , date_str ):
66
65
user_id = int (user_id )
67
- creditTotal = self .getDif (cr , uid , user_id )
66
+ creditTotal = self .getDif (user_id )
68
67
date = datetime .strptime (date_str , "%Y-%m-%d" )
69
- creditMonth = self .getDifMonth (cr , uid , user_id , date )
68
+ creditMonth = self .getDifMonth (user_id , date )
70
69
#Hard coded. TODO some better code on next releases.
71
70
account = [0 ];
72
- account_lines = self .pool . get ( 'account.analytic.account' )
73
- account = account_lines .search (cr , uid , [('name' , '=' , 'Salaires' )])
71
+ account_lines = self .env [ 'account.analytic.account' ]
72
+ account = account_lines .search ([('name' , '=' , 'Salaires' )])
74
73
if len (account ) == 0 :
75
74
accoundId = 0
76
75
else :
@@ -82,8 +81,9 @@ def get_form_context(self, cr, uid, user_id, date_str):
82
81
'journal' :2 ,
83
82
'account' :1 ,
84
83
'analytic_account' :accoundId ,}
85
-
86
- def create (self , cr , uid , vals , context = None ):
84
+
85
+ @api .model
86
+ def create (self , vals , context = None ):
87
87
if context .has_key ('default_user_id_read' ):
88
88
user_id = context ['default_user_id_read' ]
89
89
if vals .has_key ('journal' ):
@@ -94,17 +94,17 @@ def create(self, cr, uid, vals, context=None):
94
94
account = vals ['account' ]
95
95
else :
96
96
account = 1
97
- account_lines = self .pool . get ( 'account.analytic.line' )
97
+ account_lines = self .env [ 'account.analytic.line' ]
98
98
account_lines .create (cr , uid , {'name' : vals ['comment' ], 'account_id' : vals ['analytic_account' ],
99
99
'journal_id' :journal , 'user_id' :user_id , 'date' : vals ['date' ],
100
100
'amount' :- vals ['amount' ], 'general_account_id' :account ,}, context )
101
- return super (staff_pay_push , self ).create (cr , uid , vals , context )
101
+ return super (staff_pay_push , self ).create (vals , context )
102
102
103
-
104
- def get_month_salaries (self , cr , uid , domain ):
105
- account = self .pool . get ( 'account.analytic.line' )
106
- ids = account .search (cr , uid , domain )
107
- values = account .browse (cr , uid , ids )
103
+ @ api . model
104
+ def get_month_salaries (self , domain ):
105
+ account = self .env [ 'account.analytic.line' ]
106
+ ids = account .search (domain )
107
+ values = account .browse (ids )
108
108
dic = {}
109
109
for record in values :
110
110
dayInMonth = record .date [8 :10 ]
@@ -121,7 +121,5 @@ def get_month_salaries(self, cr, uid, domain):
121
121
userDic [dayInMonth ] = {'timework' :[dayWorkTime ], 'amounts' :[dayAmount ]}
122
122
else :
123
123
dic [record .user_id .id ] = {'name' :record .user_id .name , dayInMonth :{'timework' :[dayWorkTime ], 'amounts' :[dayAmount ]}}
124
-
125
124
return dic
126
125
127
- staff_pay_push ()
0 commit comments