Odoo Help

0
1 Answer
0
Aldennis
11/11/17, 10:47 PM

I finaly manage to solve this issue by using the do_action function. My new js sript we'ere as follow:

 

openerp.till_reconciliation_ept = function (instance) {
    var _t = instance.web._t;
    var QWeb = instance.web.qweb;
    var Groups_ept = instance.web.ListView.Groups;

    /*
    Need to extended the function in order make the sequence work based on our need.
    That is used in the Bank Statement View.
    Stop the resequencing functionality of based while we are dealing with the Bank Statement view.

    --------------------------------------------------
    Changes were made in start and stop function of the sortable widget
    --------------------------------------------------
    added by jignesh date: 16/10/2017
    */

    // Added by Aldennis
    instance.web.ActionManager = instance.web.ActionManager.extend({

  // This will refresh the view for the current form
  // Usage: return {'type' : 'ir.actions.act_reload_statement_view'}
  ir_actions_act_reload_statement_view: function () {
   this.inner_widget.views[this.inner_widget.active_view].controller.reload();
   return $.when();
  },

  // This will refresh the view after a pop-up wizard was closed
  // Usage: return {'type' : 'ir.actions.wizard_reload_statement_view'}
  ir_actions_wizard_reload_statement_view: function (action, options) {
   if (!this.dialog) {
    options.on_close();
   }
   this.dialog_stop();
   this.inner_widget.views[this.inner_widget.active_view].controller.reload();
   return $.when();
  },
    });
    

    // This will reload the widget by invoking an action that executes the refresh function above - Aldennis
    instance.web.ListView.include({        
        reload_widget: function() {
            var self = this;
            return self.do_action({type: 'ir.actions.act_reload_statement_view'});
        },    
    });

    
    instance.web.ListView.Groups.include(/** @lends instance.web.ListView.Groups# */{
        passthrough_events: 'action deleted row_link',
        
        setup_resequence_rows: function (list, dataset) {
            // drag and drop enabled if list is not sorted and there is a
            // visible column with @widget=handle or "sequence" column in the view.
            if ((dataset.sort && dataset.sort())
                || !_(this.columns).any(function (column) {
                    return column.widget === 'handle'
                        || column.name === 'sequence';
                })) {
                return;
                list.view.reload_content();
            }
            var sequence_field = _(this.columns).find(function (c) {
                return c.widget === 'handle';
            });
            var seqname = sequence_field ? sequence_field.name : 'sequence';

            // ondrop, move relevant record & fix sequences
            list.$current.sortable({
                axis: 'y',
                items: '> tr[data-id]',
                helper: 'clone'
            });
            if (sequence_field) {
                list.$current.sortable('option', 'handle', '.oe_list_field_handle');
            }
            list.$current.sortable('option', {
                start: function (e, ui) {
                    ui.placeholder.height(ui.item.height());
                    if (dataset.model === 'bank.statement.ept') {
                        current_record_ept = list.records.get(ui.item.data('id')).attributes
                        if (current_record_ept) {
                            if (current_record_ept.state === 'validated') {
                                alert("You can't change ranking of those records which is in Validate state");
                                list.view.reload_content()
                                return;
                            }
                        }
                    }
                },
                stop: function (event, ui) {
                    var to_move = list.records.get(ui.item.data('id')),
                        target_id = ui.item.prev().data('id'),
                        from_index = list.records.indexOf(to_move),
                        target = list.records.get(target_id);
                    if (list.records.at(from_index - 1) == target) {
                        return;
                    }
                    if (dataset.model === 'bank.statement.ept') {
                        var target_next_id = ui.item.next().data('id')
                        return dataset.alive(dataset._model.call('check_sequence', [[ui.item.data('id')], target_id, target_next_id], {context: dataset.get_context()}))
                            .then(function (result) {
                                if (!result) {
                                    alert("You can't move bank statement across an already validated bank statement.");
                                    list.view.reload_content()
                                }
                                // Added additional alert messages whe dragged to different date - Aldennis 19/10/2017
                                if (result == 3) { alert("You can't move down any record past previous transaction date");
                                    list.view.reload_content()
                                }
                                if (result == 2) { alert("You can't move up record past upcoming transaction date");
                                    list.view.reload_content()
                                }
                                return result
                            })
                            .done(function () {
                                // Call the reload_widget function to invoke an action to reload the widget - Aldennis
                                list.view.reload_widget()
                            })
                    }
                    list.records.remove(to_move);
                    var to = target_id ? list.records.indexOf(target) + 1 : 0;
                    list.records.add(to_move, {at: to});

                    // resequencing time!
                    var record, index = to,
                        // if drag to 1st row (to = 0), start sequencing from 0
                        // (exclusive lower bound)
                        seq = to ? list.records.at(to - 1).get(seqname) : 0;
                    while (++seq, record = list.records.at(index++)) {
                        // write are independent from one another, so we can just
                        // launch them all at the same time and we don't really
                        // give a fig about when they're done
                        // FIXME: breaks on o2ms (e.g. Accounting > Financial
                        // Accounting > Taxes > Taxes, child tax accounts)
                        // when synchronous (without setTimeout)
                        (function (dataset, id, seq) {
                            $.async_when().done(function () {
                                var attrs = {};
                                attrs[seqname] = seq;
                                dataset.write(id, attrs);
                            });
                        }(dataset, record.get('id'), seq));
                        record.set(seqname, seq);
                    }
                } 
            }); 
        },
    });
};
Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now