Merge lp:~openerp-dev/openobject-addons/trunk-improve_hr_timesheet_sheet into lp:openobject-addons

Proposed by ajay javiya (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-improve_hr_timesheet_sheet
Merge into: lp:openobject-addons
Diff against target: 291 lines (+99/-31)
5 files modified
analytic/analytic.py (+2/-1)
hr_timesheet_sheet/static/src/css/timesheet.css (+3/-0)
hr_timesheet_sheet/static/src/css/timesheet.sass (+2/-0)
hr_timesheet_sheet/static/src/js/timesheet.js (+84/-25)
hr_timesheet_sheet/static/src/xml/timesheet.xml (+8/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-improve_hr_timesheet_sheet
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+165015@code.launchpad.net

Description of the change

Improve Timesheet widget on timesheet.

To post a comment you must log in.
8704. By ajay javiya (OpenERP)

[IMP]:global description shouldn't be reset on saving the record

8705. By ajay javiya (OpenERP)

[IMP]:code to reduce rpc call

8706. By ajay javiya (OpenERP)

[ADD]: global description on account.analytic.line

8707. By ajay javiya (OpenERP)

[PORT]: forward port from lp:~openerp-dev/openobject-addons/7.0-float-time-timesheet-vme

Unmerged revisions

8707. By ajay javiya (OpenERP)

[PORT]: forward port from lp:~openerp-dev/openobject-addons/7.0-float-time-timesheet-vme

8706. By ajay javiya (OpenERP)

[ADD]: global description on account.analytic.line

8705. By ajay javiya (OpenERP)

[IMP]:code to reduce rpc call

8704. By ajay javiya (OpenERP)

[IMP]:global description shouldn't be reset on saving the record

8703. By Vishmita Jadeja (openerp)

[IMP]Improve code for time

8702. By Vishmita Jadeja (openerp)

[IMP]Imporve code for description field

8701. By Vishmita Jadeja (openerp)

[IMP]Imporve code for covert time to float

8700. By Vishmita Jadeja (openerp)

[IMP]the time fields should be a float time, not a simple float

8699. By Vishmita Jadeja (openerp)

[IMP]Minor change

8698. By Vishmita Jadeja (openerp)

[Merge]Add Description field after the analytic account

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'analytic/analytic.py'
2--- analytic/analytic.py 2013-04-11 12:44:46 +0000
3+++ analytic/analytic.py 2013-05-27 10:56:29 +0000
4@@ -1,3 +1,4 @@
5+
6 # -*- coding: utf-8 -*-
7 ##############################################################################
8 #
9@@ -324,7 +325,7 @@
10 'account_id': fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', select=True, domain=[('type','<>','view')]),
11 'user_id': fields.many2one('res.users', 'User'),
12 'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
13-
14+ 'global_desc':fields.text('Global Description'),
15 }
16
17 def _get_default_date(self, cr, uid, context=None):
18
19=== modified file 'hr_timesheet_sheet/static/src/css/timesheet.css'
20--- hr_timesheet_sheet/static/src/css/timesheet.css 2012-10-26 10:02:07 +0000
21+++ hr_timesheet_sheet/static/src/css/timesheet.css 2013-05-27 10:56:29 +0000
22@@ -2,6 +2,9 @@
23 .openerp .oe_form_readonly .oe_timesheet_weekly .oe_timesheet_button_add {
24 display: none;
25 }
26+.openerp .oe_form .oe_timesheet_weekly .oe_timesheet_button_add {
27+ font-weight: bold
28+}
29 .openerp .oe_form_readonly .oe_timesheet_weekly div.oe_view_nocontent {
30 display: none;
31 }
32
33=== modified file 'hr_timesheet_sheet/static/src/css/timesheet.sass'
34--- hr_timesheet_sheet/static/src/css/timesheet.sass 2012-10-26 10:02:07 +0000
35+++ hr_timesheet_sheet/static/src/css/timesheet.sass 2013-05-27 10:56:29 +0000
36@@ -21,6 +21,8 @@
37 font-size: 10px
38 background: #eee
39 min-width: 47px
40+ .oe_timesheet_button_add
41+ font-weight: bold
42 .oe_timesheet_total
43 background: #eee
44 .oe_timesheet_weekly_account
45
46=== modified file 'hr_timesheet_sheet/static/src/js/timesheet.js'
47--- hr_timesheet_sheet/static/src/js/timesheet.js 2012-12-17 11:13:37 +0000
48+++ hr_timesheet_sheet/static/src/js/timesheet.js 2013-05-27 10:56:29 +0000
49@@ -84,6 +84,7 @@
50 var accounts;
51 var account_names;
52 var default_get;
53+ var description;
54 return this.render_drop.add(new instance.web.Model("hr.analytic.timesheet").call("default_get", [
55 ['account_id','general_account_id', 'journal_id','date','name','user_id','product_id','product_uom_id','to_invoice','amount','unit_amount'],
56 new instance.web.CompoundContext({'user_id': self.get('user_id')})]).then(function(result) {
57@@ -115,8 +116,9 @@
58 // group by days
59 account_id = account_id === "false" ? false : Number(account_id);
60 var index = _.groupBy(lines, "date");
61+ var day;
62 var days = _.map(dates, function(date) {
63- var day = {day: date, lines: index[instance.web.date_to_str(date)] || []};
64+ day = {day: date, lines: index[instance.web.date_to_str(date)] || []};
65 // add line where we will insert/remove hours
66 var to_add = _.find(day.lines, function(line) { return line.name === self.description_line });
67 if (to_add) {
68@@ -132,7 +134,7 @@
69 }
70 return day;
71 });
72- return {account: account_id, days: days, account_defaults: account_defaults};
73+ return {account: account_id, days: days, account_defaults: account_defaults, description: day.lines[0]};
74 }).value();
75
76 // we need the name_get of the analytic accounts
77@@ -148,14 +150,25 @@
78 });;
79 });
80 })).then(function(result) {
81+ var completed = $.Deferred();
82+ _.each(accounts,function(account){
83+ $.when(new instance.web.Model("account.analytic.line").get_func("search_read")([['account_id','=',account.account],['user_id','=',account.description.user_id]],['global_desc','name']).then(function(result){
84+ if (result[0])
85+ account.dec = result[0].global_desc
86+ else
87+ account.dec = ''
88+ })).done(function(){
89+ self.display_data();
90+ completed.resolve();
91+ })
92 // we put all the gathered data in self, then we render
93 self.dates = dates;
94 self.accounts = accounts;
95 self.account_names = account_names;
96 self.default_get = default_get;
97 //real rendering
98- self.display_data();
99 });
100+ });
101 },
102 destroy_content: function() {
103 if (this.dfm) {
104@@ -163,29 +176,67 @@
105 this.dfm = undefined;
106 }
107 },
108+ is_valid_value:function(value){
109+ var split_value = value.split(":");
110+ var valid_value = true;
111+ if (split_value.length > 2)
112+ return false;
113+ _.detect(split_value,function(num){
114+ if(isNaN(num)){
115+ valid_value = false;
116+ }
117+ });
118+ return valid_value;
119+ },
120 display_data: function() {
121 var self = this;
122+ var ids = [];
123+ var name_ids = [];
124 self.$el.html(QWeb.render("hr_timesheet_sheet.WeeklyTimesheet", {widget: self}));
125 _.each(self.accounts, function(account) {
126- _.each(_.range(account.days.length), function(day_count) {
127- if (!self.get('effective_readonly')) {
128- self.get_box(account, day_count).val(self.sum_box(account, day_count)).change(function() {
129- var num = Number($(this).val());
130- if (isNaN(num)) {
131- $(this).val(self.sum_box(account, day_count));
132- } else {
133- account.days[day_count].lines[0].unit_amount += num - self.sum_box(account, day_count);
134- self.display_totals();
135- self.sync();
136+ if (!self.get('effective_readonly')) {
137+ _.each(account.days,function(day){
138+ if(day.lines.length > 1){
139+ if (day.lines[1].name == self.$el.find('.oe_timesheet_desc[data-account = '+ account.account+']').val()){ids.push(day.lines[1].id)}
140+ else{name_ids.push(day.lines[1].id)}
141+ }
142+ });
143+ self.$el.find('.oe_timesheet_desc[data-account = '+ account.account+']').change(function(){
144+ var change_list = [[ids,{'global_desc':$(this).val(),'name':$(this).val()},new instance.web.CompoundContext()],[name_ids,{'global_desc':$(this).val()},new instance.web.CompoundContext()]];
145+ _.each(change_list,function(val){
146+ if (val[0][0])
147+ {
148+ return new instance.web.Model("account.analytic.line").call("write",val);}
149+ else
150+ return
151+ });
152+ });
153+ }
154+ _.each(_.range(account.days.length), function(day_count) {
155+ if (!self.get('effective_readonly')) {
156+ self.get_box(account, day_count).val(self.sum_box(account, day_count, true)).change(function() {
157+ var num = $(this).val();
158+ if (self.is_valid_value(num)){
159+ num = (num == 0)?0:Number(self.parse_client(num));
160 }
161- });
162- } else {
163- self.get_box(account, day_count).html(self.sum_box(account, day_count));
164- }
165- });
166+ if (isNaN(num)) {
167+ $(this).val(self.sum_box(account, day_count, true));
168+ } else {
169+ account.days[day_count].lines[0].unit_amount += num - self.sum_box(account, day_count);
170+ self.display_totals();
171+ self.sync();
172+ if(!isNaN($(this).val())){
173+ $(this).val(self.sum_box(account, day_count, true));
174+ }
175+ }
176+ });
177+ } else {
178+ self.get_box(account, day_count).html(self.sum_box(account, day_count, true));
179+ }
180+ });
181 });
182 self.display_totals();
183- self.$(".oe_timesheet_weekly_adding button").click(_.bind(this.init_add_account, this));
184+ self.$(".oe_timesheet_weekly_adding a").click(_.bind(this.init_add_account, this));
185 },
186 init_add_account: function() {
187 var self = this;
188@@ -216,7 +267,7 @@
189 },
190 });
191 self.account_m2o.prependTo(self.$(".oe_timesheet_weekly_add_row td"));
192- self.$(".oe_timesheet_weekly_add_row button").click(function() {
193+ self.account_m2o.on("change:value", self, function(){
194 var id = self.account_m2o.get_value();
195 if (id === false) {
196 self.dfm.set({display_invalid_fields: true});
197@@ -247,12 +298,12 @@
198 get_super_total: function() {
199 return this.$('.oe_timesheet_weekly_supertotal');
200 },
201- sum_box: function(account, day_count) {
202+ sum_box: function(account, day_count, show_value_in_hour) {
203 var line_total = 0;
204 _.each(account.days[day_count].lines, function(line) {
205 line_total += line.unit_amount;
206 });
207- return line_total;
208+ return (show_value_in_hour && line_total != 0)?this.format_client(line_total):line_total;
209 },
210 display_totals: function() {
211 var self = this;
212@@ -266,12 +317,12 @@
213 day_tots[day_count] += sum;
214 super_tot += sum;
215 });
216- self.get_total(account).html(acc_tot);
217+ self.get_total(account).html(self.format_client(acc_tot));
218 });
219 _.each(_.range(self.dates.length), function(day_count) {
220- self.get_day_total(day_count).html(day_tots[day_count]);
221+ self.get_day_total(day_count).html(self.format_client(day_tots[day_count]));
222 });
223- self.get_super_total().html(super_tot);
224+ self.get_super_total().html(self.format_client(super_tot));
225 },
226 sync: function() {
227 var self = this;
228@@ -279,6 +330,14 @@
229 self.set({sheets: this.generate_o2m_value()});
230 self.setting = false;
231 },
232+ //converts hour value to float
233+ parse_client: function(value) {
234+ return instance.web.parse_value(value, { type:"float_time" });
235+ },
236+ //converts float value to hour
237+ format_client:function(value){
238+ return instance.web.format_value(value, { type:"float_time" });
239+ },
240 generate_o2m_value: function() {
241 var self = this;
242 var ops = [];
243
244=== modified file 'hr_timesheet_sheet/static/src/xml/timesheet.xml'
245--- hr_timesheet_sheet/static/src/xml/timesheet.xml 2012-11-26 21:29:03 +0000
246+++ hr_timesheet_sheet/static/src/xml/timesheet.xml 2013-05-27 10:56:29 +0000
247@@ -1,11 +1,11 @@
248 <?xml version="1.0" encoding="UTF-8"?>
249-
250 <templates>
251 <t t-name="hr_timesheet_sheet.WeeklyTimesheet">
252 <div class="oe_timesheet_weekly">
253 <table>
254 <tr>
255 <th class="oe_timesheet_first_col"> </th>
256+ <th class="oe_timesheet_desc_col"> </th>
257 <t t-foreach="widget.dates" t-as="date">
258 <th t-att-class="'oe_timesheet_weekly_date_head' + (Date.compare(date, Date.today()) === 0 ? ' oe_timesheet_weekly_today' : '')">
259 <t t-esc="date.toString('ddd')"/><br />
260@@ -16,6 +16,10 @@
261 </tr>
262 <tr t-foreach="widget.accounts" t-as="account">
263 <td class="oe_timesheet_weekly_account"><a href="javascript:void(0)" t-att-data-id="JSON.stringify(account.account)"><t t-esc="widget.account_names[account.account]"/></a></td>
264+ <td>
265+ <textarea t-if="!widget.get('effective_readonly')" rows="1" class="oe_timesheet_desc" t-att-data-account="account.account"><t t-esc="account.dec"/></textarea>
266+ <span t-if="widget.get('effective_readonly')" class="oe_timesheet_desc_box" t-att-data-account="account.account"><t t-esc="account.dec"/></span>
267+ </td>
268 <t t-set="day_count" t-value="0"/>
269 <t t-foreach="account.days" t-as="day">
270 <td t-att-class="(Date.compare(day.day, Date.today()) === 0 ? 'oe_timesheet_weekly_today' : '')">
271@@ -29,17 +33,16 @@
272 <td t-att-data-account-total="account.account" class="oe_timesheet_total"> </td>
273 </tr>
274 <tr class="oe_timesheet_weekly_add_row" style="display: none">
275- <td t-att-colspan="widget.dates.length + 2">
276- <button class="oe_highlight">Add</button>
277- </td>
278+ <td t-att-colspan="widget.dates.length + 2"></td>
279 </tr>
280 <tr class="oe_timesheet_total">
281 <td>
282 <div class="oe_timesheet_weekly_adding_tot">
283- <div class="oe_timesheet_weekly_adding"><button class="oe_timesheet_button_add">Add a Line</button></div>
284+ <div class="oe_timesheet_weekly_adding"><a class="oe_timesheet_button_add">Add a Line</a></div>
285 <div class="oe_timesheet_weekly_tottot"><span>Total</span></div>
286 </div>
287 </td>
288+ <td><span></span></td>
289 <t t-set="day_count" t-value="0"/>
290 <t t-foreach="widget.dates" t-as="date">
291 <td class="oe_timesheet_total">

Subscribers

People subscribed via source and target branches

to all changes: