Odoo Help


How do I update line.price_subtotal with website_sale.js in website /shop/cart?

Luke Branch
on 10/27/14, 2:09 AM 1,159 views

I've added an extra column in my shopping cart page to include line subtotal as follows:

<span class="amount" t-field="line.price_subtotal" t-field-options="{                                      &quot;widget&quot;: &quot;monetary&quot;,                                      &quot;display_currency&quot;: &quot;user_id.partner_id.property_product_pricelist.currency_id&quot;                                  }"/>

I've reformatted the page and all other elements are updating automatically (on click) using website_sale.js, however as this field is an extra addition to the page it is not defined in website_sale.js and therefore is not updating correctly.

Unfortunately i'm not familiar with Javascript, however I'm interested in adding another .js file to my template to add this functionality (ie. auto update on click on quantity change), however i'm not sure how to tackle the problem given the .js file is a core file and should not be edited.

If anyone else has any insight into how this might be acomplished I would appreciate your advice.

Nedas Zilinskas
On 5/1/15, 1:07 PM

Hello Luke,

If I understood you correctly that you want to show a subtotal amount for each row in the cart and already have added a new column in cart table view then the following code might help you to resolve your needs:

 $('.oe_website_sale').on("change", ".oe_cart input.js_quantity", function(event) {
        var $input = $(this);
        var value = parseInt($input.val(), 10);
        var $dom = $(event.target).closest('tr');
        var product_id = parseInt($input.data('product-id'), 10);
        var product_ids = [product_id];
        openerp.jsonRpc("/shop/get_unit_price", 'call', {
            'product_ids': product_ids,
            'add_qty': value
            .then(function(res) {
                var price = res[Object.keys(res)[0]];
                var amount = Number(value * price).toFixed(2);
                var current_subtotal = $dom.find('.amount').text();
                var new_subtotal = current_subtotal.replace(/[\d\.,]+/, amount);

This code requests for the price and multiplies it by the number in qty. field and adds result to .amount element when the quantity is changed (assuming you print initial amount before).

Note: this is only a demonstration code and it only returns unformatted amount. If you would want formatted amount you would need to format it before setting it in .amount element.

UPDATE: modified script to format result and put it into .amount element.


Thank you! I'll try this out shortly and reply back to let you know if i've managed to get it to work.

. What I will likely do is build it into a very basic module to achieve the frontend view, and onchange requirements I need. I'd like to make sure you are properly accredited if I do this, so please let me know whether you would like me to add a comment block into the javascript file for your contribution along with your contact details, license, etc. along with your name on in the Author section of the __openerp__.py manifest file for the module.

Luke Branch
on 5/4/15, 12:05 AM

Hello Luke, I had already pushed this code a bit further (formatting price, keep currency symbol) since one of the forum members contacted me directly regarding this. Are you going to host your module on github? In that case I would be more then happy to contribute to your module and push latest code and so some tests. My gitihub account is https://github.com/nedaszilinskas.

Nedas Zilinskas
on 5/4/15, 3:29 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 10/27/14, 2:09 AM
Seen: 1159 times
Last updated: 5/5/15, 3:10 PM