diff --git a/line.py b/line.py index 7c9ebe8111..1e8dfb64b6 100644 --- a/line.py +++ b/line.py @@ -116,95 +116,6 @@ class EnterLines(Wizard): EnterLines() -class HoursWorkType(OSV): - 'Hours per Work Type' - _name = 'timesheet.hours_work_type' - - work_type = fields.Many2One('timesheet.work_type', 'Work Type', select=1) - hours = fields.Function('get_hours', digits=(16, 2), string='Hours') - - def table_query(self, context=None): - return ('SELECT DISTINCT(work_type) AS id, work_type ' \ - 'FROM timesheet_line', []) - - def get_hours(self, cursor, user, ids, name, arg, context=None): - res = {} - clause = ' ' - args = [] - for work_type_id in ids: - res[work_type_id] = 0.0 - - if context.get('start_date'): - clause += 'AND date >= %s ' - args.append(context['start_date']) - if context.get('end_date'): - clause += 'AND date <= %s ' - args.append(context['end_date']) - - cursor.execute('SELECT work_type, SUM(COALESCE(hours, 0)) ' \ - 'FROM timesheet_line ' - 'WHERE work_type IN (' + \ - ','.join(['%s' for x in ids]) + ') ' \ - + clause + - 'GROUP BY work_type', ids + args) - for work_type_id, sum in cursor.fetchall(): - res[work_type_id] = sum - return res - -HoursWorkType() - - -class OpenHoursWorkTypeInit(WizardOSV): - _name = 'timesheet.open_hours_work_type.init' - start_date = fields.Date('Start Date') - end_date = fields.Date('End Date') - -OpenHoursWorkTypeInit() - - -class OpenHoursWorkTypes(Wizard): - 'Open Hours per Work Type' - _name = 'timesheet.open_hours_work_type' - states = { - 'init': { - 'result': { - 'type': 'form', - 'object': 'timesheet.open_hours_work_type.init', - 'state': [ - ('end', 'Cancel', 'gtk-cancel'), - ('open', 'Open', 'gtk-ok', True), - ], - }, - }, - 'open': { - 'result': { - 'type': 'action', - 'action': '_action_open', - 'state': 'end', - }, - }, - } - - def _action_open(self, cursor, user, data, context=None): - model_data_obj = self.pool.get('ir.model.data') - act_window_obj = self.pool.get('ir.action.act_window') - - model_data_ids = model_data_obj.search(cursor, user, [ - ('fs_id', '=', 'act_hours_work_type_form'), - ('module', '=', 'timesheet'), - ], limit=1, context=context) - model_data = model_data_obj.browse(cursor, user, model_data_ids[0], - context=context) - res = act_window_obj.read(cursor, user, model_data.db_id, context=context) - res['context'] = str({ - 'start_date': data['form']['start_date'], - 'end_date': data['form']['end_date'], - }) - return res - -OpenHoursWorkTypes() - - class HoursEmployee(OSV): 'Hours per Employee' _name = 'timesheet.hours_employee' diff --git a/line.xml b/line.xml index e689a04257..a0fb5b6e77 100644 --- a/line.xml +++ b/line.xml @@ -63,73 +63,6 @@ - - timesheet.hours_work_type - tree - - - - - - ]]> - - - - timesheet.hours_work_type - graph - - - - - - - - - - ]]> - - - - Hours per Work Type - timesheet.hours_work_type - form - - - - - - - - - - - - - - timesheet.open_hours_work_type.init - form - - - - - Hours per Work Type - timesheet.open_hours_work_type - - - timesheet.hours_employee tree diff --git a/work_type.py b/work_type.py index e7af891985..2812b206e4 100644 --- a/work_type.py +++ b/work_type.py @@ -159,3 +159,26 @@ class OpenWorkType(Wizard): return res OpenWorkType() + + +class OpenWorkType2(OpenWorkType): + _name = 'timesheet.work_type.open2' + + def _action_open_work_type(self, cursor, user, data, context=None): + model_data_obj = self.pool.get('ir.model.data') + act_window_obj = self.pool.get('ir.action.act_window') + + model_data_ids = model_data_obj.search(cursor, user, [ + ('fs_id', '=', 'act_work_type_form2'), + ('module', '=', 'timesheet'), + ], limit=1, context=context) + model_data = model_data_obj.browse(cursor, user, model_data_ids[0], + context=context) + res = act_window_obj.read(cursor, user, model_data.db_id, context=context) + res['context'] = str({ + 'from_date': data['form']['from_date'], + 'to_date': data['form']['to_date'], + }) + return res + +OpenWorkType2() diff --git a/work_type.xml b/work_type.xml index 3a2bfe29ca..e126d793a4 100644 --- a/work_type.xml +++ b/work_type.xml @@ -90,7 +90,6 @@ - ]]> @@ -109,11 +108,46 @@ - Open Work Types + Hours per Work Type timesheet.work_type.open - + + + + timesheet.work_type + graph + + + + + + + + + + ]]> + + + + Hours per Work Type + timesheet.work_type + form + [('parent', '=', False)] + + + + + + + + Hours per Work Type + timesheet.work_type.open2 + +