2017-08-08 46 views
2

在Odoo/openerp文檔中,它表示'客戶端操作'完全是客戶端實現的。他們沒有提供有關Odoo v10的任何示例詳細文檔。Odoo中的客戶端操作

有沒有人對如何實施客戶端操作及其全部潛力有精確的想法。 (我們可以通過客戶端操作實現的可能性)。

回答

1

客戶端操作基本上是在xml中定義的菜單項,並且相應的操作將映射到一個窗口小部件。

以下是客戶端操作的實現:

你的XML文件將包含以下代碼:

<record id="some-report-client-action" model="ir.actions.client"> 
    <field name="name">Report Page</field> 
    <field name="tag">report.report_page</field> 
</record> 

<menuitem id="some-report-menuitem" name="Some" parent="pdf_report" 
       action="some-report-client-action"/> 

創建控件創建一個js文件。它將包含下面的代碼:

openerp.guard_payments = function(instance, local) { 
var _t = instance.web._t, 
    _lt = instance.web._lt; 
var QWeb = instance.web.qweb; 

local.HomePage = instance.Widget.extend({ 
    template: 'MyQWebTemplate', 
    init: function(parent, options){ 
     this._super.apply(this, arguments); 
     this.name=parent.name; 
    }, 
    start: function() { 
     this._super.apply(this, arguments); 
     console.log('Widget Start') 
    }, 
}); 

//Following code will attach the above widget to the defined client action 

instance.web.client_actions.add('report.report_page', 'instance.guard_payments.HomePage'); 
} 

因此,大家可以看到,我們可以創建一個全定製QWeb模板,並添加任何功能它。

基本上這最精彩的部分由Odoo

+0

謝謝您的回答。我正在爲v10實現的客戶端操作,但面臨另一個問題>我的窗口小部件呈現的模板無法獲取任何值(通過它傳遞給它的參數(例如.parame或任何變量,我放在窗口小部件的init方法中))對此有何想法? – DexJ

+0

你在init方法中聲明的任何變量都可以被其他使用'this'關鍵字的方法使用。如果你希望變量在視圖中可用,你必須明確地將它傳遞給像'Qweb.render('MyTemplate',{'variable1':this.variable1})' –