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 = {};
|
|
|
|
|
2012-10-15 15:33:39 +00:00
|
|
|
instance.web.views.add('tree_account_reconciliation', 'instance.web.account.ReconciliationListView');
|
2012-09-13 16:09:48 +00:00
|
|
|
instance.web.account.ReconciliationListView = instance.web.ListView.extend({
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-09-21 10:11:22 +00:00
|
|
|
var self = this;
|
2012-09-17 09:55:18 +00:00
|
|
|
this.current_partner = null;
|
2012-09-21 10:11:22 +00:00
|
|
|
this.do_select.add(function() {
|
|
|
|
if (self.get_selected_ids().length === 0) {
|
|
|
|
self.$(".oe_account_recon_reconcile").attr("disabled", "");
|
|
|
|
} else {
|
|
|
|
self.$(".oe_account_recon_reconcile").removeAttr("disabled");
|
|
|
|
}
|
|
|
|
});
|
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 13:49:57 +00:00
|
|
|
this.$(".oe_account_recon_previous").click(function() {
|
2012-09-17 12:53:09 +00:00
|
|
|
self.current_partner = (self.current_partner - 1) % self.partners.length;
|
|
|
|
self.search_by_partner();
|
|
|
|
});
|
2012-09-17 13:49:57 +00:00
|
|
|
this.$(".oe_account_recon_next").click(function() {
|
2012-09-17 12:53:09 +00:00
|
|
|
self.current_partner = (self.current_partner + 1) % self.partners.length;
|
|
|
|
self.search_by_partner();
|
|
|
|
});
|
2012-09-17 13:49:57 +00:00
|
|
|
this.$(".oe_account_recon_reconcile").click(function() {
|
2012-09-17 12:53:09 +00:00
|
|
|
self.reconcile();
|
|
|
|
});
|
2012-09-20 16:22:57 +00:00
|
|
|
this.$(".oe_account_recom_mark_as_reconciled").click(function() {
|
|
|
|
self.mark_as_reconciled();
|
|
|
|
});
|
2012-09-17 12:53:09 +00:00
|
|
|
}
|
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-20 12:20:53 +00:00
|
|
|
var mod = new instance.web.Model("account.move.line", context, domain);
|
|
|
|
return mod.call("list_partners_to_reconcile", []).pipe(function(result) {
|
2012-09-17 13:49:57 +00:00
|
|
|
var current = self.current_partner !== null ? self.partners[self.current_partner][0] : null;
|
2012-09-20 12:20:53 +00:00
|
|
|
self.partners = result;
|
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() {
|
2012-09-21 12:59:17 +00:00
|
|
|
var self = this;
|
2012-09-21 13:08:16 +00:00
|
|
|
var fct = function() {
|
2012-09-21 12:59:17 +00:00
|
|
|
return self.old_search(new instance.web.CompoundDomain(self.last_domain,
|
|
|
|
[["partner_id", "in", self.current_partner === null ? [] :
|
|
|
|
[self.partners[self.current_partner][0]] ]]), self.last_context, self.last_group_by);
|
2012-09-21 13:08:16 +00:00
|
|
|
};
|
|
|
|
if (self.current_partner === null) {
|
|
|
|
self.last_reconciliation_date = _t("Never");
|
|
|
|
return fct();
|
|
|
|
} else {
|
|
|
|
return new instance.web.Model("res.partner").call("read",
|
|
|
|
[self.partners[self.current_partner][0], ["last_reconciliation_date"]]).pipe(function(res) {
|
|
|
|
self.last_reconciliation_date =
|
|
|
|
instance.web.format_value(res.last_reconciliation_date, {"type": "datetime"}, _t("Never"));
|
|
|
|
return fct();
|
|
|
|
});
|
|
|
|
}
|
2012-09-17 09:55:18 +00:00
|
|
|
},
|
2012-09-17 12:53:09 +00:00
|
|
|
reconcile: function() {
|
|
|
|
var self = this;
|
|
|
|
var ids = this.get_selected_ids();
|
2012-09-17 13:49:57 +00:00
|
|
|
if (ids.length === 0) {
|
|
|
|
instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), {
|
|
|
|
title: _t("Warning"),
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:41:03 +00:00
|
|
|
new instance.web.Model("ir.model.data").call("get_object_reference", ["account", "action_view_account_move_line_reconcile"]).pipe(function(result) {
|
2012-09-17 13:49:57 +00:00
|
|
|
var additional_context = _.extend({
|
|
|
|
active_id: ids[0],
|
|
|
|
active_ids: ids,
|
|
|
|
active_model: self.model
|
|
|
|
});
|
|
|
|
return self.rpc("/web/action/load", {
|
|
|
|
action_id: result[1],
|
|
|
|
context: additional_context
|
2012-10-03 12:34:12 +00:00
|
|
|
}).then(function (result) {
|
2012-09-17 13:49:57 +00:00
|
|
|
result = result.result;
|
|
|
|
result.context = _.extend(result.context || {}, additional_context);
|
|
|
|
result.flags = result.flags || {};
|
|
|
|
result.flags.new_window = true;
|
|
|
|
return self.do_action(result, function () {
|
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2012-09-17 12:53:09 +00:00
|
|
|
},
|
2012-09-20 16:22:57 +00:00
|
|
|
mark_as_reconciled: function() {
|
|
|
|
var self = this;
|
|
|
|
var id = self.partners[self.current_partner][0];
|
|
|
|
new instance.web.Model("res.partner").call("mark_as_reconciled", [[id]]).pipe(function() {
|
|
|
|
self.do_search(self.last_domain, self.last_context, self.last_group_by);
|
|
|
|
});
|
|
|
|
},
|
2012-09-13 16:09:48 +00:00
|
|
|
});
|
|
|
|
|
2012-09-20 13:00:28 +00:00
|
|
|
};
|