基于微信odoo哥发布的代码尝试进行bug修复,最终效果如下
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
import { KanbanController } from "@web/views/kanban/kanban_controller";
import { patch } from "@web/core/utils/patch";
import { deepCopy } from "@web/core/utils/objects";
function createOnSearchPanel(self){
const sectionDefault = {};
if(!self.model.action.currentController.action.context_copy){
// 深拷贝一个对象
// this.model.action.currentController.action.context_copy = JSON.parse(JSON.stringify(this.model.action.currentController.action.context));
self.model.action.currentController.action.context_copy = deepCopy(self.model.action.currentController.action.context);
// console.log('拷贝:this.model.action.currentController.action.context_copy');
}
// console.log(this.model.env.searchModel.sections);
self.model.env.searchModel.sections.forEach((section) => {
let sel_key = 'default_'+ section.fieldName;
if(section.activeValueId){
sectionDefault[sel_key] = section.values.get(section.activeValueId).id;
}else if(self.model.action.currentController.action.context_copy.hasOwnProperty(sel_key)){
sectionDefault[sel_key] = self.model.action.currentController.action.context_copy[sel_key];
}else{
delete self.model.action.currentController.action.context[sel_key]
}
});
// console.log(sectionDefault);
// console.log(this.model.action.currentController.action.context);
self.model.action.currentController.action.context = Object.assign({},self.model.action.currentController.action.context, sectionDefault);
return self._super(...arguments);
}
patch(ListController.prototype, 'og_searchPanel_to_default', {
onClickCreate() {
const self = this;
return createOnSearchPanel(self);
}
});
patch(KanbanController.prototype, 'og_kanban_searchPanel_to_default', {
async createRecord(group) {
const self = this;
return createOnSearchPanel(self);
}
});