Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Modify Javascript from Odoo in custom module

Subscribe

Get notified when there's activity on this post

This question has been flagged
javascriptdeliveryv11checkoutwebsite_sale
1 Reply
16602 Views
Avatar
Isaac

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?


1
Avatar
Discard
Avatar
Daniele Morelli
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!


2
Avatar
Discard
Isaac
Author

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

I try with include, extends, by not work.

Daniele Morelli

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

Isaac
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.

Daniele Morelli

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!

Isaac
Author

Thanks Daniele!

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to load JavaScript files from custom payment module only on /shop/payment page in Odoo 18
javascript website_sale Website
Avatar
1
Jul 25
2510
Accidental modification in the Extra information Page in checkout process Solved
ecommerce checkout website_sale
Avatar
Avatar
1
May 23
3868
how to inherit _onCarrierUpdateAnswer() to update some info on selecting delivery carrier
javascript website_sale odoo11community
Avatar
Avatar
1
Jan 19
4698
Malfunction of Custom Checkout Buttons and Failure to Save Data
javascript frontend checkout odoo17
Avatar
0
Sep 24
2258
[v15] header: change selector for cart popup Solved
javascript inheritance override website_sale
Avatar
Avatar
2
Dec 22
4012
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now