You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo10转Odoo11模块遇web.DataModel缺失,求代码转换方案

Odoo 10 to 11 Migration: Fixing Missing web.DataModel (Model) Issue

Hey there, let's work through this migration problem! Odoo 11 completely phased out the old web.DataModel class (which you’re using as Model in your code) and shifted to a cleaner RPC-based approach for calling backend methods. Here’s how to update your code to fit Odoo 11’s frontend structure:

Core Change to Understand

Instead of instantiating a Model and using its .call() method, you’ll use Odoo’s built-in rpc.query() function (or this._rpc() if you’re inside an Odoo widget/component that inherits from base classes). Just make sure the web.rpc module is loaded as a dependency in your JS file.

Converted Odoo 11 Compatible Code

Here’s your updated code with the new RPC syntax:

// First, ensure you've imported the rpc module at the top of your JS file
// Example:
// odoo.define('your_module.pos_coupon', function (require) {
//     "use strict";
//     var rpc = require('web.rpc');
//     // ... other required imports ...

var temp = { 
    'partner_id': client['id'], 
    'coupon_pos': cp.code, 
};

// Replace the old Model().call() with rpc.query()
rpc.query({
    model: 'partner.coupon.pos',
    method: 'update_history',
    args: ['', temp]  // Keep your original arguments intact here
}).then(function (result) { 
    var applied = self.pos.applied_coupon;
    var already_used = false;
    for (var j in applied) {
        if (applied[j]['partner_id'][0] == client['id'] && applied[j]['coupon_pos'] == order.coupon_status['code']) {
            applied[j]['number_pos'] += 1;
            already_used = true;
            break;
        }
    }
    if (!already_used) {
        var temp = { 
            'partner_id': [client['id'], client['name']], 
            'number_pos': 1, 
            'coupon_pos': order.coupon_status['code'] 
        };
        self.pos.applied_coupon.push(temp);
    }
}).catch(function (error) {
    // Added error handling (best practice for Odoo 11+)
    console.error('Failed to update coupon history:', error);
});

self.gui.close_popup();

Quick Additional Tips

  1. Dependency Declaration: Double-check that your JS module lists web.rpc as a dependency – without this, the rpc object won’t be available.
  2. Promise Syntax: Odoo 11 uses ES6 promises, so we use .then() instead of .done() (.done() might still work for backward compatibility, but .then() is the standard now).
  3. POS Widget Context: If this code lives inside a POS widget (like a popup handler), you can also use this._rpc() instead of rpc.query() if your widget inherits from AbstractWidget or similar base classes – the arguments stay identical.

内容的提问来源于stack exchange,提问作者Kyaw Zin Oo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:52:38