Ir al contenido
Odoo Menú
  • Inicia sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Artificial Intelligence
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de propiedades
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Modify Javascript from Odoo in custom module

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
javascriptdeliveryv11checkoutwebsite_sale
1 Responder
16729 Vistas
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
Descartar
Avatar
Daniele Morelli
Mejor respuesta

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
Descartar
Isaac
Autor

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
Autor

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
Autor

Thanks Daniele!

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
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
2572
Accidental modification in the Extra information Page in checkout process Resuelto
ecommerce checkout website_sale
Avatar
Avatar
1
may 23
3941
how to inherit _onCarrierUpdateAnswer() to update some info on selecting delivery carrier
javascript website_sale odoo11community
Avatar
Avatar
1
ene 19
4751
Malfunction of Custom Checkout Buttons and Failure to Save Data
javascript frontend checkout odoo17
Avatar
0
sept 24
2308
[v15] header: change selector for cart popup Resuelto
javascript inheritance override website_sale
Avatar
Avatar
2
dic 22
4073
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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