~tempo-openerp/+junk/loewert-prod

« back to all changes in this revision

Viewing changes to addons/account/static/src/js/account_move_reconciliation.js

  • Committer: jbe at tempo-consulting
  • Date: 2013-08-21 08:48:11 UTC
  • Revision ID: jbe@tempo-consulting.fr-20130821084811-913uo4l7b5ayxq8m
[NEW] Création de la branche trunk Loewert

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
openerp.account = function (instance) {
 
2
    openerp.account.quickadd(instance);
 
3
    var _t = instance.web._t,
 
4
        _lt = instance.web._lt;
 
5
    var QWeb = instance.web.qweb;
 
6
    
 
7
    instance.web.account = instance.web.account || {};
 
8
    
 
9
    instance.web.views.add('tree_account_reconciliation', 'instance.web.account.ReconciliationListView');
 
10
    instance.web.account.ReconciliationListView = instance.web.ListView.extend({
 
11
        init: function() {
 
12
            this._super.apply(this, arguments);
 
13
            var self = this;
 
14
            this.current_partner = null;
 
15
            this.on('record_selected', this, function() {
 
16
                if (self.get_selected_ids().length === 0) {
 
17
                    self.$(".oe_account_recon_reconcile").attr("disabled", "");
 
18
                } else {
 
19
                    self.$(".oe_account_recon_reconcile").removeAttr("disabled");
 
20
                }
 
21
            });
 
22
        },
 
23
        load_list: function() {
 
24
            var self = this;
 
25
            var tmp = this._super.apply(this, arguments);
 
26
            if (this.partners) {
 
27
                this.$el.prepend(QWeb.render("AccountReconciliation", {widget: this}));
 
28
                this.$(".oe_account_recon_previous").click(function() {
 
29
                    self.current_partner = (((self.current_partner - 1) % self.partners.length) + self.partners.length) % self.partners.length;
 
30
                    self.search_by_partner();
 
31
                });
 
32
                this.$(".oe_account_recon_next").click(function() {
 
33
                    self.current_partner = (self.current_partner + 1) % self.partners.length;
 
34
                    self.search_by_partner();
 
35
                });
 
36
                this.$(".oe_account_recon_reconcile").click(function() {
 
37
                    self.reconcile();
 
38
                });
 
39
                this.$(".oe_account_recom_mark_as_reconciled").click(function() {
 
40
                    self.mark_as_reconciled();
 
41
                });
 
42
            }
 
43
            return tmp;
 
44
        },
 
45
        do_search: function(domain, context, group_by) {
 
46
            var self = this;
 
47
            this.last_domain = domain;
 
48
            this.last_context = context;
 
49
            this.last_group_by = group_by;
 
50
            this.old_search = _.bind(this._super, this);
 
51
            var mod = new instance.web.Model("account.move.line", context, domain);
 
52
            return mod.call("list_partners_to_reconcile", []).then(function(result) {
 
53
                var current = self.current_partner !== null ? self.partners[self.current_partner][0] : null;
 
54
                self.partners = result;
 
55
                var index = _.find(_.range(self.partners.length), function(el) {
 
56
                    if (current === self.partners[el][0])
 
57
                        return true;
 
58
                });
 
59
                if (index !== undefined)
 
60
                    self.current_partner = index;
 
61
                else
 
62
                    self.current_partner = self.partners.length == 0 ? null : 0;
 
63
                self.search_by_partner();
 
64
            });
 
65
        },
 
66
        search_by_partner: function() {
 
67
            var self = this;
 
68
            var fct = function() {
 
69
                return self.old_search(new instance.web.CompoundDomain(self.last_domain, 
 
70
                    [["partner_id", "in", self.current_partner === null ? [] :
 
71
                    [self.partners[self.current_partner][0]] ]]), self.last_context, self.last_group_by);
 
72
            };
 
73
            if (self.current_partner === null) {
 
74
                self.last_reconciliation_date = _t("Never");
 
75
                return fct();
 
76
            } else {
 
77
                return new instance.web.Model("res.partner").call("read",
 
78
                    [self.partners[self.current_partner][0], ["last_reconciliation_date"]]).then(function(res) {
 
79
                    self.last_reconciliation_date = 
 
80
                        instance.web.format_value(res.last_reconciliation_date, {"type": "datetime"}, _t("Never"));
 
81
                    return fct();
 
82
                });
 
83
            }
 
84
        },
 
85
        reconcile: function() {
 
86
            var self = this;
 
87
            var ids = this.get_selected_ids();
 
88
            if (ids.length === 0) {
 
89
                instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), {
 
90
                    title: _t("Warning"),
 
91
                    modal: true
 
92
                });
 
93
                return false;
 
94
            }
 
95
 
 
96
            new instance.web.Model("ir.model.data").call("get_object_reference", ["account", "action_view_account_move_line_reconcile"]).then(function(result) {
 
97
                var additional_context = _.extend({
 
98
                    active_id: ids[0],
 
99
                    active_ids: ids,
 
100
                    active_model: self.model
 
101
                });
 
102
                return self.rpc("/web/action/load", {
 
103
                    action_id: result[1],
 
104
                    context: additional_context
 
105
                }).done(function (result) {
 
106
                    result.context = instance.web.pyeval.eval('contexts', [result.context, additional_context]);
 
107
                    result.flags = result.flags || {};
 
108
                    result.flags.new_window = true;
 
109
                    return self.do_action(result, {
 
110
                        on_close: function () {
 
111
                            self.do_search(self.last_domain, self.last_context, self.last_group_by);
 
112
                        }
 
113
                    });
 
114
                });
 
115
            });
 
116
        },
 
117
        mark_as_reconciled: function() {
 
118
            var self = this;
 
119
            var id = self.partners[self.current_partner][0];
 
120
            new instance.web.Model("res.partner").call("mark_as_reconciled", [[id]]).then(function() {
 
121
                self.do_search(self.last_domain, self.last_context, self.last_group_by);
 
122
            });
 
123
        },
 
124
        do_select: function (ids, records) {
 
125
            this.trigger('record_selected')
 
126
            this._super.apply(this, arguments);
 
127
        },
 
128
    });
 
129
    
 
130
};