Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
264 Tampilan
I previously developed a function in odoo 14 to select the saved draft for the new form record, but when I migrated it to odoo 16, these functions (updateControlPanel() and _setMode('edit')) could not be called. Can someone tell me how to refresh the field values ​​on the form page in odoo 16? As you can see I've already created a handle for the record. Here's my code below:


patch(FormController.prototype, "BaseDraftController", {
async _createRecord(draft_id,form_json,initialState_context, parentID =undefined, additionalContext=undefined) {
const record = this.model.__bm__.get(this.model.root.__bm_handle__, { raw: true });
var context_ = record.getContext({ additionalContext: undefined});
var _context ={};
var __context ={};
_.forEach(context_, function(v, i) {
_context[i] = v;
__context[i] = v;
})
var _json = eval('('+form_json+')');
delete _json.message_main_attachment_id;
_json["base_draft_id"]= draft_id
_context["default__initialState_context"] = initialState_context;
_.forEach(_json, function(v, i) {
if(record.fields[i].type=='many2one' || record.fields[i].type=='one2many'){
if(typeof v == 'object' && v.length ==2){
if(v[0] !=null){
_context["default_"+i] = v[0];
}else{
delete _json[i];
}
}
} else {
_context["default_"+i] = v;
}
})
_context["default__all"] = _json;
const handle = await this.model.__bm__.load({
context: _context,
fields: record.fields,
fieldsInfo: record.fieldsInfo,
modelName: this.model_name,
parentID: parentID,
res_ids: record.res_ids,
type: 'record',
viewType: 'form',
});
this.model.__bm__.handle = handle;
​ // TypeError: this.updateControlPanel is not a function
this.updateControlPanel();
this._setMode('edit');
this.model.__bm__.localData[this.model.root.__bm_handle__].context=__context
},
)}

Thank you!

Avatar
Buang
Jawaban Terbai

Hii,

please try this code 

Here’s how you can revise your method in Odoo 16:

import { patch } from "@web/core/utils/patch"; import { FormController } from "@web/views/form/form_controller"; patch(FormController.prototype, "BaseDraftController", { async _createRecord(draft_id, form_json, initialState_context, parentID = undefined, additionalContext = undefined) { const record = this.model.root; const context_ = record.context || {}; const _context = { ...context_ }; const __context = { ...context_ }; const _json = JSON.parse(form_json); delete _json.message_main_attachment_id; _json["base_draft_id"] = draft_id; _context["default__initialState_context"] = initialState_context; for (const [key, value] of Object.entries(_json)) { if (record.fields[key]?.type === "many2one" || record.fields[key]?.type === "one2many") { if (Array.isArray(value) && value.length === 2) { if (value[0] !== null) { _context["default_" + key] = value[0]; } else { delete _json[key]; } } } else { _context["default_" + key] = value; } } _context["default__all"] = _json; // Load new record with context const newHandle = await this.model.load({ context: _context, fields: record.fields, fieldsInfo: record.fieldsInfo, modelName: this.model.modelName, parentID: parentID, res_ids: [], type: "record", viewType: "form", }); this.model.root.handle = newHandle; // Recommended: use loadRecord instead of legacy _setMode await this.loadRecord(newHandle); this.model.root.context = __context; // Optional: trigger UI update this.render(); }, });

i hope it is use full

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jun 25
522
2
Mei 25
779
2
Jan 25
794
0
Apr 25
609
1
Apr 25
761