Odoo16中将SearchPanel选中项当成新增时的默认值

 基于微信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);
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值