1

I want to override parseFloatTime() method of field_utils.js in web module odoo14. For that i have followed to links:-

link1

link2

but not getting override in my custom module.

Also here is my code which i have tried following the above links:-

odoo.define('custom_module_name.field_utils.float_time', function (require) {

"use strict";

// override float_time function

var field_utils = require('web.field_utils');



function parseFloatTime(value) {

    var factor = 1;

    if (value[0] === '-') {

        value = value.slice(1);

        factor = -1;

    }

    if(value){

    var float_time_pair = value.split(":");

    if (float_time_pair.length !== 2)

        return factor * parseFloat(value);

    var hours = parseInteger(float_time_pair[0]);

    var minutes = parseInteger(float_time_pair[1]);

    return factor * (hours + (minutes / 60));

    }

}



field_utils.parse.float_time = parseFloatTime;

});

assets.xml:-

<?xml version="1.0" encoding="utf-8"?>

<odoo>
    <template id="web_widget_custom_assets_backend"
              name="web_widget_custom_assets"
              inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
           
            <script type="text/javascript" src="/custom_module_name/static/src/js/field_utils.js"/>
        </xpath>
    </template>
</odoo>

So can anyone help me on this problem please?

Gautam Bothra
  • 565
  • 1
  • 8
  • 23
  • Can you share the logs from the devtools console? The code seems correct, did you add your javascript to the backend assets through an xml template? – Tiki Apr 30 '21 at 20:23
  • thanks tiki for the reponse. yes i have added javascript file to the backend assets through template i have updated my question with backend assets template code you can even check that.And for devtools console, i am getting this in console while executing the function:- "Tour Manager is ready. running_tour=null web.assets_common.js:4419 Can't find "li.divider" when extending template UserMenu.Actions web.assets_common.js:4419 Can't find "a[data-menu='settings']" when extending template UserMenu.Actions" – Gautam Bothra May 01 '21 at 07:34

1 Answers1

0

You have to define your custom JS module:

odoo.define('mymodule.ReconciliationRenderer', function (require) {
  "use strict";

  var field_utils = require('web.field_utils'); // if the module in the  field_utils.js is defined as web.field_utils otherwise, you have to require the web.module_name_in_that_file

});

To override this function try the following:

field_utils.include({
  function parseFloatTime(value) { 
      // your custom code
  }
 

});

This will work if the object contains parseFloatTime is written as var ObjectName = .. in the field_utils.js file, but if it's written as a class that works as a widget component then try this

const CustomObject = module_name_in_that_file => class extends module_name_in_that_file {
   parseFloatTime(value) {//your code custom here},
}
Registries.Component.extend(module_name_in_that_file, CustomObject);
Abdelrahman
  • 23
  • 1
  • 8