odoo/addons/hr_timesheet_sheet/static/src/js/timesheet.js

71 lines
2.8 KiB
JavaScript
Raw Normal View History

openerp.hr_timesheet_sheet = function(instance) {
var QWeb = instance.web.qweb;
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({
sheets: [],
date_to: false,
date_from: false,
});
this.field_manager.on("field_changed:timesheet_ids", this, this.query_sheets);
this.field_manager.on("field_changed:date_from", this, function() {
this.set({"date_from": instance.web.str_to_date(this.field_manager.get_field_value("date_from"))});
});
this.field_manager.on("field_changed:date_to", this, function() {
this.set({"date_to": instance.web.str_to_date(this.field_manager.get_field_value("date_to"))});
});
this.on("change:sheets", this, this.update_sheets);
this.res_o2m_drop = new instance.web.DropMisordered();
},
query_sheets: function() {
var self = this;
if (self.updating)
return;
var commands = this.field_manager.get_field_value("timesheet_ids");
this.res_o2m_drop.add(new instance.web.Model(this.view.model).call("resolve_2many_commands", ["timesheet_ids", commands, []]))
.then(function(result) {
self.querying = true;
self.set({sheets: result});
self.querying = false;
});
},
update_sheets: function() {
var self = this;
if (self.querying)
return;
self.updating = true;
self.field_manager.set_values({timesheet_ids: self.get("sheets")}).then(function() {
self.updating = false;
});
},
start: function() {
this.on("change:sheets", this, this.render);
this.on("change:date_to", this, this.render);
this.on("change:date_from", this, this.render);
this.render();
},
render: function() {
var self = this;
if (self.setting)
return;
// don't render anything until we have date_to and date_from
if (!self.get("date_to") || !self.get("date_from"))
return;
// 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
});
},
});
instance.web.form.custom_widgets.add('weekly_timesheet', 'instance.hr_timesheet_sheet.WeeklyTimesheet');
};