[IMP]code cleaning in web and server side

bzr revid: dhr@tinyerp.com-20120508125745-ctyts4mqre4b8rnk
This commit is contained in:
Dharti Ratani (OpenERP) 2012-05-08 18:27:45 +05:30
parent a7d1437889
commit 6651be584b
6 changed files with 46 additions and 28 deletions

View File

@ -130,8 +130,8 @@
<field name="coach_id" position="after">
<group colspan="2">
<field name="state"/>
<button name="attendance_action_change" states="present" string="Sign Out" type="object" icon="gtk-go-forward" context="{'type':'sign_out'}" groups="base.group_hr_user"/>
<button name="attendance_action_change" states="absent" string="Sign In" type="object" icon="gtk-go-back" context="{'type':'sign_in'}" groups="base.group_hr_user"/>
<button name="%(action_hr_attendance_sigh_in_out)d" states="present" type="action" string="Sign Out" icon="gtk-go-forward" context="{'type':'sign_out'}" groups="base.group_hr_user"/>
<button name="%(action_hr_attendance_sigh_in_out)d" states="absent" type="action" string="Sign In" icon="gtk-go-back" context="{'type':'sign_in'}" groups="base.group_hr_user"/>
</group>
</field>
</field>

View File

@ -1,4 +1,4 @@
.oe_attendance_button {
cursor: 'pointer';
cursor:pointer;
}

View File

@ -2,11 +2,6 @@ openerp.hr_attendance = function(instance) {
var QWeb = instance.web.qweb;
instance.hr_attendance.AttendanceNotifier = instance.web.Widget.extend({
template: 'AttendanceNotifier',
init: function(parent){
this._super(parent);
this.session = parent.session;
this.employee = new instance.web.DataSetSearch(this, 'hr.employee', this.session.user_context, [['user_id','=', this.session.uid]]);
},
renderElement: function() {
var self = this;
if (this.attendance_status == 'present'){
@ -33,29 +28,44 @@ openerp.hr_attendance = function(instance) {
action = action[0];
action.context = JSON.parse(action.context);
var action_manager = new instance.web.ActionManager(self);
action_manager.do_action(action, function(){
self.employee.read_slice(['state']).done(function(employee) {
if(_.isEmpty(employee)) return;
self.attendance_status = employee[0]['state'];
self.renderElement();
});
});
action_manager.do_action(action);
});
},
});
instance.hr_attendance.AttendanceStatus = instance.web.Class.extend({
init: function(parent){
this.session = parent.session;
attendance = new instance.hr_attendance.AttendanceNotifier(self);
employee = new instance.web.DataSetSearch(this, 'hr.employee', this.session.user_context, [['user_id','=', this.session.uid]]);
employee.read_slice(['state']).done(function(employee) {
if(_.isEmpty(employee)) return;
attendance.attendance_status = employee[0]['state'];
attendance.renderElement();
});
},
});
instance.web.ActionManager.include({
do_action: function(action, on_close) {
var self = this;
if (action.res_model == "hr.sign.in.out"){
var old_close = on_close;
on_close = function(){
if(old_close){old_close();}
new instance.hr_attendance.AttendanceStatus(self);
}
}
this._super(action, on_close);
},
});
instance.web.UserMenu.include({
do_update: function() {
var self = this;
this._super();
this.update_promise.then(function() {
attendance = new instance.hr_attendance.AttendanceNotifier(self);
attendance.employee.read_slice(['state']).done(function(employee) {
if(_.isEmpty(employee)) return;
attendance.attendance_status = employee[0]['state'];
attendance.renderElement();
});
new instance.hr_attendance.AttendanceStatus(self);
});
},
});

View File

@ -71,7 +71,16 @@ class hr_sign_in_out(osv.osv_memory):
'state': fields.char('Current state', size=32, required=True, readonly=True),
'emp_id': fields.many2one('hr.employee', 'Empoyee ID', readonly=True),
}
# def set_name(self,cr,uid,id,context=None):
# act_obj=self.pool.get('ir.actions.act_window')
# action_id = act_obj.search(cr, uid, [('res_model','=','hr.sign.in.out')],context=context)
# action = act_obj.browse(cr, uid, action_id[0], context=context)
# #data = self.read(cr, uid, id, [], context=context)[0]
# if data['state']=='present':
# name = act_obj.write(cr, uid, action_id[0], {'name':'Sign Out'}, context=context)
# if data['state']=='absent':
# name = act_obj.write(cr, uid, action_id[0], {'name':'Sign In'}, context=context)
def _get_empid(self, cr, uid, context=None):
emp_id = context.get('emp_id', self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context))
if emp_id:
@ -80,6 +89,7 @@ class hr_sign_in_out(osv.osv_memory):
return {}
def default_get(self, cr, uid, fields_list, context=None):
#self.set_name(cr, uid, uid, context)
res = super(hr_sign_in_out, self).default_get(cr, uid, fields_list, context=context)
res_emp = self._get_empid(cr, uid, context=context)
res.update(res_emp)
@ -102,7 +112,7 @@ class hr_sign_in_out(osv.osv_memory):
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_attendance_so_ask')], context=context)
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': _('Sign in / Sign out'),
'name': _('Sign in '),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'hr.sign.in.out.ask',

View File

@ -38,7 +38,7 @@
</record>
<record id="action_hr_attendance_sigh_in_out" model="ir.actions.act_window">
<field name="name">Sign in / Sign out</field>
<field name="name">Sign In / Sign Out</field>
<field name="res_model">hr.sign.in.out</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
@ -47,8 +47,6 @@
<field name="help">Sign in / Sign out. In some companies, staff have to sign in when they arrive at work and sign out again at the end of the day. If each employee has been linked to a system user, then they can encode their time with this action button.</field>
</record>
<menuitem action="action_hr_attendance_sigh_in_out" id="menu_hr_attendance_sigh_in_out"
parent="menu_hr_attendance" sequence="4"/>
<record id="view_hr_attendance_so_ask" model="ir.ui.view">
<field name="name">hr.sign.in.out.ask.form</field>

View File

@ -91,8 +91,8 @@
</field>
<group col="4" colspan="1">
<field name="state_attendance"/>
<button name="sign_in" string="Sign In" type="object" icon="terp-gtk-jump-to-ltr" />
<button name="sign_out" string="Sign Out" type="object" icon="terp-gtk-jump-to-rtl" />
<button name="%(hr_attendance.action_hr_attendance_sigh_in_out)d" type="action" string="Sign In" attrs="{'invisible':[('state_attendance','=','present')]}" icon="terp-gtk-jump-to-ltr" />
<button name="%(hr_attendance.action_hr_attendance_sigh_in_out)d" type="action" string="Sign Out" attrs="{'invisible':[('state_attendance','=','absent')]}" icon="terp-gtk-jump-to-rtl" />
<field name="total_attendance_day" widget="float_time" colspan="4"/>
</group>
<field colspan="4" context="{'date':date_current,'user_id':user_id}" domain="[('name','=',date_current)]" name="timesheet_ids" nolabel="1">