[FIX] web: loss of context when duplicating
- Create a vendor bill, save and validate - Duplicate the bill, save - Click on "Create" A customer invoice is created, while the user expects a vendor bill. After duplication, the new record is loaded but the context is lost. Since the default value for the invoice type is based on the context key `type`, a loss of context leads to an incorrect invoice type. opw-1826453 Co-authored-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
committed by
Nicolas Martinelli
co-authored by
Géry Debongnie
parent
64ef2b396b
commit
6397ce7eb0
@@ -375,11 +375,12 @@ var BasicModel = AbstractModel.extend({
|
||||
duplicateRecord: function (recordID) {
|
||||
var self = this;
|
||||
var record = this.localData[recordID];
|
||||
var context = this._getContext(record);
|
||||
return this._rpc({
|
||||
model: record.model,
|
||||
method: 'copy',
|
||||
args: [record.data.id],
|
||||
context: this._getContext(record),
|
||||
context: context,
|
||||
})
|
||||
.then(function (res_id) {
|
||||
var index = record.res_ids.indexOf(record.res_id);
|
||||
@@ -391,6 +392,7 @@ var BasicModel = AbstractModel.extend({
|
||||
res_id: res_id,
|
||||
res_ids: record.res_ids.slice(0),
|
||||
viewType: record.viewType,
|
||||
context: context,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1623,6 +1623,37 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('duplicating a record preserve the context', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="foo"/>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
viewOptions: {sidebar: true, context: {hey: 'hoy'}},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'read') {
|
||||
// should have 2 read, one for initial load, second for
|
||||
// read after duplicating
|
||||
assert.strictEqual(args.kwargs.context.hey, 'hoy',
|
||||
"should have send the correct context");
|
||||
}
|
||||
if (args.method === 'search_read' && args.model === 'ir.attachment') {
|
||||
return $.when([]);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
form.sidebar.$('a:contains(Duplicate)').click();
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('cannot duplicate a record', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user