From 841accd1793c1e092ebbd02f13a4885e988a4158 Mon Sep 17 00:00:00 2001 From: Vidhin Mehta Date: Thu, 23 May 2013 17:35:17 +0530 Subject: [PATCH 1/3] [IMP]Introduce float_time concept in Timesheet Widget. bzr revid: vme@tinyerp.com-20130523120517-y281pkgqj66atthr --- .../static/src/js/timesheet.js | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/addons/hr_timesheet_sheet/static/src/js/timesheet.js b/addons/hr_timesheet_sheet/static/src/js/timesheet.js index fe7d0c82767..9a272051655 100644 --- a/addons/hr_timesheet_sheet/static/src/js/timesheet.js +++ b/addons/hr_timesheet_sheet/static/src/js/timesheet.js @@ -163,24 +163,41 @@ openerp.hr_timesheet_sheet = function(instance) { this.dfm = undefined; } }, + is_valid_value:function(value){ + var split_value = value.split(":"); + var wrong_value = true; + if (split_value.length > 2)return false; + _.detect(split_value,function(num){ + if(isNaN(num)){ + wrong_value = false; + } + }) + return wrong_value; + }, display_data: function() { var self = this; self.$el.html(QWeb.render("hr_timesheet_sheet.WeeklyTimesheet", {widget: self})); _.each(self.accounts, function(account) { _.each(_.range(account.days.length), function(day_count) { if (!self.get('effective_readonly')) { - self.get_box(account, day_count).val(self.sum_box(account, day_count)).change(function() { - var num = Number($(this).val()); + self.get_box(account, day_count).val(self.sum_box(account, day_count, true)).change(function() { + var num = $(this).val(); + if (self.is_valid_value(num)){ + num = Number(self.parse_client(num)); + } if (isNaN(num)) { - $(this).val(self.sum_box(account, day_count)); + $(this).val(self.sum_box(account, day_count, true)); } else { account.days[day_count].lines[0].unit_amount += num - self.sum_box(account, day_count); self.display_totals(); self.sync(); + if(!isNaN($(this).val())){ + $(this).val(self.sum_box(account, day_count, true)); + } } }); } else { - self.get_box(account, day_count).html(self.sum_box(account, day_count)); + self.get_box(account, day_count).html(self.sum_box(account, day_count, true)); } }); }); @@ -247,12 +264,12 @@ openerp.hr_timesheet_sheet = function(instance) { get_super_total: function() { return this.$('.oe_timesheet_weekly_supertotal'); }, - sum_box: function(account, day_count) { + sum_box: function(account, day_count, setter) { var line_total = 0; _.each(account.days[day_count].lines, function(line) { line_total += line.unit_amount; }); - return line_total; + return (setter)?this.format_client(line_total):line_total; }, display_totals: function() { var self = this; @@ -266,12 +283,12 @@ openerp.hr_timesheet_sheet = function(instance) { day_tots[day_count] += sum; super_tot += sum; }); - self.get_total(account).html(acc_tot); + self.get_total(account).html(self.format_client(acc_tot)); }); _.each(_.range(self.dates.length), function(day_count) { - self.get_day_total(day_count).html(day_tots[day_count]); + self.get_day_total(day_count).html(self.format_client(day_tots[day_count])); }); - self.get_super_total().html(super_tot); + self.get_super_total().html(self.format_client(super_tot)); }, sync: function() { var self = this; @@ -279,6 +296,14 @@ openerp.hr_timesheet_sheet = function(instance) { self.set({sheets: this.generate_o2m_value()}); self.setting = false; }, + //converts hour value to float + parse_client: function(value) { + return instance.web.parse_value(value, { type:"float_time" }); + }, + //converts float value to hour + format_client:function(value){ + return instance.web.format_value(value, { type:"float_time" }); + }, generate_o2m_value: function() { var self = this; var ops = []; From 41fd5d657da5d3d0a6d7e9dda851ec08d1a42d2c Mon Sep 17 00:00:00 2001 From: Vidhin Mehta Date: Thu, 23 May 2013 18:11:17 +0530 Subject: [PATCH 2/3] [IMP]Change Variable name. bzr revid: vme@tinyerp.com-20130523124117-g6hnj394fndmookq --- addons/hr_timesheet_sheet/static/src/js/timesheet.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/hr_timesheet_sheet/static/src/js/timesheet.js b/addons/hr_timesheet_sheet/static/src/js/timesheet.js index 9a272051655..90ce8eff39b 100644 --- a/addons/hr_timesheet_sheet/static/src/js/timesheet.js +++ b/addons/hr_timesheet_sheet/static/src/js/timesheet.js @@ -165,14 +165,14 @@ openerp.hr_timesheet_sheet = function(instance) { }, is_valid_value:function(value){ var split_value = value.split(":"); - var wrong_value = true; + var valid_value = true; if (split_value.length > 2)return false; _.detect(split_value,function(num){ if(isNaN(num)){ - wrong_value = false; + valid_value = false; } }) - return wrong_value; + return valid_value; }, display_data: function() { var self = this; @@ -264,12 +264,12 @@ openerp.hr_timesheet_sheet = function(instance) { get_super_total: function() { return this.$('.oe_timesheet_weekly_supertotal'); }, - sum_box: function(account, day_count, setter) { + sum_box: function(account, day_count, show_value_in_hour) { var line_total = 0; _.each(account.days[day_count].lines, function(line) { line_total += line.unit_amount; }); - return (setter)?this.format_client(line_total):line_total; + return (show_value_in_hour)?this.format_client(line_total):line_total; }, display_totals: function() { var self = this; From fcff0fcbea15f1db6eebae81660ec0ca8d2850c0 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 24 May 2013 10:55:34 +0200 Subject: [PATCH 3/3] [IMP] don't format 0 values bzr revid: mat@openerp.com-20130524085534-coh7tjadajiu4bv3 --- .../hr_timesheet_sheet/static/src/js/timesheet.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/hr_timesheet_sheet/static/src/js/timesheet.js b/addons/hr_timesheet_sheet/static/src/js/timesheet.js index 90ce8eff39b..e7d13c425b6 100644 --- a/addons/hr_timesheet_sheet/static/src/js/timesheet.js +++ b/addons/hr_timesheet_sheet/static/src/js/timesheet.js @@ -166,12 +166,13 @@ openerp.hr_timesheet_sheet = function(instance) { is_valid_value:function(value){ var split_value = value.split(":"); var valid_value = true; - if (split_value.length > 2)return false; + if (split_value.length > 2) + return false; _.detect(split_value,function(num){ if(isNaN(num)){ valid_value = false; } - }) + }); return valid_value; }, display_data: function() { @@ -183,15 +184,15 @@ openerp.hr_timesheet_sheet = function(instance) { self.get_box(account, day_count).val(self.sum_box(account, day_count, true)).change(function() { var num = $(this).val(); if (self.is_valid_value(num)){ - num = Number(self.parse_client(num)); - } + num = (num == 0)?0:Number(self.parse_client(num)); + } if (isNaN(num)) { $(this).val(self.sum_box(account, day_count, true)); } else { account.days[day_count].lines[0].unit_amount += num - self.sum_box(account, day_count); self.display_totals(); self.sync(); - if(!isNaN($(this).val())){ + if(!isNaN($(this).val())){ $(this).val(self.sum_box(account, day_count, true)); } } @@ -269,7 +270,7 @@ openerp.hr_timesheet_sheet = function(instance) { _.each(account.days[day_count].lines, function(line) { line_total += line.unit_amount; }); - return (show_value_in_hour)?this.format_client(line_total):line_total; + return (show_value_in_hour && line_total != 0)?this.format_client(line_total):line_total; }, display_totals: function() { var self = this;