Skip to content
Permalink
Browse files

[IMP] web: reload currencies when activating one

Active currencies are given in session_info, in the page source.
When the user activated a new currency, he had to reload the page
to make the browser aware of that new currency (without reloading,
there was no currency symbol displayed next to the amounts).

This rev. forces a reload of the currencies each time a currency is
edited.

Task #1838654

closes #31192
  • Loading branch information...
svs-odoo authored and aab-odoo committed Oct 2, 2018
1 parent aa8aadd commit b35d103cc0fe64547c3212ef01ab329faf0bacc4
@@ -336,6 +336,27 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
return -new Date(date).getTimezoneOffset();
},

//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------

/**
* Reload the currencies (initially given in session_info). This is meant to
* be called when changes are made on 'res.currency' records (e.g. when
* (de-)activating a currency). For the sake of simplicity, we reload all
* session_info.
*
* FIXME: this whole currencies handling should be moved out of session.
*
* @returns {$.promise}
*/
reloadCurrencies: function () {
var self = this;
return this.rpc('/web/session/get_session_info').then(function (result) {
self.currencies = result.currencies;
});
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
@@ -3477,13 +3477,18 @@ var BasicModel = AbstractModel.extend({
* Invalidates the DataManager's cache if the main model (i.e. the model of
* its root parent) of the given dataPoint is a model in 'noCacheModels'.
*
* Reloads the currencies if the main model is 'res.currency'.
*
* @private
* @param {Object} dataPoint
*/
_invalidateCache: function (dataPoint) {
while (dataPoint.parentID) {
dataPoint = this.localData[dataPoint.parentID];
}
if (dataPoint.model === 'res.currency') {
session.reloadCurrencies();
}
if (_.contains(this.noCacheModels, dataPoint.model)) {
core.bus.trigger('clear_cache');
}
@@ -7004,6 +7004,47 @@ QUnit.module('Views', {
testUtils.mock.unpatch(BasicModel);
});

QUnit.test('reload currencies when writing on records of model res.currency', function (assert) {
assert.expect(5);

this.data['res.currency'] = {
fields: {},
records: [{id: 1, display_name: "some currency"}],
};

var form = createView({
View: FormView,
model: 'res.currency',
data: this.data,
arch: '<form><field name="display_name"/></form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
mockRPC: function (route, args) {
assert.step(args.method);
return this._super.apply(this, arguments);
},
session: {
reloadCurrencies: function () {
assert.step('reload currencies');
},
},
});

testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value');
testUtils.form.clickSave(form);

assert.verifySteps([
'read',
'write',
'reload currencies',
'read',
]);

form.destroy();
});

QUnit.test('a popup window should automatically close after a do_action event', function (assert) {

// Having clicked on a one2many in a form view and clicked on a many2one

0 comments on commit b35d103

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