An employee should receive a mail.message in inbox when an manager refuse a timesheet.
authorTejas Tank <tta@openerp.com>
Thu, 22 Nov 2012 11:00:15 +0000 (16:30 +0530)
committerTejas Tank <tta@openerp.com>
Thu, 22 Nov 2012 11:00:15 +0000 (16:30 +0530)
bzr revid: tta@openerp.com-20121122110015-61xx09vchksen6v3

addons/hr_timesheet_sheet/hr_timesheet_sheet.py
addons/hr_timesheet_sheet/hr_timesheet_sheet_data.xml
addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml

index 15eb6d3..36b76c0 100644 (file)
@@ -100,6 +100,15 @@ class hr_timesheet_sheet(osv.osv):
                 raise osv.except_osv(_('Warning!'), _('Please verify that the total difference of the sheet is lower than %.2f.') %(di,))
         return True
 
+    def button_cancel(self, cr, uid, ids, context=None):
+        for sheet in self.browse(cr, uid, ids, context=context):
+            if sheet.employee_id and sheet.employee_id.user_id:
+                self.message_subscribe_users(cr, uid, [sheet.id], user_ids=[sheet.employee_id.user_id.id], context=context)
+            wf_service = netsvc.LocalService("workflow")
+            wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'cancel', cr)
+            self.cancel_send_note(cr, uid, ids, context=context)
+        return True
+
     def attendance_action_change(self, cr, uid, ids, context=None):
         hr_employee = self.pool.get('hr.employee')
         employee_ids = []
@@ -237,6 +246,11 @@ class hr_timesheet_sheet(osv.osv):
         for obj in self.browse(cr, uid, ids, context=context):
             self.message_post(cr, uid, [obj.id], body=_("Timesheet has been submitted by %s.") % (obj.employee_id.name), subtype="hr_timesheet_sheet.mt_submit_timesheet", context=context)
 
+    def cancel_send_note(self, cr, uid, ids, context=None):
+        user_name = self.pool.get("res.users").browse(cr, uid, uid, context=context).name
+        for obj in self.browse(cr, uid, ids, context=context):
+            self.message_post(cr, uid, [obj.id], body=_("Timesheet has been refused by %s.") % (user_name), subtype="hr_timesheet_sheet.mt_refuse_timesheet", context=context)
+
 hr_timesheet_sheet()
 
 class account_analytic_line(osv.osv):
index 0f081a3..84d85c4 100644 (file)
         <menuitem name="My Current Timesheet" id="menu_act_hr_timesheet_sheet_form_my_current" parent="hr_attendance.menu_hr_time_tracking" action="ir_actions_server_timsheet_sheet" sequence="1"/>
         
         <record id="mt_submit_timesheet" model="mail.message.subtype">
-            <field name="name">Timesheets to Validate</field>
+            <field name="name">Submit</field>
+            <field name="res_model">hr_timesheet_sheet.sheet</field>
+        </record>
+
+        <record id="mt_refuse_timesheet" model="mail.message.subtype">
+            <field name="name">Refuse</field>
             <field name="res_model">hr_timesheet_sheet.sheet</field>
         </record>
 
index 6de6be6..a78ab4b 100644 (file)
@@ -66,7 +66,7 @@
                     <button name="button_confirm" states="draft" string="Submit to Manager" type="object" class="oe_highlight"/>
                     <button name="done" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button name="action_set_to_draft" states="done" string="Set to Draft" type="object" />
-                    <button name="cancel" states="confirm" string="Refuse" type="workflow" groups="base.group_hr_user" />
+                    <button name="button_cancel" states="confirm" string="Refuse" type="object" groups="base.group_hr_user" />
                     <field name="state" widget="statusbar" statusbar_visible="new,confirm,done"/>
                 </header>
                 <sheet>