Skip to Content
Menu
This question has been flagged
2 Replies
3768 Views

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?

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Best Answer

Hello!

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

Thanks!

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 23
384
0
Sep 21
2806
0
Oct 19
3258
1
Apr 16
9772
1
Feb 16
4170