تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2655 أدوات العرض

Hello,


I used to have this working code with Odoo 9. But now with the 11 it doesnt  work anymore because error to get the model.


Can you help me to translate the code below, how to call a model ??

I know i should use rpc but I didn't find any working code with my case.


The code :

odoo.define('app_ca.index'function (require) {
    "use strict";
    var Model = require('web.rpc')
    console.log($(document));
    var hist_model = new Model('app.history')
    var hist_officecentral_model = new Model('app.history.officecentral')
    var purchase_orderline_model = new Model('purchase.order.line')

    $(document).on('click'function() {
        // on click
        var domElement = $(event.target).val();
        console.log('d,os,fs,fs'domElement);
        if (domElement) {
            // change n values
            hist_model.call('get_values', [domElement], {}).then(function(result){
                // console.log(result);
                if ($('[title="Article"]')[0] !== undefined) {
                    $('[title="Article"]')[0].innerText = result['product_id']
                }
                if ($('[title="M"]')[0] !== undefined) {
                    $('[title="M"]')[0].innerText = result['m0']
                }
                for (var i = 1i<13i++) {
                    if ($('[title="M-' + i + '"]')[0] !== undefined) {
                        $('[title="M-' + i + '"]')[0].innerText = result['n' + i]
                    }
                }
            });
            // change n id
            hist_model.call('get_month', [], {}).then(function(result) {
                for (var i = 0i<13i++) {
                    if($('[data-id="m'+i+'"]')[0] !== undefined) {
                        $('[data-id="m'+i+'"]')[0].innerText = result[i]
                    }
                }
            });
        }
    });
الصورة الرمزية
إهمال
الكاتب

I forgot to thanks you a lot!!!!

أفضل إجابة

Hello, you cannot make "new Model" from the "web.rpc" module now. Actually, in v11 the whole Model class is deprecated in JavaScript and hidden the web/static/src/js/_deprecated/data.js file (not even exported).

With web.rpc you directly query your models on the method you want with args and kwargs. Try this to correct your code:

odoo.define("app_ca.index", function (require) {
  "use strict";
  var rpc = require("web.rpc");
  console.log($(document));
  $(document).on("click", function () {
    // on click
    var domElement = $(event.target).val();
    console.log("d,os,fs,fs", domElement);
    if (domElement) {
      // change n values
      rpc.query({
        model: "app.history",
        method: "get_values",
        args: [domElement],
      }).then(function (result) {
        // console.log(result);
        if ($('[title="Article"]')[0] !== undefined) {
         $('[title="Article"]')[0].innerText = result["product_id"];
        }
        if ($('[title="M"]')[0] !== undefined) {
         $('[title="M"]')[0].innerText = result["m0"];
        }
        for (var i = 1; i < 13; i++) {
         if ($('[title="M-' + i + '"]')[0] !== undefined) {
         $('[title="M-' + i + '"]')[0].innerText = result["n" + i];
         }
        }
      });
      // change n id
      rpc.query({
        model: "app.history",
        method: "get_month",
        args: [],
      }).then(function (result) {
        for (var i = 0; i < 13; i++) {
         if ($('[data-id="m' + i + '"]')[0] !== undefined) {
           $('[data-id="m' + i + '"]')[0].innerText = result[i];
         }
        }
      });
    }
  });
});

Good luck

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مايو 20
9066
1
يناير 20
4428
0
مارس 19
2829
0
أكتوبر 18
5561
3
مايو 22
8548