summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2018-08-13 14:40:28 +0200
committerjem-odoo <jem@openerp.com>2018-08-13 14:40:28 +0200
commit58e4a58427c2aeba6398b5ff1940931abe33463e (patch)
tree95dfda263f1e120d6fc7d003e221de9fa7c013a4 /addons/web/static/tests/fields/basic_fields_tests.js
parent8db463d124a04f4264862a5cfd78c612064c8a34 (diff)
parentcce8e002f5085b290bd4142c259f3f9f9a5e7225 (diff)
[MERGE] hr_timesheet: log timesheet in any time UoM
Since uom management has been extract in a separated module, we can now add the possibility to use it without product. This commit brings the ability to record the timesheets in an different UoM than 'Hours'. The user can now set an encoding UoM for its timesheet on the company. This will display the timesheet field `unit_amount` with a different widget. For instance, timesheeting in hours will still use the traditionnal float_time widget, when timesheeting in 'Days' will displayed a toggle button with a range of defined possible values. The widget used by UoM is customizable on the UoM. The `unit_amount` field should now be decorated with the 'timesheet_uom' widget. This one will bind the correct widget (float_time, float_toggle, ...). If the encoding UoM has no widget associated, the fallback will be 'float_factor', using the uoM converstion factor. Everything will still be stored in the database in 'Hours' (the UoM set on the `project_mode_time_id` field on the company). For more details, please have a look at the subcommits. Task #39079 Closes #24893
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index 030d173dbeb..1855b032bf3 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -3264,6 +3264,90 @@ QUnit.module('basic_fields', {
});
+ QUnit.module('FieldFloatFactor');
+
+ QUnit.test('float_factor field in form view', function (assert) {
+ assert.expect(4);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="qux" widget="float_factor" options="{\'factor\': 0.5}" digits="[16,2]"/>' +
+ '</sheet>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/call_kw/partner/write') {
+ // 16.4 / 2 = 8.2
+ assert.strictEqual(args.args[1].qux, 4.6, 'the correct float value should be saved');
+ }
+ return this._super.apply(this, arguments);
+ },
+ res_id: 5,
+ });
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '4.55', // 9.1 / 0.5
+ 'The formatted value should be displayed properly.');
+
+ form.$buttons.find('.o_form_button_edit').click();
+ assert.strictEqual(form.$('input').val(), '4.55',
+ 'The value should be rendered correctly in the input.');
+
+ form.$('input').val('2.3').trigger('input');
+
+ form.$buttons.find('.o_form_button_save').click();
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '2.30',
+ 'The new value should be saved and displayed properly.');
+
+ form.destroy();
+ });
+
+ QUnit.module('FieldFloatToggle');
+
+ QUnit.test('float_toggle field in form view', function (assert) {
+ assert.expect(5);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="qux" widget="float_toggle" options="{\'factor\': 0.125, \'range\': [0, 1, 0.75, 0.5, 0.25]}" digits="[5,3]"/>' +
+ '</sheet>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/call_kw/partner/write') {
+ // 1.000 / 0.125 = 8
+ assert.strictEqual(args.args[1].qux, 8, 'the correct float value should be saved');
+ }
+ return this._super.apply(this, arguments);
+ },
+ res_id: 1,
+ });
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '0.056',
+ 'The formatted time value should be displayed properly.');
+
+ form.$buttons.find('.o_form_button_edit').click();
+
+ assert.strictEqual(form.$('button.o_field_float_toggle').text(), '0.056',
+ 'The value should be rendered correctly on the button.');
+
+ form.$('button.o_field_float_toggle').click(); // clicking will make the next value 1, since 0 was the closest of 0.056
+
+ assert.strictEqual(form.$('button.o_field_float_toggle').text(), '1.000',
+ 'The value should be rendered correctly on the button.');
+
+ form.$buttons.find('.o_form_button_save').click();
+
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '1.000',
+ 'The new value should be saved and displayed properly.');
+
+ form.destroy();
+ });
+
+
QUnit.module('PhoneWidget');
QUnit.test('phone field in form view on extra small screens', function (assert) {