Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Reload/refresh data in one2many form view after dragging records through widget handle

Subscribe

Get notified when there's activity on this post

This question has been flagged
widgetrefresh
1 Reply
12707 Views
Avatar
Aldennis

This affects the widget handle from OpenERP 7 to Odoo 10.

I would like to ask if it is possible to reload the data from the one2many field in a form view after dragging the record up/down using the widget handle. We've got this working on a list view such that the view gets refreshed each time a record was dragged up/down hence, the new values gets reflected. However, it does not work in form view when I add the one2many field.

This can be tested by doing the following:

1. In Odoo10 project.project object, create a related field for the sequence and have it displayed in the list view under Project/ Configuration/ Projects

2. Drag the records using the widget handle (the plus icon) either up/down. Notice that the related field does not get displayed with the new values. Refreshing the page is the only thing that can be done to view the new value. We had solved this by adding a list.view.reload_contetn(); in the js script but it fails to load in one2many field.

I would like to use this widget to allow users to move records from multiple bank statement records in a form view using one2many field since I need to display 2 tables (2 one2many fields) side by side. As you may know, the bank statement has a concept of rolling bank balance such that the sequence of the record affect the current balance of the succeeding record.

Below is my js code for reference. It is written for openerp 7 using old API. This is working fine for list view.

We have extended the "setup_resequence_rows" function of the web module (web/static/src/js/view_list.js). This executes the method "check_sequence" which is responsible for writing new values. The "list.view.reload_content()" function was called at .done to refresh the list view with new values. 


js script

=====================================

openerp.till_reconciliation_ept = function (instance) {

    var _t = instance.web._t;

    var QWeb = instance.web.qweb;

    var Groups_ept = instance.web.ListView.Groups;


    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;

            }

            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 () {

                                list.view.reload_content()

                            })

                    }

                    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);

                    }

                } 

            }); 

        },

    });

};



python method

===========================

def check_sequence(self, cr, uid, ids, target_id, target_next_id, context={}):

        """

        This method is execute from the sortable widget of JavaScript.

        Checking the sequence with to restrict move of transaction between the validated

        transaction and resequencing it based on the current operation.

        :param cr: the current row, from the database cursor,

        :param uid: the current users ID for security checks,

        :param ids: ids of object of bank.statement.ept,

        :param target_id: previous record of the current moving record,

        :param target_next_id: next record of the current moving record,

        :param context: context arguments, like lang, time zone,

        :return: True if done otherwise return null and raise warning from Javascript.

        """

        to_move = self.browse(cr, uid, ids[0], context=context)

        order = False

        records = []

        to_move_process_date = to_move.process_date

        

        if target_next_id :

            # While record is moving in between existing records whether it can be down or up.

            target = self.browse(cr, uid, target_next_id, context=context)

            to_move_seq = to_move.sequence

            to_index = target.sequence

            

            if to_move_seq > to_index :

                # While moving record down.

                order = 'movedown'

                bank_statement_ids = self.search(cr, uid, [('sequence','>', to_index), ('sequence','<', to_move_seq), ('state','=','validated')], limit=1)

                if bank_statement_ids :

                    return;

                target = self.browse(cr, uid, target_id, context=context)

                to_move_seq = to_move.sequence

                to_index = target.sequence

                target_process_date = target.process_date

                

                # Prevent moving down record past any record with previous date - Aldennis

                if to_move_process_date > target_process_date:

                    return 3


                

                records_to_modify = to_move_seq - to_index

                if records_to_modify == 1:

                    self.write(cr, uid, ids, {'sequence': to_move_seq - 1}, context=context)

                    self.write(cr, uid, [target_id], {'sequence': to_move_seq}, context=context)

                    return True

                self.write(cr, uid, ids, {'sequence': to_index}, context=context)

                records = self.search(cr, uid, [('id', 'not in', ids), ('sequence','>=', to_index), ('sequence','<', to_move_seq)])

            

            else :

                # While moving record up.

                order = 'moveup'

                target = self.browse(cr, uid, target_next_id, context=context)

                to_move_seq = to_move.sequence

                to_index = target.sequence

                target_process_date = target.process_date

                bank_statement_ids = self.search(cr, uid, [('sequence','>', to_move_seq), ('sequence','<', to_index), ('state','=','validated')], limit=1)

                if bank_statement_ids :

                    return;

                

                # Prevent moving up record past any record with upcoming date - Aldennis

                if to_move_process_date < target_process_date:

                    return 2

                

                records_to_modify = to_index - to_move_seq

                if records_to_modify == 1:

                    self.write(cr, uid, ids, {'sequence': to_move_seq + 1}, context=context)

                    self.write(cr, uid, [target_next_id], {'sequence': to_move_seq}, context=context)

                    return True

                self.write(cr, uid, ids, {'sequence': to_index}, context=context)

                records = self.search(cr, uid, [('id', 'not in', ids), ('sequence', '>', to_move_seq), ('sequence','<=', to_index)])

        else:

            # While record is moving at the last of view.

            order = 'movedown'

            to_seq = to_move.sequence

            bank_statement_ids = self.search(cr, uid, [('sequence', '<', to_seq), ('state', '=', 'validated')], limit=1)

            if bank_statement_ids:

                return;

            self.write(cr, uid, ids, {'sequence': 0}, context=context)

            records = self.search(cr, uid, [('id', 'not in', ids), ('sequence', '>=', 0), ('sequence','<=', to_seq)])

        self.re_allocate_sequence(cr, uid, records, order, context=context)

        # Recalculate all subsequent records balance 

        self._compute_balance(cr, uid, records, ['balance','calculate_balance'], args=None, context=context)

        return True

0
Avatar
Discard
Sehrish

Reorder records in tree view using handle widget: https://learnopenerp.blogspot.com/2022/05/use-handle-widget-to-reorder-records-in-tree-view-odoo15.html

Avatar
Aldennis
Author Best Answer

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);
                    }
                } 
            }); 
        },
    });
};
0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
[Odoo 16] Date widget validates the type of maxDate is wrong
widget
Avatar
Avatar
1
जुल॰ 24
2991
Odoo 12: How to define a Form View with custom Widget in odoo 12
widget
Avatar
Avatar
1
जुल॰ 23
5347
Create a list of selection into "Add a section" button
widget
Avatar
0
मार्च 24
4211
[widget] Ice Editor widget
widget
Avatar
Avatar
1
सित॰ 22
7103
How to create a Widget
widget
Avatar
Avatar
1
मार्च 22
7252
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now