2012-11-09 12:38:08 +00:00
|
|
|
openerp.account = function (instance) {
|
|
|
|
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() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.journals = [];
|
|
|
|
this.periods = [];
|
|
|
|
this.current_journal = null;
|
|
|
|
this.current_period = null;
|
|
|
|
},
|
|
|
|
load_list: function() {
|
|
|
|
var self = this;
|
|
|
|
var tmp = this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.$el.prepend(QWeb.render("AccountMoveLineQuickAdd", {widget: this}));
|
|
|
|
|
|
|
|
this.$("#oe_account_select_journal").change(function() {
|
|
|
|
self.current_journal = parseInt(this.value);
|
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
|
|
|
this.$("#oe_account_select_period").change(function() {
|
|
|
|
self.current_period = parseInt(this.value);
|
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
|
|
|
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-09 12:56:18 +00:00
|
|
|
return new instance.web.Model("account.move.line", context, domain);
|
|
|
|
$.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-09 12:38:08 +00:00
|
|
|
self.current_journal = self.current_journal === null ? self.journals[0][0] : self.current_journal;
|
|
|
|
self.current_period = self.current_period === null ? self.periods[0][0] :self.current_period;
|
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-09 13:00:18 +00:00
|
|
|
var compoundDomain = new instance.web.CompoundDomain(self.last_domain,
|
2012-11-09 12:38:08 +00:00
|
|
|
[
|
|
|
|
["journal_id", "=", self.current_journal],
|
|
|
|
["period_id", "=", self.current_period]
|
|
|
|
]);
|
2012-11-09 13:00:18 +00:00
|
|
|
var cc = new instance.web.CompoundContext(this.last_context, {
|
|
|
|
"journal_id": self.current_journal,
|
|
|
|
"period_id" :self.current_period,
|
|
|
|
});
|
|
|
|
return self.old_search(compoundDomain, cc, self.last_group_by);
|
2012-11-09 12:38:08 +00:00
|
|
|
},
|
|
|
|
_next: function (next_record, options) {
|
|
|
|
next_record = next_record || 'succ';
|
|
|
|
var self = this;
|
|
|
|
return this.save_edition().then(function (saveInfo) {
|
|
|
|
if (saveInfo.created || self.records.at(self.records.length-1).get("id") === saveInfo.record.get("id")) {
|
|
|
|
return self.start_edition();
|
|
|
|
}
|
|
|
|
var record = self.records[next_record](
|
|
|
|
saveInfo.record, {wraparound: true});
|
|
|
|
return self.start_edition(record, options);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|