2012-11-12 09:36:09 +00:00
|
|
|
|
|
|
|
openerp.account.quickadd = function (instance) {
|
2012-11-09 12:38:08 +00:00
|
|
|
var _t = instance.web._t,
|
|
|
|
_lt = instance.web._lt;
|
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
|
2012-11-09 13:00:18 +00:00
|
|
|
instance.web.account = instance.web.account || {};
|
2012-11-09 12:38:08 +00:00
|
|
|
|
|
|
|
instance.web.views.add('tree_account_move_line_quickadd', 'instance.web.account.QuickAddListView');
|
|
|
|
instance.web.account.QuickAddListView = instance.web.ListView.extend({
|
|
|
|
_template: 'ListView',
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.journals = [];
|
|
|
|
this.periods = [];
|
|
|
|
this.current_journal = null;
|
|
|
|
this.current_period = null;
|
2012-11-12 14:10:00 +00:00
|
|
|
this.default_period = null;
|
|
|
|
this.default_journal = null;
|
2012-11-21 17:29:54 +00:00
|
|
|
this.current_journal_type = null;
|
|
|
|
this.current_journal_currency = null;
|
|
|
|
this.current_journal_analytic = null;
|
2012-11-09 12:38:08 +00:00
|
|
|
},
|
2012-11-19 10:48:50 +00:00
|
|
|
start:function(){
|
2012-11-09 12:38:08 +00:00
|
|
|
var tmp = this._super.apply(this, arguments);
|
2012-11-19 10:48:50 +00:00
|
|
|
var self = this;
|
|
|
|
this.$el.parent().prepend(QWeb.render("AccountMoveLineQuickAdd", {widget: this}));
|
2012-11-09 12:38:08 +00:00
|
|
|
|
2012-11-19 10:48:50 +00:00
|
|
|
this.$el.parent().find('.oe_account_select_journal').change(function() {
|
2012-11-22 14:28:59 +00:00
|
|
|
self.current_journal = this.value === '' ? null : parseInt(this.value);
|
2012-11-09 12:38:08 +00:00
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
2012-11-19 10:48:50 +00:00
|
|
|
this.$el.parent().find('.oe_account_select_period').change(function() {
|
2012-11-22 14:28:59 +00:00
|
|
|
self.current_period = this.value === '' ? null : parseInt(this.value);
|
2012-11-09 12:38:08 +00:00
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
2012-11-19 12:32:54 +00:00
|
|
|
this.on('edit:after', this, function () {
|
|
|
|
self.$el.parent().find('.oe_account_select_journal').attr('disabled', 'disabled');
|
|
|
|
self.$el.parent().find('.oe_account_select_period').attr('disabled', 'disabled');
|
|
|
|
});
|
|
|
|
this.on('save:after cancel:after', this, function () {
|
|
|
|
self.$el.parent().find('.oe_account_select_journal').removeAttr('disabled');
|
|
|
|
self.$el.parent().find('.oe_account_select_period').removeAttr('disabled');
|
|
|
|
});
|
2012-11-22 14:28:59 +00:00
|
|
|
var mod = new instance.web.Model("account.move.line", self.dataset.context, self.dataset.domain);
|
|
|
|
mod.call("default_get", [['journal_id','period_id'],self.dataset.context]).then(function(result) {
|
|
|
|
self.current_period = result['period_id'];
|
|
|
|
self.current_journal = result['journal_id'];
|
|
|
|
});
|
2012-11-09 12:38:08 +00:00
|
|
|
return tmp;
|
|
|
|
},
|
|
|
|
do_search: function(domain, context, group_by) {
|
|
|
|
var self = this;
|
|
|
|
this.last_domain = domain;
|
|
|
|
this.last_context = context;
|
|
|
|
this.last_group_by = group_by;
|
|
|
|
this.old_search = _.bind(this._super, this);
|
|
|
|
var mod = new instance.web.Model("account.move.line", context, domain);
|
2012-11-12 09:36:09 +00:00
|
|
|
return $.when(mod.call("list_journals", []).then(function(result) {
|
2012-11-09 12:38:08 +00:00
|
|
|
self.journals = result;
|
2012-11-09 12:56:18 +00:00
|
|
|
}),mod.call("list_periods", []).then(function(result) {
|
2012-11-09 12:38:08 +00:00
|
|
|
self.periods = result;
|
2012-11-09 12:56:18 +00:00
|
|
|
})).then(function () {
|
2012-11-19 10:48:50 +00:00
|
|
|
var o;
|
|
|
|
self.$el.parent().find('.oe_account_select_journal').children().remove().end();
|
2012-11-22 14:28:59 +00:00
|
|
|
self.$el.parent().find('.oe_account_select_journal').append(new Option('', ''));
|
2012-11-19 10:48:50 +00:00
|
|
|
for (var i = 0;i < self.journals.length;i++){
|
|
|
|
o = new Option(self.journals[i][1], self.journals[i][0]);
|
2012-11-21 17:29:54 +00:00
|
|
|
if (self.journals[i][0] === self.current_journal){
|
|
|
|
self.current_journal_type = self.journals[i][2];
|
|
|
|
self.current_journal_currency = self.journals[i][3];
|
|
|
|
self.current_journal_analytic = self.journals[i][4];
|
|
|
|
$(o).attr('selected',true);
|
|
|
|
}
|
2012-11-19 10:48:50 +00:00
|
|
|
self.$el.parent().find('.oe_account_select_journal').append(o);
|
|
|
|
}
|
|
|
|
self.$el.parent().find('.oe_account_select_period').children().remove().end();
|
2012-11-22 14:28:59 +00:00
|
|
|
self.$el.parent().find('.oe_account_select_period').append(new Option('', ''));
|
2012-11-19 10:48:50 +00:00
|
|
|
for (var i = 0;i < self.periods.length;i++){
|
|
|
|
o = new Option(self.periods[i][1], self.periods[i][0]);
|
|
|
|
self.$el.parent().find('.oe_account_select_period').append(o);
|
|
|
|
}
|
|
|
|
self.$el.parent().find('.oe_account_select_period').val(self.current_period).attr('selected',true);
|
2012-11-09 12:56:18 +00:00
|
|
|
return self.search_by_journal_period();
|
2012-11-09 12:38:08 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
search_by_journal_period: function() {
|
|
|
|
var self = this;
|
2012-11-22 14:28:59 +00:00
|
|
|
var domain = [];
|
|
|
|
if (self.current_journal !== null) domain.push(["journal_id", "=", self.current_journal]);
|
|
|
|
if (self.current_period !== null) domain.push(["period_id", "=", self.current_period]);
|
|
|
|
self.last_context["journal_id"] = self.current_journal === null ? false : self.current_journal;
|
|
|
|
self.last_context["period_id"] = self.current_period === null ? false : self.current_period;
|
2012-11-21 17:29:54 +00:00
|
|
|
self.last_context["journal_type"] = self.current_journal_type;
|
|
|
|
self.last_context["currency"] = self.current_journal_currency;
|
|
|
|
self.last_context["analytic_journal_id"] = self.current_journal_analytic;
|
2012-11-22 14:28:59 +00:00
|
|
|
return self.old_search(new instance.web.CompoundDomain(self.last_domain, domain), self.last_context, self.last_group_by);
|
2012-11-09 12:38:08 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|