Hello everyone, I try to call python function by model without rpc , but when I declare model, I see this error ReferenceError: instance is not defined
Here is my js code
odoo.define('erpvn_ztree_view.Model', function (require) {
"use strict";
var AbstractModel = require('web.AbstractModel');
var ZtreeModel = AbstractModel.extend({
get: function () {
return this.data;
},
/**
* @param {Object} params
* @param {string} params.modelName the name of the model
* @returns {Deferred} The deferred resolves to some kind of handle
*/
load: function (params) {
this.modelName = params.modelName;
this.domain = params.domain || [];
this.fields = params.fields;
this.viewFields = params.viewFields;
this.child_id = params.child_id;
this.parent_name = params.parent_name;
this.parents_name = params.parents_name;
return this._fetchData();
},
/**
* @param {Object} params
* @returns {Deferred}
*/
reload: function (handle, params) {
if ('domain' in params) {
this.domain = params.domain;
}
return this._fetchData();
},
_fetchData: function () {
var self = this;
var params = Array.prototype.slice.call(arguments);
var recordId = params[0];
var child =[];
var defs = [
this._rpc({
model:this.fields[this.parent_name].relation,
method: 'search_read',
sort: "",
})
];
return $.when.apply($, defs,).then(function () {
var results = Array.prototype.slice.call(arguments);
console.log(child);
var model = new instance.web.Model("custom.model"); // Error here
model.call("my_function", {
context: new instance.web.CompoundContext()
}).then(function(result) {
context: new instance.web.CompoundContext()
}).then(function(result) {
console.log(result);
});
self.data = {
"zTreeNodes": results[0],
};
});
},
});
return ZtreeModel;
});
Here is my model
Here is my model
from odoo import fields, models,api
class CustomModel(models.Model):
_name = 'custom.model'
@api.model
def my_function(self):
return 'Hello world'