Skip to content

Commit 3ab98e1

Browse files
committed
Adapting code to odoo 9
1 parent 6e2c7e1 commit 3ab98e1

6 files changed

+51
-59
lines changed

staff_management/staff_booking.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ class staff_booking(models.Model):
5656
#Check if the hour from is between 0 and 24
5757
@api.model
5858
def _check_hour_to(self, ids):
59-
for event in self.browse(cr, uid, ids):
59+
for event in self.browse(ids):
6060
if(event.hour_to < 0 or event.hour_to > 24):
6161
return False
6262
return True
6363

6464
#Check if the hour to is between 0 and 24
6565
@api.model
6666
def _check_hour_from(self, ids):
67-
for event in self.browse(cr, uid, ids):
67+
for event in self.browse(ids):
6868
if(event.hour_from < 0 or event.hour_from > 24):
6969
return False
7070
return True

staff_management/staff_comments.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
#
2020
##############################################################################
21-
from openerp.osv import orm, fields
21+
from openerp import api, fields, models
2222
import datetime
2323

24-
class staff_comments(orm.Model):
24+
class staff_comments(models.Model):
2525
_name="staff.comments"
2626

2727
comment = fields.Text('Comment',required=True)
2828
user_id = fields.Many2one('res.users', 'User', readonly=False, relate=True)
2929
comment_type = fields.Many2one('staff.comment.type', 'Comment Type', readonly=False, relate=True)
3030
create_uid = fields.Many2one('res.users', 'Author', readonly=True, relate=True)
31-
write_date = fields.date('Date of comment',readonly=True )
31+
write_date = fields.Date('Date of comment',readonly=True )
3232

33-
34-
staff_comments()

staff_management/staff_events.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class staff_events(models.Model):
2525

2626
event_name = fields.Char('Event',size= 32 ,required=True)
2727
date = fields.Date('Date', readonly=False)
28-
hour_from = fields.float('Start Hour', readonly=False)
29-
hour_to = fields.float('End Hour', readonly=False)
28+
hour_from = fields.Float('Start Hour', readonly=False)
29+
hour_to = fields.Float('End Hour', readonly=False)
3030

3131

3232
_rec_name = 'event_name'

staff_management/staff_pay_push.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
#
2121
##############################################################################
22-
from openerp.osv import fields
23-
from openerp.osv.orm import TransientModel
22+
from openerp import api, fields, models
2423
from openerp.tools.translate import _
2524
from datetime import datetime
2625
from staff_utils import staff_utils
2726

28-
class staff_pay_push(TransientModel):
27+
class staff_pay_push(models.TransientModel):
2928
_name="staff.pay.push"
3029

3130
user_id = fields.Many2one('res.users', 'User', relate=True)
@@ -40,37 +39,37 @@ class staff_pay_push(TransientModel):
4039
date = fields.Date('Date')
4140
state = fields.Selection([('init', 'init'),('defineAmount', 'defineAmount')])
4241

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)])
4846
#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), ))
5048
ammount = cr.fetchone()
5149
return ammount[0]
5250

53-
def getDifMonth(self, cr, uid, user_id, date):
51+
@api.model
52+
def getDifMonth(self, user_id, date):
5453
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)])
5756
#Excecute SQL for optimization! "For" loop will take too long on future.
5857
first = utils.get_first_day_month(date.strftime("%Y-%m-%d"))
5958
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, ))
6160
ammount = cr.fetchone()
6261
return ammount[0]
6362

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):
6665
user_id = int(user_id)
67-
creditTotal = self.getDif(cr, uid, user_id)
66+
creditTotal = self.getDif(user_id)
6867
date = datetime.strptime(date_str, "%Y-%m-%d")
69-
creditMonth = self.getDifMonth(cr, uid, user_id, date)
68+
creditMonth = self.getDifMonth(user_id, date)
7069
#Hard coded. TODO some better code on next releases.
7170
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')])
7473
if len(account) == 0:
7574
accoundId = 0
7675
else:
@@ -82,8 +81,9 @@ def get_form_context(self, cr, uid, user_id, date_str):
8281
'journal':2,
8382
'account':1,
8483
'analytic_account':accoundId,}
85-
86-
def create(self, cr, uid, vals, context=None):
84+
85+
@api.model
86+
def create(self, vals, context=None):
8787
if context.has_key('default_user_id_read'):
8888
user_id = context['default_user_id_read']
8989
if vals.has_key('journal'):
@@ -94,17 +94,17 @@ def create(self, cr, uid, vals, context=None):
9494
account = vals['account']
9595
else:
9696
account = 1
97-
account_lines = self.pool.get('account.analytic.line')
97+
account_lines = self.env['account.analytic.line']
9898
account_lines.create(cr, uid, {'name': vals['comment'], 'account_id': vals['analytic_account'],
9999
'journal_id':journal, 'user_id':user_id, 'date': vals['date'],
100100
'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)
102102

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)
108108
dic = {}
109109
for record in values:
110110
dayInMonth = record.date[8:10]
@@ -121,7 +121,5 @@ def get_month_salaries(self, cr, uid, domain):
121121
userDic[dayInMonth] = {'timework':[dayWorkTime], 'amounts':[dayAmount]}
122122
else:
123123
dic[record.user_id.id] = {'name':record.user_id.name, dayInMonth:{'timework':[dayWorkTime], 'amounts':[dayAmount]}}
124-
125124
return dic
126125

127-
staff_pay_push()

staff_management/staff_scheduler.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@
2929
class staff_scheduler(models.Model):
3030
_name="staff.scheduler"
3131

32-
_columns={
33-
'user_id':fields.Many2one('res.users', 'User', readonly=True, relate=True),
34-
'task_id':fields.Many2one('account.analytic.account', 'Task', readonly=False),
35-
'date': fields.Date('Date', readonly=True),
36-
'hour_from': fields.Float('Start Hour', readonly=False),
37-
'hour_to': fields.Float('End Hour', readonly=False),
38-
'comment':fields.Char('Comment',size= 512 ,required=False),
39-
'work_time':fields.Float('Worked time', readonly=False),
40-
'confirm':fields.Boolean('Confirm', readonly=False),
41-
'replaceable':fields.Boolean('Replaceable', readonly=False, default=False),
42-
}
32+
user_id = fields.Many2one('res.users', 'User', readonly=True, relate=True)
33+
task_id = fields.Many2one('account.analytic.account', 'Task', readonly=False)
34+
date = fields.Date('Date', readonly=True)
35+
hour_from = fields.Float('Start Hour', readonly=False)
36+
hour_to = fields.Float('End Hour', readonly=False)
37+
comment = fields.Char('Comment',size= 512 ,required=False)
38+
work_time = fields.Float('Worked time', readonly=False)
39+
confirm = fields.Boolean('Confirm', readonly=False)
40+
replaceable = fields.Boolean('Replaceable', readonly=False, default=False)
4341

4442
#Check if the hour from is between 0 and 24
4543
@api.model
@@ -214,8 +212,9 @@ def swapUidTask(self, task_id):
214212
# add user_id to create the elements
215213
@api.model
216214
def create(self, vals):
217-
vals['user_id']=user
218-
vals['task_id']=False
215+
user = self._context['uid']
216+
vals['user_id'] = user
217+
vals['task_id'] = False
219218
#Control if an event is set this day.
220219
listTasks = self.search([('date','=',vals['date']),('user_id','=',user)])
221220
if len(listTasks) >= 1:
@@ -229,13 +228,12 @@ def create(self, vals):
229228
#Remove an availability with assignement check.
230229
@api.model
231230
def unlink(self, ids):
232-
records = super(staff_scheduler, self).read(ids, ['id', 'task_id'])
231+
record = self.browse(ids)
233232
#raise Exception(records) if a user want remove an availibility with a task
234-
if(records[0]['task_id']):
233+
if record.task_id.id:
235234
raise except_orm(_('Error'), _("You can't delete this availability because there is an assigned task on it."))
236235
#Check the unlink date.
237-
date = super(staff_scheduler, self).read(ids, ['date'])
238-
if self.checkPastDay(datetime.strptime(date[0]['date'], "%Y-%m-%d")):
236+
if self.checkPastDay(datetime.strptime(record.date, "%Y-%m-%d")):
239237
raise except_orm(_('Error'), _("Only future dates can be changed."))
240238
return super(staff_scheduler, self).unlink(ids)
241239

staff_management/staff_timesheet.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@
2323
class staff_timesheet(models.Model):
2424
_name="staff.timesheet"
2525

26-
_columns={
27-
'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
28-
}
26+
user_id = fields.Many2one('res.users', 'User', readonly=True, relate=True)
2927

0 commit comments

Comments
 (0)