Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Extending the Class in the web gantt

By
Napster
on 12/1/16, 10:43 AM 141 views

please find the code that i edited as marked as mycode ..Is this there is any other way to do this

openerp.gantt_view_custom = function(instance){
instance.gantt_view_custom = {};
var module = instance.web_gantt;
var _super_ = module.GanttTask.prototype.create;
gantt_view_custom.GanttTask.prototype.create = function(){ console.log('Hello!');
_super_.call(this);
};
}

console.log("this yyyyyyyy creae")
var containerTasks = this.Chart.oData.firstChild;
var containerNames = null;
if (this.Chart._showTreePanel) containerNames = this.Chart.panelNames.firstChild;
var predecessorTask = this.TaskInfo.PredecessorTask;
var parentTask = this.TaskInfo.ParentTask;
var isCParentTask = (this.TaskInfo.ChildTasks.length > 0);
var self = this;
this.cTaskItem = [];
this.cTaskNameItem = [];
//creation arrTasks if (!parentTask) { if (this.TaskInfo.previousParentTask) { this.previousParentTask = this.Project.getTaskById(this.TaskInfo.previousParentTask.Id);
var lastChildTask = this.Chart.getLastChildTask(this.previousParentTask);

// ######################## My code
// for moving the workorder bar to the manufactoring order
this.posY = this.Project.posY;
// #########################################
// this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
this.previousParentTask.nextParentTask = this;
} else {
// ######################## My code
// for moving the workorder bar to the manufactoring order
this.posY = this.Project.posY;
// #########################################
// this.posY = parseInt(this.Project.projectItem[0].style.top) + this.Chart.heightTaskItem + 11;
} }
if (parentTask) { var task = this.Project.getTaskById(this.TaskInfo.ParentTask.Id);
this.parentTask = task;
if (this.TaskInfo.previousChildTask) { this.previousChildTask = this.Project.getTaskById(this.TaskInfo.previousChildTask.Id);
var lastChildTask = this.Chart.getLastChildTask(this.previousChildTask);
this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
this.previousChildTask.nextChildTask = this;
} else { this.posY = parseInt(task.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
} task.childTask.push(this);
}
if (predecessorTask) { var task = this.Project.getTaskById(predecessorTask.Id);
this.predTask = task;
task.childPredTask.push(this);
}
//creation task item this.cTaskItem.push(this.createTaskItem());
containerTasks.appendChild(this.cTaskItem[0]);
if (this.Chart.panelNames) { this.cTaskNameItem.push(this.createTaskNameItem(isCParentTask));
this.Chart.panelNames.firstChild.appendChild(this.cTaskNameItem[0]);
}
if (this.Chart.isShowDescTask) { containerTasks.appendChild(this.createTaskDescItem());
}
//Create Connecting Lines var arrConnectingLines = [];
if (predecessorTask) arrConnectingLines = this.createConnectingLinesDS();
this.cTaskItem.push(arrConnectingLines);
if (this.Chart.panelNames) { //Create Connecting Lines var arrConnectingLinesNames = [];
if (parentTask) { this.cTaskNameItem[0].style.left = parseInt(this.parentTask.cTaskNameItem[0].style.left) + 15 + "px";
arrConnectingLinesNames = this.createConnectingLinesPN();
} this.checkWidthTaskNameItem();
var treeImg = null;
if (isCParentTask) treeImg = this.createTreeImg();
this.cTaskNameItem.push(arrConnectingLinesNames);
this.cTaskNameItem.push(treeImg);
} this.addDayInPanelTime();
// console.log("thissssssssssdddddddddddddssssssss",this) console.log("thissssssssssdddddddddddddssssssss",this.Project.posY)// console.log("thissssssssssdddddddddddddssssssss",this.posY)// this.posY = this.Project.posY// console.log("thissssssssssdddddddddddddssssssss",this.posY)//
// ######################## My code
if (this.Chart.Project){ var project_obj = this.Chart.Project;
} for (var key in project_obj) { if (project_obj.hasOwnProperty(key)) { console.log(key + " -> " , project_obj[key]['Id']);
var id_project = project_obj[key]['Id'] $("#"+id_project.toString()).css("display", "None");
} } $(".taskNameItem").css("display", "None"); //hiding the workorder// my code return this;

};

1

Axel Mendoza

--Axel Mendoza--
10308
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/2/16, 5:39 AM

In odoo js framework you could change any widget class by using mostly 2 ways.

1- Using include function that it will change the properties(functions included) original class widget prototype

2- Using extend function that it will return a copy of the changes to the properties(functions included) original class widget prototype

In both cases you always will be able to access the overrides functions in the new ones using this.super or this._super (in newer versions) depending on the Odoo version. You could call it passing the same parameters received or just call it as using js prototype function apply to call it with arguments like:

 this._super.apply(this, arguments);

That is for example the case when you need to change a function like in your case but still need to call the original one and you could do it using the super call.

For the non widget classes created using js prototype like the case of GanttTask you could do what you are doing copying the original function to call it when you need to and just replace the original function in the class protoype but you need to put all your code inside the js odoo module like:

openerp.gantt_view_custom = function(instance){
    instance.gantt_view_custom = {};
    var module = instance.web_gantt;
    var _super_ = GanttTask.prototype.create;
    
    GanttTask.prototype.create = function(){
        var containerTasks = this.Chart.oData.firstChild;
        var containerNames = null;
        if (this.Chart._showTreePanel) containerNames = this.Chart.panelNames.firstChild;
        var predecessorTask = this.TaskInfo.PredecessorTask;
        var parentTask = this.TaskInfo.ParentTask;
        var isCParentTask = (this.TaskInfo.ChildTasks.length > 0);
        var self = this;
        
        this.cTaskItem = [];
        this.cTaskNameItem = [];
        
        //creation arrTasks
        if (!parentTask) {
            if (this.TaskInfo.previousParentTask) {
                this.previousParentTask = this.Project.getTaskById(this.TaskInfo.previousParentTask.Id);
                var lastChildTask = this.Chart.getLastChildTask(this.previousParentTask);
                this.posY = this.Project.posY;
                this.previousParentTask.nextParentTask = this;
            
            } else {
                this.posY = this.Project.posY;
            }
        }
        
        if (parentTask) {
            var task = this.Project.getTaskById(this.TaskInfo.ParentTask.Id);
            this.parentTask = task;
            
            if (this.TaskInfo.previousChildTask) {
                this.previousChildTask = this.Project.getTaskById(this.TaskInfo.previousChildTask.Id);
                var lastChildTask = this.Chart.getLastChildTask(this.previousChildTask);
                this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
                this.previousChildTask.nextChildTask = this;
            
            } else {
                this.posY = parseInt(task.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
            }
            task.childTask.push(this);
        }
        
        if (predecessorTask) {
            var task = this.Project.getTaskById(predecessorTask.Id);
            this.predTask = task;
            task.childPredTask.push(this);
        }
        
        //creation task item
        this.cTaskItem.push(this.createTaskItem());
        containerTasks.appendChild(this.cTaskItem[0]);
        
        if (this.Chart.panelNames) {
            this.cTaskNameItem.push(this.createTaskNameItem(isCParentTask));
            this.Chart.panelNames.firstChild.appendChild(this.cTaskNameItem[0]);
        }
        
        if (this.Chart.isShowDescTask) {
            containerTasks.appendChild(this.createTaskDescItem());
        }
        
        //Create Connecting Lines
        var arrConnectingLines = [];
        if (predecessorTask) arrConnectingLines = this.createConnectingLinesDS();
        this.cTaskItem.push(arrConnectingLines);
        
        if (this.Chart.panelNames) {
            //Create Connecting Lines
            var arrConnectingLinesNames = [];
            if (parentTask) {
                this.cTaskNameItem[0].style.left = parseInt(this.parentTask.cTaskNameItem[0].style.left) + 15 + "px";
                arrConnectingLinesNames = this.createConnectingLinesPN();
            }
            this.checkWidthTaskNameItem();
            
            var treeImg = null;
            if (isCParentTask) treeImg = this.createTreeImg();
            
            this.cTaskNameItem.push(arrConnectingLinesNames);
            this.cTaskNameItem.push(treeImg);
        }
        this.addDayInPanelTime();
        //    console.log("thissssssssssdddddddddddddssssssss",this)
        console.log("thissssssssssdddddddddddddssssssss",this.Project.posY)
        //    console.log("thissssssssssdddddddddddddssssssss",this.posY)
        //    this.posY = this.Project.posY
        //    console.log("thissssssssssdddddddddddddssssssss",this.posY)
        //    
        // ########################   My code
        if (this.Chart.Project){
            var project_obj = this.Chart.Project;
        }
        for (var key in project_obj) {
            if (project_obj.hasOwnProperty(key)) {
                console.log(key + " -> " , project_obj[key]['Id']);
                var id_project = project_obj[key]['Id']
                $("#"+id_project.toString()).css("display", "None");
            }
        }
        $(".taskNameItem").css("display", "None");
        //hiding the workorder
        // my code
        return this;
    }
});

Hope this helps

Thank you It worked..!!!

Napster
on 12/2/16, 6:08 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/1/16, 10:43 AM
Seen: 141 times
Last updated: 12/2/16, 6:07 AM