Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4591 Lượt xem

I have made a popup form for sale order liner using the following structure:

<field name="order_line" mode="tree,kanban">
    <form string="Sale Order Line">
    </form>
</field>

The form by default has Save & New, Save & Close, Remove, and Discard. I was looking to add an extra option of "Save & Duplicate". In order to do this I attempted to overwrite the footer using xml however the normal write functions within a model doesn't work for order_lines due to the sale order not being saved yet (but still does not work if it is saved).
So next i tried to add it through JavaScript since that's how odoo inserts the button.
I have tried the duplicateRecord method, but it doesn't pass the order_line to python, next I added the values to context in JavaScript:

var data = record.data
var getcontext = record.getContext()
for (var attname in date) {getcontext[attname] = data[attname]}

return model.load({
    fields: record.fields,
    fieldsInfo: record.fieldsInfo,
    modelName: form.modelName,
    parentID: self.parentID,
    res_ids: record.res_ids,
    context: getcontext,
    type: 'record',
    viewType: 'form',
}) .then(function (handle) {
    form.handle = handle;
    form._updateEnv();
    return form._setMode('edit');
})

However this method never populated the next form.

Not sure if ive done something wroing or if this just isn;t the way to approach it?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Solved it, you need to set the .then to:

.then(function (handle) {
    form.handle = handle;
    var local = form.model.localData[form.handle]
    for (var attname in local._changes) {
        if (attname != "__proto__") {
    form.model.localData[form.handle]._changes[attname] = record1._changes[attname]
}
}
    form._updateEnv(); return form._setMode('edit'); })

If proto is copied the field is still linked to the previous one


Edit: if anyone sees this and agrees please upvote so i can get some karma to use the odoo forums

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello!

Can you say to which file JS you've added those modifications, I need to do exactly this 

Thanks!

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 23
384
0
thg 9 21
3646
0
thg 10 19
4081
1
thg 4 16
11216
1
thg 2 16
5133