2012-09-13 12:08:26 +00:00
|
|
|
openerp.account = function (instance) {
|
|
|
|
var _t = instance.web._t,
|
|
|
|
_lt = instance.web._lt;
|
2012-09-14 13:06:30 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
2012-09-13 16:09:48 +00:00
|
|
|
|
|
|
|
instance.web.account = {};
|
|
|
|
|
|
|
|
instance.web.views.add('account_reconciliation_list', 'instance.web.account.ReconciliationListView');
|
|
|
|
instance.web.account.ReconciliationListView = instance.web.ListView.extend({
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-09-17 09:55:18 +00:00
|
|
|
this.current_partner = null;
|
2012-09-14 13:06:30 +00:00
|
|
|
},
|
|
|
|
on_loaded: function() {
|
2012-09-17 12:53:09 +00:00
|
|
|
var self = this;
|
2012-09-14 13:06:30 +00:00
|
|
|
var tmp = this._super.apply(this, arguments);
|
2012-09-17 12:53:09 +00:00
|
|
|
if (this.partners) {
|
2012-09-17 12:04:42 +00:00
|
|
|
this.$el.prepend(QWeb.render("AccountReconciliation", {widget: this}));
|
2012-09-17 12:53:09 +00:00
|
|
|
this.$("oe_account_recon_previous").click(function() {
|
|
|
|
self.current_partner = (self.current_partner - 1) % self.partners.length;
|
|
|
|
self.search_by_partner();
|
|
|
|
});
|
|
|
|
this.$("oe_account_recon_next").click(function() {
|
|
|
|
self.current_partner = (self.current_partner + 1) % self.partners.length;
|
|
|
|
self.search_by_partner();
|
|
|
|
});
|
|
|
|
this.$("oe_account_recon_reconcile").click(function() {
|
|
|
|
self.reconcile();
|
|
|
|
});
|
|
|
|
}
|
2012-09-14 13:06:30 +00:00
|
|
|
return tmp;
|
|
|
|
},
|
2012-09-14 15:31:33 +00:00
|
|
|
do_search: function(domain, context, group_by) {
|
2012-09-17 08:41:30 +00:00
|
|
|
var self = this;
|
|
|
|
this.last_domain = domain;
|
|
|
|
this.last_context = context;
|
|
|
|
this.last_group_by = group_by;
|
|
|
|
this.old_search = _.bind(this._super, this);
|
2012-09-14 15:31:33 +00:00
|
|
|
var mod = new instance.web.Model(this.model, context, domain);
|
|
|
|
return mod.query("partner_id").group_by(["partner_id"]).pipe(function(result) {
|
2012-09-17 12:53:09 +00:00
|
|
|
var current = self.current_partner !== null ? self.partner[self.current_partner][0] : null;
|
2012-09-17 08:41:30 +00:00
|
|
|
self.partners = _.chain(result).pluck("attributes").pluck("value")
|
2012-09-14 15:31:33 +00:00
|
|
|
.filter(function(el) {return !!el;}).value();
|
2012-09-17 12:53:09 +00:00
|
|
|
var index = _.find(_.range(self.partners.length), function(el) {
|
|
|
|
if (current === self.partners[el][0])
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (index !== undefined)
|
|
|
|
self.current_partner = index;
|
|
|
|
else
|
|
|
|
self.current_partner = self.partners.length == 0 ? null : 0;
|
2012-09-17 09:55:18 +00:00
|
|
|
self.search_by_partner();
|
2012-09-14 15:31:33 +00:00
|
|
|
});
|
|
|
|
},
|
2012-09-17 09:55:18 +00:00
|
|
|
search_by_partner: function() {
|
|
|
|
return this.old_search(new instance.web.CompoundDomain(this.last_domain, [["partner_id", "in", this.current_partner === null ? [] :
|
|
|
|
[this.partners[this.current_partner][0]] ]]), this.last_context, this.last_group_by);
|
|
|
|
},
|
2012-09-17 12:53:09 +00:00
|
|
|
reconcile: function() {
|
|
|
|
var self = this;
|
|
|
|
var ids = this.get_selected_ids();
|
|
|
|
},
|
2012-09-13 16:09:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/*instance.web.views.add('form_clone', 'instance.account.extend_form_view');
|
2012-09-13 12:00:00 +00:00
|
|
|
|
2012-09-13 12:08:26 +00:00
|
|
|
instance.account.extend_viewmanager = instance.web.ViewManagerAction.include({
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
|
|
|
if (this.action.context && this.action.context.extended_view_id && this.action.context.extended_model) {
|
|
|
|
this.setup_exended_form_view(this.action.context.extended_model, this.action.context.extended_view_id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setup_exended_form_view: function (view_model, view_id) {
|
|
|
|
var self = this;
|
|
|
|
var from_view = this.registry.get_object('form_clone');
|
|
|
|
this.dataset_form = new instance.web.DataSetSearch(this, view_model, this.action.context, this.action.domain);
|
|
|
|
this.dataset_loaded = this.dataset_form.read_slice();
|
|
|
|
var obj_from_view = new from_view(self, self.dataset_form, view_id, {});
|
|
|
|
obj_from_view.template = 'ExtendedFormView';
|
|
|
|
var view_form = obj_from_view.appendTo(self.$el.find('.oe_extended_form_view'));
|
|
|
|
$.when(view_form, this.dataset_loaded).then(function () {
|
|
|
|
obj_from_view.on_pager_action('first');
|
|
|
|
});
|
2012-06-20 13:26:21 +00:00
|
|
|
}
|
2012-09-13 12:08:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
instance.account.extend_form_view = instance.web.FormView.extend({
|
|
|
|
on_loaded: function (data) {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
var self = this;
|
|
|
|
this.$el.find(".oe_reconcile").on('click', this.do_reconcilation);
|
|
|
|
this.$el.find(".oe_nothing_to_reconcile").on('click', this.do_nothing_to_reconcile);
|
|
|
|
this.$el.on('click', 'a[data-pager-action]', function () {
|
|
|
|
var action = $(this).data('pager-action');
|
|
|
|
self.on_pager_action(action);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_reconcilation: function (event) {
|
|
|
|
var self = this;
|
|
|
|
if (!self.datarecord.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var list_view = this.getParent().views['list'].controller;
|
|
|
|
var ids = list_view.get_selected_ids();
|
|
|
|
if (ids.length === 0) {
|
|
|
|
instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), {
|
|
|
|
title: _t("Warning"),
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var additional_context = _.extend({
|
|
|
|
active_id: ids[0],
|
|
|
|
active_ids: ids,
|
|
|
|
active_model: list_view.dataset.model
|
|
|
|
});
|
|
|
|
self.rpc("/web/action/load", {
|
|
|
|
action_id: py.eval(event.target.name),
|
|
|
|
context: additional_context
|
|
|
|
}, function (result) {
|
2012-08-06 13:20:34 +00:00
|
|
|
result.result.context = _.extend(result.result.context || {},
|
2012-09-13 12:08:26 +00:00
|
|
|
additional_context);
|
2012-08-06 13:20:34 +00:00
|
|
|
result.result.flags = result.result.flags || {};
|
|
|
|
result.result.flags.new_window = true;
|
|
|
|
self.do_action(result.result, function () {
|
2012-09-13 12:08:26 +00:00
|
|
|
self.dataset.read_slice().done(function () {
|
2012-08-30 13:26:29 +00:00
|
|
|
self.on_pager_action('next');
|
|
|
|
});
|
2012-09-13 12:08:26 +00:00
|
|
|
});
|
2012-06-20 13:26:21 +00:00
|
|
|
});
|
2012-09-13 12:10:14 +00:00
|
|
|
return true;
|
2012-09-13 12:08:26 +00:00
|
|
|
},
|
2012-08-29 12:43:03 +00:00
|
|
|
|
2012-09-05 07:58:20 +00:00
|
|
|
|
2012-09-13 12:08:26 +00:00
|
|
|
do_nothing_to_reconcile: function () {
|
|
|
|
var self = this;
|
|
|
|
if (!self.datarecord.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// how do you want this to not fail ???
|
|
|
|
var event = null;
|
|
|
|
this.dataset.call(event.target.name, [
|
|
|
|
[self.datarecord.id], self.dataset.context]).then(function () {
|
|
|
|
self.dataset.read_slice().done(function () {
|
|
|
|
self.on_pager_action('next');
|
|
|
|
});
|
2012-09-05 07:51:20 +00:00
|
|
|
});
|
2012-09-13 12:10:14 +00:00
|
|
|
return true;
|
2012-09-13 12:08:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_update_pager: function (hide_index) {
|
|
|
|
var index = this.dataset.index + 1;
|
|
|
|
if (this.dataset.ids.length === 0) index = 0;
|
|
|
|
index = hide_index ? '-' : index;
|
|
|
|
this.$el.find('span.oe_pager_index_extend').html(index).end().find('span.oe_pager_count_extend').html(this.dataset.ids.length);
|
|
|
|
},
|
|
|
|
|
|
|
|
do_search_move_line: function (partner_ids) {
|
|
|
|
var viewmanager = this.getParent();
|
|
|
|
viewmanager.action.context.next_partner_only = true;
|
|
|
|
viewmanager.action.context.partner_id = partner_ids;
|
|
|
|
viewmanager.searchview.do_search();
|
|
|
|
},
|
|
|
|
|
|
|
|
on_pager_action: function (action) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (this.dataset.ids.length === 0) {
|
|
|
|
self.datarecord = {};
|
|
|
|
_(this.fields).each(function (field, f) {
|
|
|
|
field.set_value(self.datarecord[f] || false);
|
|
|
|
});
|
|
|
|
self.do_update_pager();
|
|
|
|
self.do_search_move_line([]);
|
|
|
|
} else {
|
|
|
|
$.when(this._super(action)).then(function () {
|
|
|
|
var id = self.get_fields_values().partner_id;
|
|
|
|
self.do_search_move_line([id]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2012-09-13 16:09:48 +00:00
|
|
|
});*/
|
2012-08-07 13:34:27 +00:00
|
|
|
|
2012-09-13 12:08:26 +00:00
|
|
|
};
|