This question has been flagged

Hi, I need rewrite this fragment:

var _onCarrierUpdateAnswer = function(result) {
var $amount_delivery = $('#order_delivery span.oe_currency_value');
var $amount_untaxed = $('#order_total_untaxed span.oe_currency_value');
var $amount_tax = $('#order_total_taxes span.oe_currency_value');
var $amount_total = $('#order_total span.oe_currency_value');
var $carrier_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .badge.hidden');
var $compute_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .o_delivery_compute');
if (result.status === true) {
$amount_delivery.text(result.new_amount_delivery);
$amount_untaxed.text(result.new_amount_untaxed);
$amount_tax.text(result.new_amount_tax);
$amount_total.text(result.new_amount_total);
$carrier_badge.children('span').text(result.new_amount_delivery);
$carrier_badge.removeClass('hidden');
$compute_badge.addClass('hidden');
$pay_button.prop('disabled', false);
}
else {
console.error(result.error_message);
$compute_badge.text(result.error_message);
$amount_delivery.text(result.new_amount_delivery);
$amount_untaxed.text(result.new_amount_untaxed);
$amount_tax.text(result.new_amount_tax);
$amount_total.text(result.new_amount_total);
}
};

from website_sale_delivery.checkout, in Odoo 11.

How to modify in a custom module this code?


Avatar
Discard
Best Answer

I'd need to understand what exactly you are trying to do. I can think of different options.

- Do you want to have a similar js code in your (otherwise unrelated) custom module? In that case, i think that the best way is to brutally copy the js of your interest into your custom module and adapt it to your needs.

- Do you want to change the way the existing website_sale_delivery.checkout module works? In this case you probably need to inherit the js module and change some parts in your custom module (let's say that your addon is called "my_custom_addon_name").

In any case, you need to create an "assets.xml" file in your view, and register it in the data array in the __manifest__. The assets.xml file must look like this:

<template id="my_custom_assets_view_name" name="my_custom_assets_view_name" inherit_id="web.assets_backend"> 
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_custom_addon_name/static/src/js/my_js_module_name.js"></script>
</xpath>
</template>

hat you want to do precisely. You can find some info online about javascript inheritance in odoo, but pay attention to the odoo version because unfortunately it appears that most of the available informations online are deprecated...

The 'script' tag shall point to a js file (usually in my_custom_addon_name/static/src/js folder, you have to create the dirs yourself if they are not present). This will import the js file.

So, go on and create your js file in the my_custom_addon_name/static/src/js folder. Here you may wanto to set up some boilerplate:

odoo.define('my_custom_addon_name.my_js_module_name', function (require){
"use strict";

//your stuff here

});

Ok... now it all depends on what you want to do precisely. You can find some info online about javascript inheritance in odoo, but pay attention to the odoo version because unfortunately it appears that most of the available informations online are deprecated...

Good luck, cheers

checkout = require(website_sale_delivery.checkout);

//override the method:
checkout.include({
      _onCarrierUpdateAnswer = function(result) {
    //rewrite the function with your changes
    }
    });

EDIT:

Unfortunately i cannot test this at the moment, but maybe it's sufficient to override the function in the inherited model... like this:

odoo.define('my_custom_addon_name.my_js_module_name', function (require){
"use strict";

//require the module to modify:
var checkout = require(website_sale_delivery.checkout);

//override the method:
checkout.include({
      _onCarrierUpdateAnswer : function(result) {
    //rewrite the function with your changes
    }
    });
});

This is at least what i found trying to look for informations online... i can't assure that this will work, i'm still a noob with odoo but, well... i wish you the best!


Avatar
Discard
Author

Hi, I need change $pay_button.prop('disabled', false) by $pay_button.prop('disabled', true);

I try with include, extends, by not work.

Hi, i edited my answer with some other details... best regards

Author

Hello Daniele, I try your solution, but not work. I think that your solution I the tried or similar, but not work for me.

I'm sorry to hear that... gonna try some experiments as soon as i can; if i come up with a solution i'll surely let you know!

Author

Thanks Daniele!