[FIX] web: FieldSelection on m2o: unset value
When the value of a many2one field with widget selection was unset, it's value wasn't actually set to false in the BasicModel. It was set to a virtual id like 'virtual_294' instead. This caused a traceback when this value was sent to the server, obviously. This was for example the case of the Register Payment form view (accessible from a customer invoice), when the user selected a payment journal, and then unselected it (the virtual id was then sent to the onchange RPC).
This commit is contained in:
@@ -1001,7 +1001,7 @@ var BasicModel = AbstractModel.extend({
|
||||
*/
|
||||
_applyMany2OneChange: function (record, fieldName, data) {
|
||||
var self = this;
|
||||
if (!data) {
|
||||
if (!data || data.id === false) {
|
||||
record._changes[fieldName] = false;
|
||||
return $.when();
|
||||
}
|
||||
|
||||
@@ -5797,6 +5797,35 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('unset selection on a many2one field', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="trululu" widget="selection"/>' +
|
||||
'</form>',
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'write') {
|
||||
assert.strictEqual(args.args[1].trululu, false,
|
||||
"should send 'false' as trululu value");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
res_id: 1,
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
});
|
||||
|
||||
form.$('select').val("false").trigger('change');
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldMany2ManyTags');
|
||||
|
||||
QUnit.test('fieldmany2many tags: rendering and edition', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user