Skip to content
Permalink
Browse files

[FIX] *: pass context in kwargs in rpc calls

  • Loading branch information...
rco-odoo committed Feb 15, 2019
1 parent 579965a commit 1ced3bfca457ac50845637bcd42a8e53bd7f088d
@@ -152,7 +152,8 @@ var ShowPaymentLineWidget = AbstractField.extend({
this._rpc({
model: 'account.move.line',
method: 'remove_move_reconcile',
args: [paymentId, {'invoice_id': this.res_id}]
args: [paymentId],
context: {'invoice_id': this.res_id},
}).then(function () {
self.trigger_up('reload');
});
@@ -26,7 +26,7 @@ QUnit.module('account', {
QUnit.module('Reconciliation');

QUnit.test('Reconciliation form field', async function (assert) {
assert.expect(5);
assert.expect(6);

var form = await createView({
View: FormView,
@@ -39,7 +39,8 @@ QUnit.module('account', {
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'remove_move_reconcile') {
assert.deepEqual(args.args, [22,{"invoice_id":1}], "should call remove_move_reconcile {warning: required focus}");
assert.deepEqual(args.args, [22], "should call remove_move_reconcile {warning: required focus}");
assert.deepEqual(args.kwargs, {context: {"invoice_id": 1}}, "should call remove_move_reconcile {warning: required focus}");
return Promise.resolve();
}
if (args.method === 'assign_outstanding_credit') {
@@ -117,7 +117,7 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) {
return this._rpc({
model: 'hr.leave.type',
method: 'get_days_all_request',
args: [this.context],
context: this.context,
})
.then(function (leaves) {
$('#counter_leaves').children().remove();
@@ -537,10 +537,12 @@ var Chatter = Widget.extend({
var self = this;
if (!this.suggested_partners_def) {
this.suggested_partners_def = new Promise(function (resolve, reject) {
var method = 'message_get_suggested_recipients';
var args = [[self.context.default_res_id], self.context];
self._rpc({model: self.record.model, method: method, args: args})
.then(function (result) {
self._rpc({
model: self.record.model,
method: 'message_get_suggested_recipients',
args: [[self.context.default_res_id]],
context: self.context,
}).then(function (result) {
if (!self.suggested_partners_def) {
return; // widget has been reset (e.g. we just switched to another record)
}
@@ -937,8 +937,8 @@ def call_kw(self, model, method, args, kwargs, path=None):
return self._call_kw(model, method, args, kwargs)

@http.route('/web/dataset/call_button', type='json', auth="user")
def call_button(self, model, method, args, domain_id=None, context_id=None):
action = self._call_kw(model, method, args, {})
def call_button(self, model, method, args, kwargs):
action = self._call_kw(model, method, args, kwargs)
if isinstance(action, dict) and action.get('type') != '':
return clean_action(action)
return False
@@ -835,13 +835,13 @@ var Model = Class.extend({
},
call_button: function (method, args) {
pyUtils.ensure_evaluated(args, {});
// context should be the last argument
var context = (args || []).length > 0 ? args.pop() : {};
return session.rpc('/web/dataset/call_button', {
model: this.name,
method: method,
// Should not be necessary anymore. Integrate remote in this?
domain_id: null,
context_id: args.length - 1,
args: args || []
args: args || [],
kwargs: {context: context},
});
},
});
@@ -609,11 +609,11 @@ ActionManager.include({
console.error("Could not JSON.parse arguments", actionData.args);
}
}
args.push(context.eval());
def = this._rpc({
route: '/web/dataset/call_button',
params: {
args: args,
kwargs: {context: context.eval()},
method: actionData.name,
model: env.model,
},
@@ -655,7 +655,8 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
params: {
model: 'ir.translation',
method: 'translate_fields',
args: [record.model, record.res_id, ev.data.fieldName, record.getContext()],
args: [record.model, record.res_id, ev.data.fieldName],
kwargs: {context: record.getContext()},
}
}).then(function (result) {
self.do_action(result, {
@@ -3901,7 +3901,8 @@ var BasicModel = AbstractModel.extend({
return self._rpc({
model: record.model,
method: 'onchange',
args: [idList, currentData, fields, onchangeSpec, context],
args: [idList, currentData, fields, onchangeSpec],
context: context,
})
.then(function (result) {
if (!record._changes) {
@@ -300,7 +300,8 @@ var CalendarController = AbstractController.extend({
model: self.modelName,
method: 'get_formview_id',
//The event can be called by a view that can have another context than the default one.
args: [[id], event.context || self.context],
args: [[id]],
context: event.context || self.context,
}).then(function (viewId) {
self.do_action({
type:'ir.actions.act_window',
@@ -2615,7 +2615,8 @@ QUnit.module('ActionManager', {
assert.step(args.method || route);
if (route === '/web/dataset/call_button') {
assert.deepEqual(args, {
args: [[1], {some_key: 2}],
args: [[1]],
kwargs: {context: {some_key: 2}},
method: 'object',
model: 'partner',
}, "should call route with correct arguments");
@@ -1031,7 +1031,7 @@ QUnit.module('basic_fields', {
res_id: 1,
mockRPC: function (route, args) {
if (route === "/web/dataset/call_button" && args.method === 'translate_fields') {
assert.deepEqual(args.args, ["partner",1,"foo",{}], 'should call "call_button" route');
assert.deepEqual(args.args, ["partner",1,"foo"], 'should call "call_button" route');
return Promise.resolve();
}
return this._super.apply(this, arguments);
@@ -1666,7 +1666,7 @@ QUnit.module('basic_fields', {
res_id: 1,
mockRPC: function (route, args) {
if (route === "/web/dataset/call_button" && args.method === 'translate_fields') {
assert.deepEqual(args.args, ["partner",1,"txt",{}], 'should call "call_button" route');
assert.deepEqual(args.args, ["partner",1,"txt"], 'should call "call_button" route');
return Promise.resolve();
}
return this._super.apply(this, arguments);
@@ -214,7 +214,7 @@ odoo.define('web.basic_model_tests', function (require) {
data: this.data,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
var context = args.args[4];
var context = args.kwargs.context;
assert.deepEqual(context, { hello: 'world' },
"context should be sent by the onchange");
}
@@ -3957,9 +3957,9 @@ QUnit.module('Views', {
'</form>',
mockRPC: function (route, args) {
if (args.method === 'onchange') {
assert.strictEqual(args.args[4].test, 1,
assert.strictEqual(args.kwargs.context.test, 1,
"the context of the field triggering the onchange should be given");
assert.strictEqual(args.args[4].int_ctx, undefined,
assert.strictEqual(args.kwargs.context.int_ctx, undefined,
"the context of other fields should not be given");
}
return this._super.apply(this, arguments);
@@ -5782,7 +5782,7 @@ QUnit.module('Views', {
if (route === '/web/dataset/call_kw/product/get_formview_id') {
return Promise.resolve(false);
} else if (route === "/web/dataset/call_button" && args.method === 'translate_fields') {
assert.deepEqual(args.args, ["product",37,"name",{}], 'should call "call_button" route');
assert.deepEqual(args.args, ["product",37,"name"], 'should call "call_button" route');
nbTranslateCalls++;
return Promise.resolve();
}
@@ -804,7 +804,7 @@ QUnit.test('save immediately before iframe is rendered in edit mode', async func
res_id: 1,
mockRPC: function (route, args) {
if (route === '/web/dataset/call_button' && args.method === 'translate_fields') {
assert.deepEqual(args.args, ['note.note', 1, 'body', {}], "should call 'call_button' route");
assert.deepEqual(args.args, ['note.note', 1, 'body'], "should call 'call_button' route");
return Promise.resolve();
}
return this._super.apply(this, arguments);
@@ -840,7 +840,7 @@ QUnit.test('save immediately before iframe is rendered in edit mode', async func
res_id: 1,
mockRPC: function (route, args) {
if (route === '/web/dataset/call_button' && args.method === 'translate_fields') {
assert.deepEqual(args.args, ['note.note', 1, 'body', {}], "should call 'call_button' route");
assert.deepEqual(args.args, ['note.note', 1, 'body'], "should call 'call_button' route");
return Promise.resolve();
}
return this._super.apply(this, arguments);

0 comments on commit 1ced3bf

Please sign in to comment.
You can’t perform that action at this time.