From ec78cf2ca545cf607d85f28cbbca781091111419 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 28 Sep 2012 18:38:11 +0200 Subject: [PATCH] bunch of stuff to handle things bzr revid: nicolas.vanhoren@openerp.com-20120928163811-u1p5wabdfk5b3jqu --- .../static/src/js/timesheet.js | 46 ++++++++++++++++--- 1 file changed, 40 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 f16386fd6c3..5fc90b513af 100644 --- a/addons/hr_timesheet_sheet/static/src/js/timesheet.js +++ b/addons/hr_timesheet_sheet/static/src/js/timesheet.js @@ -4,7 +4,6 @@ openerp.hr_timesheet_sheet = function(instance) { var _t = instance.web._t; instance.hr_timesheet_sheet.WeeklyTimesheet = instance.web.form.FormWidget.extend({ - template: "hr_timesheet_sheet.WeeklyTimesheet", init: function() { this._super.apply(this, arguments); this.set({ @@ -21,6 +20,7 @@ openerp.hr_timesheet_sheet = function(instance) { }); this.on("change:sheets", this, this.update_sheets); this.res_o2m_drop = new instance.web.DropMisordered(); + this.description_line = _t("No description"); }, query_sheets: function() { var self = this; @@ -56,12 +56,46 @@ openerp.hr_timesheet_sheet = function(instance) { // don't render anything until we have date_to and date_from if (!self.get("date_to") || !self.get("date_from")) return; + // calculating dates + self.dates = []; + var start = self.get("date_from"); + var end = self.get("date_to"); + while (start <= end) { + self.dates.push(start); + start = start.clone().addDays(1); + } // group by account - var accounts = _.groupBy(this.get("sheets"), function(el) { return !!el.account_id ? el.account_id[0] : false }); - // group by days - accounts = _.map(accounts, function(el) { - //var tmp = _.groupBy(el - }); + self.accounts = _(this.get("sheets")).chain().map(function(el) { + // much simpler to use only the id in all cases + if (typeof(el.account_id) === "object") + el.account_id = el.account_id[0]; + }).groupBy("account_id") + .map(function(lines, account_id) { + // group by days + account_id = account_id === "false" ? false : Number(account_id); + var index = _.groupBy(lines, "date"); + var days = _.map(self.dates, function(date) { + var day = {day: date, lines: index[instance.web.date_to_str(date)] || []}; + var to_add = _.find(day.lines, function(line) { return line.name === self.description_line }); + if (to_add) { + day.lines = _.without(to_add); + day.lines.unshift(to_add); + } else { + day.lines.unshift({ + name: self.description_line, + unit_amount: 0, + date: instance.web.date_to_str(date), + account_id: k === "false" ? false : Number(account_id), + }); + } + }); + return {account: account_id, days: days}; + }).sortBy(function(account) { + return account.account; + }).value(); + + debugger; + //TODO: handle the account_id name_get problem ! }, });