From 2f392ec561fe85826757e61cf3adc2911a2c24f4 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 10 Sep 2018 18:18:46 +0200 Subject: [PATCH] [FIX] (website_)sale_coupon: `_compute_tax_id` with tax on reward line It should get tax from the SOL and not the SO's product as the tax is applied on the SOL only (the reward product has no tax by default). --- static/src/js/website_sale_coupon.test.js | 88 ++++++++++++----------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/static/src/js/website_sale_coupon.test.js b/static/src/js/website_sale_coupon.test.js index deb5ba81527..68348f7c6ed 100644 --- a/static/src/js/website_sale_coupon.test.js +++ b/static/src/js/website_sale_coupon.test.js @@ -4,6 +4,7 @@ odoo.define('website_sale_coupon.test', function (require) { require("website_sale.tour"); var tour = require("web_tour.tour"); var base = require("web_editor.base"); +var ajax = require('web.ajax'); tour.register('shop_sale_coupon', { test: true, @@ -19,6 +20,11 @@ tour.register('shop_sale_coupon', { { content: "click on 'Show # found'", trigger: "#customize-menu a:contains(Show # found)", + run: function () { + if (!$('#customize-menu a:contains(Show # found) input').prop('checked')) { + $('#customize-menu a:contains(Show # found)').click(); + } + }, }, /* 1. Buy 1 iPad Mini, enable coupon code & insert 10% code */ { @@ -52,6 +58,11 @@ tour.register('shop_sale_coupon', { { content: "click on 'Coupon Code'", trigger: "#customize-menu a:contains(Coupon Code)", + run: function () { + if (!$('#customize-menu a:contains(Coupon Code) input').prop('checked')) { + $('#customize-menu a:contains(Coupon Code)').click(); + } + }, }, { content: "insert promo code '10pc'", @@ -68,27 +79,47 @@ tour.register('shop_sale_coupon', { trigger: '.reward_product:contains("10.0 % discount on total amount")', run: function () {}, // it's a check }, - /* 2. Add an Ice Cream in the cart (which has different tax than iPad) and ensure only one discount line is shown */ + /* 2. Add a product with tax in the cart (which has different tax than iPad) and ensure only one discount line is shown */ { content: "go to shop", trigger: '.reward_product:contains("10.0 % discount on total amount")', run: function () { - location.href = '/shop' + ajax.jsonRpc('/web/dataset/call', 'call', { + model: 'account.tax', + method: 'create', + args: [{ + 'name':'15% tax incl', + 'amount': 15, + }], + }).then(function (tax_id) { + ajax.jsonRpc('/web/dataset/call', 'call', { + model: 'product.template', + method: 'create', + args: [{ + 'name': 'Taxed Product', + 'taxes_id': [([6, false, [tax_id]])], + 'list_price': 100, + 'website_published': true, + }], + }).then(function (data) { + location.href = '/shop'; + }); + }); }, }, { - content: "type Ice Cream in search", + content: "type Taxed Product in search", trigger: 'form input[name="search"]', - run: "text Ice Cream", + run: "text Taxed Product", }, { content: "start search", trigger: 'form:has(input[name="search"]) .oe_search_button', }, { - content: "select Ice Cream", + content: "select Taxed Product", extra_trigger: '.oe_search_found', // Wait to be on search results or it sometimes throws concurent error (sent search form + click on product on /shop) - trigger: '.oe_product_cart a:containsExact("Ice Cream")', + trigger: '.oe_product_cart a:containsExact("Taxed Product")', }, { content: "click on 'Add to Cart' button", @@ -96,7 +127,7 @@ tour.register('shop_sale_coupon', { }, { content: "check reduction amount got recomputed and merged both discount lines into one only", - extra_trigger: '.oe_currency_value:contains("‑74.00")', + extra_trigger: '.oe_currency_value:contains("-74.00"):not(#cart_total .oe_currency_value:contains("-74.00"))', trigger: '.oe_website_sale .oe_cart', run: function () {}, // it's a check }, @@ -108,7 +139,7 @@ tour.register('shop_sale_coupon', { }, { content: "check reduction amount got recomputed when changing qty", - trigger: '.oe_currency_value:contains("‑106.00")', + trigger: '.oe_currency_value:contains("-106.00")', run: function () {}, // it's a check }, { @@ -131,46 +162,21 @@ tour.register('shop_sale_coupon', { trigger: '#wrap:not(:has(.reward_product:contains("Free Product - iPad Mini")))', run: function () {}, // it's a check }, - /* 4. Empty cart and disable coupon */ + /* 4. Check /shop/payment does not break the `merged discount lines split per tax` (eg: with _compute_tax_id) */ { - content: "remove iPad Mini from cart", - trigger: '#cart_products input.js_quantity[value="3"]', - run: "text 0", + content: "go to checkout", + trigger: 'a[href="/shop/checkout"]', }, { - content: "remove Ice Cream from cart", - extra_trigger: '#wrap:not(:has(.td-product_name:contains("iPad Mini")))', // wait iPad got removed - trigger: '#cart_products input.js_quantity[value="1"]', - run: "text 0", + content: "Confirm checkout", + extra_trigger: "div.all_shipping .panel", + trigger: 'a[href="/shop/confirm_order"]', }, { - content: "check cart is empty", - trigger: '#wrap:not(:has(#cart_products))', + content: "check total is unchanged", + trigger: '.oe_currency_value:contains("967.50")', run: function () {}, // it's a check }, - /* 5. Disabled customize options coupon box & 'Show # found'*/ - { - content: "open customize menu", - extra_trigger: '.oe_website_sale .oe_cart', - trigger: '#customize-menu > a', - }, - { - content: "click on 'Coupon Code'", - trigger: "#customize-menu a:contains(Coupon Code)", - }, - { - content: "click on 'Continue Shopping'", - trigger: "a:contains(Continue Shopping)", - }, - { - content: "open customize menu", - extra_trigger: '.oe_website_sale #products_grid', - trigger: '#customize-menu > a', - }, - { - content: "click on 'Show # found'", - trigger: "#customize-menu a:contains(Show # found)", - }, ] );