/usr/lib/python2.7/dist-packages/trytond/modules/timesheet/line.py is in tryton-modules-timesheet 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from sql import Literal
from sql.aggregate import Max, Sum
from sql.conditionals import Coalesce
from sql.functions import Extract
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.pyson import Eval, PYSONEncoder, Date, Get
from trytond.transaction import Transaction
from trytond.pool import Pool
__all__ = ['Line', 'EnterLinesStart', 'EnterLines',
'HoursEmployee',
'OpenHoursEmployeeStart', 'OpenHoursEmployee',
'HoursEmployeeWeekly', 'HoursEmployeeMonthly']
class Line(ModelSQL, ModelView):
'Timesheet Line'
__name__ = 'timesheet.line'
employee = fields.Many2One('company.employee', 'Employee', required=True,
select=True, domain=[
('company', '=', Eval('context', {}).get('company', -1)),
])
date = fields.Date('Date', required=True, select=True)
hours = fields.Float('Hours', digits=(16, 2), required=True)
work = fields.Many2One('timesheet.work', 'Work',
required=True, select=True, domain=[
('timesheet_available', '=', True),
['OR',
('timesheet_start_date', '=', None),
('timesheet_start_date', '<=', Eval('date')),
],
['OR',
('timesheet_end_date', '=', None),
('timesheet_end_date', '>=', Eval('date')),
],
],
depends=['date'])
description = fields.Char('Description')
@classmethod
def __setup__(cls):
super(Line, cls).__setup__()
cls._order.insert(0, ('date', 'DESC'))
cls._sql_constraints += [
('check_move_hours_pos',
'CHECK(hours >= 0.0)', 'Hours field must be positive'),
]
@staticmethod
def default_employee():
User = Pool().get('res.user')
employee_id = None
if Transaction().context.get('employee'):
employee_id = Transaction().context['employee']
else:
user = User(Transaction().user)
if user.employee:
employee_id = user.employee.id
if employee_id:
return employee_id
@staticmethod
def default_date():
Date_ = Pool().get('ir.date')
return Transaction().context.get('date') or Date_.today()
@classmethod
def view_header_get(cls, value, view_type='form'):
if not Transaction().context.get('employee'):
return value
Employee = Pool().get('company.employee')
employee = Employee(Transaction().context['employee'])
return value + " (" + employee.rec_name + ")"
class EnterLinesStart(ModelView):
'Enter Lines'
__name__ = 'timesheet.line.enter.start'
employee = fields.Many2One('company.employee', 'Employee', required=True,
domain=[('company', '=', Eval('context', {}).get('company', -1))])
date = fields.Date('Date', required=True)
@staticmethod
def default_employee():
Line = Pool().get('timesheet.line')
return Line.default_employee()
@staticmethod
def default_date():
Line = Pool().get('timesheet.line')
return Line.default_date()
class EnterLines(Wizard):
'Enter Lines'
__name__ = 'timesheet.line.enter'
start = StateView('timesheet.line.enter.start',
'timesheet.line_enter_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Enter', 'enter', 'tryton-ok', default=True),
])
enter = StateAction('timesheet.act_line_form')
def do_enter(self, action):
date = self.start.date
date = Date(date.year, date.month, date.day)
action['pyson_domain'] = PYSONEncoder().encode([
('employee', '=', self.start.employee.id),
('date', '=', date),
])
action['pyson_context'] = PYSONEncoder().encode({
'employee': self.start.employee.id,
'date': date,
})
action['name'] += " - " + self.start.employee.rec_name
return action, {}
def transition_enter(self):
return 'end'
class HoursEmployee(ModelSQL, ModelView):
'Hours per Employee'
__name__ = 'timesheet.hours_employee'
employee = fields.Many2One('company.employee', 'Employee', select=True)
hours = fields.Float('Hours', digits=(16, 2))
@staticmethod
def table_query():
pool = Pool()
Line = pool.get('timesheet.line')
line = Line.__table__()
where = Literal(True)
if Transaction().context.get('start_date'):
where &= line.date >= Transaction().context['start_date']
if Transaction().context.get('end_date'):
where &= line.date <= Transaction().context['end_date']
return line.select(
line.employee.as_('id'),
Max(line.create_uid).as_('create_uid'),
Max(line.create_date).as_('create_date'),
Max(line.write_uid).as_('write_uid'),
Max(line.write_date).as_('write_date'),
line.employee,
Sum(Coalesce(line.hours, 0)).as_('hours'),
where=where,
group_by=line.employee)
class OpenHoursEmployeeStart(ModelView):
'Open Hours per Employee'
__name__ = 'timesheet.hours_employee.open.start'
start_date = fields.Date('Start Date')
end_date = fields.Date('End Date')
class OpenHoursEmployee(Wizard):
'Open Hours per Employee'
__name__ = 'timesheet.hours_employee.open'
start = StateView('timesheet.hours_employee.open.start',
'timesheet.hours_employee_open_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Open', 'open_', 'tryton-ok', default=True),
])
open_ = StateAction('timesheet.act_hours_employee_form')
def do_open_(self, action):
action['pyson_context'] = PYSONEncoder().encode({
'start_date': self.start.start_date,
'end_date': self.start.end_date,
})
return action, {}
def transition_open_(self):
return 'end'
class HoursEmployeeWeekly(ModelSQL, ModelView):
'Hours per Employee per Week'
__name__ = 'timesheet.hours_employee_weekly'
year = fields.Char('Year', select=True)
week = fields.Integer('Week', select=True)
employee = fields.Many2One('company.employee', 'Employee', select=True)
hours = fields.Float('Hours', digits=(16, 2), select=True)
@classmethod
def __setup__(cls):
super(HoursEmployeeWeekly, cls).__setup__()
cls._order.insert(0, ('year', 'DESC'))
cls._order.insert(1, ('week', 'DESC'))
cls._order.insert(2, ('employee', 'ASC'))
@classmethod
def table_query(cls):
pool = Pool()
Line = pool.get('timesheet.line')
line = Line.__table__()
type_name = cls.year.sql_type().base
year_column = Extract('YEAR', line.date).cast(type_name).as_('year')
week_column = Extract('WEEK', line.date).as_('week')
return line.select(
Max(Extract('WEEK', line.date)
+ Extract('YEAR', line.date) * 100
+ line.employee * 1000000).as_('id'),
Max(line.create_uid).as_('create_uid'),
Max(line.create_date).as_('create_date'),
Max(line.write_uid).as_('write_uid'),
Max(line.write_date).as_('write_date'),
year_column,
week_column,
line.employee,
Sum(Coalesce(line.hours, 0)).as_('hours'),
group_by=(year_column, week_column, line.employee))
class HoursEmployeeMonthly(ModelSQL, ModelView):
'Hours per Employee per Month'
__name__ = 'timesheet.hours_employee_monthly'
year = fields.Char('Year', select=True)
month = fields.Integer('Month', select=True)
employee = fields.Many2One('company.employee', 'Employee', select=True)
hours = fields.Float('Hours', digits=(16, 2), select=True)
@classmethod
def __setup__(cls):
super(HoursEmployeeMonthly, cls).__setup__()
cls._order.insert(0, ('year', 'DESC'))
cls._order.insert(1, ('month', 'DESC'))
cls._order.insert(2, ('employee', 'ASC'))
@classmethod
def table_query(cls):
pool = Pool()
Line = pool.get('timesheet.line')
line = Line.__table__()
type_name = cls.year.sql_type().base
year_column = Extract('YEAR', line.date).cast(type_name).as_('year')
month_column = Extract('MONTH', line.date).as_('month')
return line.select(
Max(Extract('MONTH', line.date)
+ Extract('YEAR', line.date) * 100
+ line.employee * 1000000).as_('id'),
Max(line.create_uid).as_('create_uid'),
Max(line.create_date).as_('create_date'),
Max(line.write_uid).as_('write_uid'),
Max(line.write_date).as_('write_date'),
year_column,
month_column,
line.employee,
Sum(Coalesce(line.hours, 0)).as_('hours'),
group_by=(year_column, month_column, line.employee))
|