Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม 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
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

Request one2many tree refresh from widget (javascript call)

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
javascripttreeviewwidgetrefresh
2 ตอบกลับ
8355 มุมมอง
อวตาร
Maxime MARAIS

Hi All,

I'm adapting the "web_one2many_selectable_10" widget in order to make it more flexible. To do it short, this widget displays a checkbox on the left for each record referenced in a one2many field + add a button on top of the list + call an action server side with selected record IDs.

I managed to do what I wanted to with this widget: custom text, custom action defined in the caller template. My problem is, after I called a function server-side, to be able to update the tree view displayed in order to reflect changes made server side.

To do, so I'm trying to refresh only the <tree> node defined in the template for the one2many field displayed with this widget. Up to now, I made it the ugly way by refreshing the whole view (it's not efficient at all) with this javascript call:

self.do_action('reload');

I noticed, this seems to be achievable. Using the "Lot split" button in stock operation ("Operation" tab, when products have lots or serial numbers: opens a pop-up window, you can then register lots or serial numbers and, when you save and close the pop-up, only the tree view in parent view is updated.)

Up to now, I could not figure how the hell this happens and how to call this action from my widget. Help would be much appreciated.

Bellow, the full code.

/*
    Usage in templates:
    <field name="One2many_name" widget="one2many_selectable" action="server_action" callback="javascript_callback>
    If defined, "server_action" will be RPC called and executed by server
    If defined, "javascript_callback" will be executed client side after "server_action" is executed server side,
    if also defined. "javascript_callback" will be sent results returned from "server_action" if any.
*/
odoo.define('web_one2many_selectable_10.form_widgets', function (require) {
    "use strict";
    var core = require('web.core');
    var _t = core._t;
    var Model = require('web.Model');
    var FieldOne2Many = core.form_widget_registry.get('one2many');
    function executeFunctionByName(functionName, context /*, args */) {
        var args = Array.prototype.slice.call(arguments, 2);
        var namespaces = functionName.split(".");
        var func = namespaces.pop();
        for (var i = 0; i < namespaces.length; i++) {
            context = context[namespaces[i]];
        }
        return context[func].apply(context, args);
    }
    var One2ManySelectable = FieldOne2Many.extend({
        template: 'One2ManySelectable',
        events: {
            'click .web_one2many_selectable': 'button_pressed',
        },
        multi_selection: true,
        // Retrieve options from caller template to have them available in the widget 'One2ManySelectable' template
        init: function () {
            this._super.apply(this, arguments);
            // Default options
            this.options = {
                caption: 'Apply',
                action: null,
                callback: null
            }
            // User defined options from field attributes in caller template
            if (arguments[1].attrs.hasOwnProperty('options')) {
                this.options = JSON.parse(arguments[1].attrs.options);
            }
            // Translate caption
            this.options.caption = _t(this.options.caption)
        },
        start: function () {
            this._super.apply(this, arguments);
        },
        // Catch button pressed event, collect IDs, call action server side, then callback client side if defined.
        button_pressed: function () {
            var self = this;
            var selected_ids = self.get_selected_ids_one2many();
            if (selected_ids.length === 0) {
                this.do_warn(_t("You must choose at least one record."));
                return false;
            }
            // If an action was defined in template, let's call this action server side
            if (this.options.action) {
                /* Here is a python example function to parse the selected objects
                    @api.multi
                    def your_action_name(self):
                         for record in self:
                             print record
                */
                var model_obj = new Model(this.dataset.model);
                model_obj.call(this.options.action, [selected_ids], {context: self.dataset.context})
                    .then(function (result) {
                        // If a callback was defined in template, let's call this callback client side with
                        // results from server call above.
                        if (self.options.callback) {
                            executeFunctionByName(self.options.callback, window, result);
                        } else {
                            self.do_action('reload');
                        }
                    });
            }
        },
        // Collect the object IDs for checked checkboxes
        get_selected_ids_one2many: function () {
            var ids = [];
            this.$el.find('td.o_list_record_selector input:checkbox:checked').closest('tr').each(function () {
                ids.push(parseInt($(this).context.dataset.id));
            });
            return ids;
        }
    });
    // Register this widget
    core.form_widget_registry.add('one2many_selectable', One2ManySelectable);

    // Make the widget available for other add-ons
    return {
        One2ManySelectable: One2ManySelectable
    }
});



0
อวตาร
ละทิ้ง
Maxime MARAIS
ผู้เขียน

Also tried the bellow instead of do_action('reload'):

var view = self.get_active_view();

view.controller.current_min = 1;

view.controller.reload_content();

without more success.

อวตาร
Maxime MARAIS
ผู้เขียน คำตอบที่ดีที่สุด

After further investigations (thanks Chrome Developer Tool and JavaScript debugger), I finally found the mechanism behind the magic.

Instead of:

self.do_action('reload');

 Replaced with:

var controller = self.get_active_view().controller;
$.each(selected_ids,function(){
    controller.reload_record(controller.records.get(this));
});

Complete code below:

/*
Usage in templates:

<field name="One2many_name" widget="one2many_selectable" action="server_action" callback="javascript_callback>

If defined, "server_action" will be RPC called and executed by server
If defined, "javascript_callback" will be executed client side after "server_action" is executed server side,
if also defined. "javascript_callback" will be sent results returned from "server_action" if any.
*/

odoo.define('web_one2many_selectable_10.form_widgets', function (require) {
"use strict";

var core = require('web.core');
var _t = core._t;
var Model = require('web.Model');
var FieldOne2Many = core.form_widget_registry.get('one2many');

function executeFunctionByName(functionName, context /*, args */) {
var args = Array.prototype.slice.call(arguments, 2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for (var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(context, args);
}

var One2ManySelectable = FieldOne2Many.extend({
template: 'One2ManySelectable',

events: {
'click .web_one2many_selectable': 'button_pressed',
},

multi_selection: true,

// Retrieve options from caller template to have them available in the widget 'One2ManySelectable' template
init: function () {
this._super.apply(this, arguments);

// Default options
this.options = {
caption: 'Apply',
action: null,
callback: null
}

// User defined options from field attributes in caller template
if (arguments[1].attrs.hasOwnProperty('options')) {
this.options = JSON.parse(arguments[1].attrs.options);
}

// Translate caption
this.options.caption = _t(this.options.caption)
},

start: function () {
this._super.apply(this, arguments);
},

// Catch button pressed event, collect IDs, call action server side, then callback client side if defined.
button_pressed: function () {
var self = this;
var selected_ids = self.get_selected_ids_one2many();
if (selected_ids.length === 0) {
this.do_warn(_t("You must choose at least one record."));
return false;
}

// If an action was defined in template, let's call this action server side
if (this.options.action) {
/* Here is a python example function to parse the selected objects

@api.multi
def your_action_name(self):
for record in self:
print record
*/

var model_obj = new Model(this.dataset.model);
model_obj.call(this.options.action, [selected_ids], {context: self.dataset.context})
.then(function (result) {
if (self.options.callback) {
// If a callback was defined in template, let's call this callback client side with
// results from server call above.
executeFunctionByName(self.options.callback, window, result);
} else {
// Else simply refresh the display for the selected records
var controller = self.get_active_view().controller;
$.each(selected_ids,function(){
controller.reload_record(controller.records.get(this));
});
}
});
}
},

// Collect the object IDs for checked checkboxes
get_selected_ids_one2many: function () {
var ids = [];
this.$el.find('td.o_list_record_selector input:checkbox:checked').closest('tr').each(function () {
ids.push(parseInt($(this).context.dataset.id));
});
return ids;
}

});

// Register this widget
core.form_widget_registry.add('one2many_selectable', One2ManySelectable);

// Make the widget available for other add-ons
return {
One2ManySelectable: One2ManySelectable
}

});
0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
Set hotkey focus input text
javascript widget
อวตาร
0
ส.ค. 20
4024
creation a widget of items as tree
javascript treeview widget items odoo
อวตาร
0
มิ.ย. 20
3517
Javascript migration from 10 to 8
javascript widget
อวตาร
0
ก.พ. 18
4257
Reload/refresh data in one2many form view after dragging records through widget handle
widget refresh
อวตาร
1
พ.ย. 17
12818
Odoo widget $el
javascript widget
อวตาร
0
ก.ย. 17
5143
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة 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 เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ 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